1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-21 01:36:03 +08:00

Tooltip shows static output values

This commit is contained in:
Thor Brigsted 2017-11-06 00:36:25 +01:00
parent 031e1d83df
commit 05f7b4ca82
5 changed files with 22 additions and 13 deletions

View File

@ -57,9 +57,9 @@ MonoBehaviour:
node: {fileID: 114708853913061688}
_direction: 1
_dynamic: 0
a: 3.06
b: 7.29
result: 0
a: 6.48
b: 7.59
result: 14.07
mathType: 0
--- !u!114 &114708853913061688
MonoBehaviour:
@ -116,7 +116,7 @@ MonoBehaviour:
x: 0
y: 2.6412349
z: 14.33477
vector: {x: 0, y: 0, z: 0}
vector: {x: 14.07, y: 2.6412349, z: 14.33477}
--- !u!114 &114729867621534192
MonoBehaviour:
m_ObjectHideFlags: 0

View File

@ -21,14 +21,15 @@ namespace BasicNodes {
float b = GetInputValue<float>("b", this.b);
// After you've gotten your input values, you can perform your calculations and return a value
result = 0f;
if (port.fieldName == "result")
switch (mathType) {
case MathType.Add: default: return a + b;
case MathType.Subtract: return a - b;
case MathType.Multiply: return a * b;
case MathType.Divide: return a / b;
case MathType.Add: default: result = a+b; break;
case MathType.Subtract: result = a - b; break;
case MathType.Multiply: result = a * b; break;
case MathType.Divide: result = a / b; break;
}
else return 0f;
return result;
}
}
}

View File

@ -7,10 +7,10 @@ namespace BasicNodes {
[Output] public Vector3 vector;
public override object GetValue(NodePort port) {
float x = GetInputValue<float>("x", this.x);
float y = GetInputValue<float>("y", this.y);
float z = GetInputValue<float>("z", this.z);
return new Vector3(x, y, z);
vector.x = GetInputValue<float>("x", this.x);
vector.y = GetInputValue<float>("y", this.y);
vector.z = GetInputValue<float>("z", this.z);
return vector;
}
}
}

View File

@ -243,6 +243,7 @@ namespace XNodeEditor {
Type type = hoveredPort.ValueType;
GUIContent content = new GUIContent();
content.text = TypeToString(type);
if (hoveredPort.IsStatic && hoveredPort.IsOutput) content.text += " = " + ObjectFromFieldName(hoveredPort.node, hoveredPort.fieldName).ToString();
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
Rect rect = new Rect(Event.current.mousePosition - (size), size);
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
@ -252,6 +253,7 @@ namespace XNodeEditor {
private string TypeToString(Type type) {
if (type == null) return "null";
if (type == typeof(System.Object)) return "object";
if (type == typeof(float)) return "float";
else if (type == typeof(int)) return "int";
else if (type == typeof(long)) return "long";

View File

@ -48,5 +48,11 @@ namespace XNodeEditor {
public static object ObjectFromType(Type type) {
return Activator.CreateInstance(type);
}
public static object ObjectFromFieldName(object obj, string fieldName) {
Type type = obj.GetType();
FieldInfo fieldInfo = type.GetField(fieldName);
return fieldInfo.GetValue(obj);
}
}
}