mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-21 09:46:03 +08:00
Tooltip shows static output values
This commit is contained in:
parent
031e1d83df
commit
05f7b4ca82
@ -57,9 +57,9 @@ MonoBehaviour:
|
|||||||
node: {fileID: 114708853913061688}
|
node: {fileID: 114708853913061688}
|
||||||
_direction: 1
|
_direction: 1
|
||||||
_dynamic: 0
|
_dynamic: 0
|
||||||
a: 3.06
|
a: 6.48
|
||||||
b: 7.29
|
b: 7.59
|
||||||
result: 0
|
result: 14.07
|
||||||
mathType: 0
|
mathType: 0
|
||||||
--- !u!114 &114708853913061688
|
--- !u!114 &114708853913061688
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
@ -116,7 +116,7 @@ MonoBehaviour:
|
|||||||
x: 0
|
x: 0
|
||||||
y: 2.6412349
|
y: 2.6412349
|
||||||
z: 14.33477
|
z: 14.33477
|
||||||
vector: {x: 0, y: 0, z: 0}
|
vector: {x: 14.07, y: 2.6412349, z: 14.33477}
|
||||||
--- !u!114 &114729867621534192
|
--- !u!114 &114729867621534192
|
||||||
MonoBehaviour:
|
MonoBehaviour:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
|||||||
@ -21,14 +21,15 @@ namespace BasicNodes {
|
|||||||
float b = GetInputValue<float>("b", this.b);
|
float b = GetInputValue<float>("b", this.b);
|
||||||
|
|
||||||
// After you've gotten your input values, you can perform your calculations and return a value
|
// After you've gotten your input values, you can perform your calculations and return a value
|
||||||
|
result = 0f;
|
||||||
if (port.fieldName == "result")
|
if (port.fieldName == "result")
|
||||||
switch (mathType) {
|
switch (mathType) {
|
||||||
case MathType.Add: default: return a + b;
|
case MathType.Add: default: result = a+b; break;
|
||||||
case MathType.Subtract: return a - b;
|
case MathType.Subtract: result = a - b; break;
|
||||||
case MathType.Multiply: return a * b;
|
case MathType.Multiply: result = a * b; break;
|
||||||
case MathType.Divide: return a / b;
|
case MathType.Divide: result = a / b; break;
|
||||||
}
|
}
|
||||||
else return 0f;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7,10 +7,10 @@ namespace BasicNodes {
|
|||||||
[Output] public Vector3 vector;
|
[Output] public Vector3 vector;
|
||||||
|
|
||||||
public override object GetValue(NodePort port) {
|
public override object GetValue(NodePort port) {
|
||||||
float x = GetInputValue<float>("x", this.x);
|
vector.x = GetInputValue<float>("x", this.x);
|
||||||
float y = GetInputValue<float>("y", this.y);
|
vector.y = GetInputValue<float>("y", this.y);
|
||||||
float z = GetInputValue<float>("z", this.z);
|
vector.z = GetInputValue<float>("z", this.z);
|
||||||
return new Vector3(x, y, z);
|
return vector;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,6 +243,7 @@ namespace XNodeEditor {
|
|||||||
Type type = hoveredPort.ValueType;
|
Type type = hoveredPort.ValueType;
|
||||||
GUIContent content = new GUIContent();
|
GUIContent content = new GUIContent();
|
||||||
content.text = TypeToString(type);
|
content.text = TypeToString(type);
|
||||||
|
if (hoveredPort.IsStatic && hoveredPort.IsOutput) content.text += " = " + ObjectFromFieldName(hoveredPort.node, hoveredPort.fieldName).ToString();
|
||||||
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
|
Vector2 size = NodeEditorResources.styles.tooltip.CalcSize(content);
|
||||||
Rect rect = new Rect(Event.current.mousePosition - (size), size);
|
Rect rect = new Rect(Event.current.mousePosition - (size), size);
|
||||||
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
|
EditorGUI.LabelField(rect, content, NodeEditorResources.styles.tooltip);
|
||||||
@ -252,6 +253,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
private string TypeToString(Type type) {
|
private string TypeToString(Type type) {
|
||||||
if (type == null) return "null";
|
if (type == null) return "null";
|
||||||
|
if (type == typeof(System.Object)) return "object";
|
||||||
if (type == typeof(float)) return "float";
|
if (type == typeof(float)) return "float";
|
||||||
else if (type == typeof(int)) return "int";
|
else if (type == typeof(int)) return "int";
|
||||||
else if (type == typeof(long)) return "long";
|
else if (type == typeof(long)) return "long";
|
||||||
|
|||||||
@ -48,5 +48,11 @@ namespace XNodeEditor {
|
|||||||
public static object ObjectFromType(Type type) {
|
public static object ObjectFromType(Type type) {
|
||||||
return Activator.CreateInstance(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user