mirror of
https://github.com/Siccity/xNode.git
synced 2025-12-22 02:06:05 +08:00
Merge branch 'master' of git@github.com:Siccity/xNode.git
This commit is contained in:
commit
9875f8d4f0
@ -241,12 +241,10 @@ namespace XNodeEditor {
|
|||||||
selectionCache = new List<UnityEngine.Object>(Selection.objects);
|
selectionCache = new List<UnityEngine.Object>(Selection.objects);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Active node is hashed before and after node GUI to detect changes
|
|
||||||
int nodeHash = 0;
|
|
||||||
System.Reflection.MethodInfo onValidate = null;
|
System.Reflection.MethodInfo onValidate = null;
|
||||||
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
|
if (Selection.activeObject != null && Selection.activeObject is XNode.Node) {
|
||||||
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
|
onValidate = Selection.activeObject.GetType().GetMethod("OnValidate");
|
||||||
if (onValidate != null) nodeHash = Selection.activeObject.GetHashCode();
|
if (onValidate != null) EditorGUI.BeginChangeCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
BeginZoomed(position, zoom, topPadding);
|
BeginZoomed(position, zoom, topPadding);
|
||||||
@ -383,12 +381,10 @@ namespace XNodeEditor {
|
|||||||
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
if (e.type != EventType.Layout && currentActivity == NodeActivity.DragGrid) Selection.objects = preSelection.ToArray();
|
||||||
EndZoomed(position, zoom, topPadding);
|
EndZoomed(position, zoom, topPadding);
|
||||||
|
|
||||||
//If a change in hash is detected in the selected node, call OnValidate method.
|
//If a change in is detected in the selected node, call OnValidate method.
|
||||||
//This is done through reflection because OnValidate is only relevant in editor,
|
//This is done through reflection because OnValidate is only relevant in editor,
|
||||||
//and thus, the code should not be included in build.
|
//and thus, the code should not be included in build.
|
||||||
if (nodeHash != 0) {
|
if (onValidate != null && EditorGUI.EndChangeCheck()) onValidate.Invoke(Selection.activeObject, null);
|
||||||
if (onValidate != null && nodeHash != Selection.activeObject.GetHashCode()) onValidate.Invoke(Selection.activeObject, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldBeCulled(XNode.Node node) {
|
private bool ShouldBeCulled(XNode.Node node) {
|
||||||
|
|||||||
@ -154,7 +154,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
private static System.Type GetType(SerializedProperty property) {
|
private static System.Type GetType(SerializedProperty property) {
|
||||||
System.Type parentType = property.serializedObject.targetObject.GetType();
|
System.Type parentType = property.serializedObject.targetObject.GetType();
|
||||||
System.Reflection.FieldInfo fi = parentType.GetField(property.propertyPath);
|
System.Reflection.FieldInfo fi = NodeEditorWindow.GetFieldInfo(property.serializedObject.targetObject.GetType(), property.name);
|
||||||
return fi.FieldType;
|
return fi.FieldType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -61,6 +61,15 @@ namespace XNodeEditor {
|
|||||||
return widths;
|
return widths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary> Get FieldInfo of a field, including those that are private and/or inherited </summary>
|
||||||
|
public static FieldInfo GetFieldInfo(Type type, string fieldName) {
|
||||||
|
// If we can't find field in the first run, it's probably a private field in a base class.
|
||||||
|
FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
// Search base classes for private fields only. Public fields are found above
|
||||||
|
while (field == null && (type = type.BaseType) != typeof(XNode.Node)) field = type.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Get all classes deriving from baseType via reflection </summary>
|
/// <summary> Get all classes deriving from baseType via reflection </summary>
|
||||||
public static Type[] GetDerivedTypes(Type baseType) {
|
public static Type[] GetDerivedTypes(Type baseType) {
|
||||||
List<System.Type> types = new List<System.Type>();
|
List<System.Type> types = new List<System.Type>();
|
||||||
|
|||||||
@ -36,9 +36,7 @@ namespace XNodeEditor {
|
|||||||
|
|
||||||
public static bool GetAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
public static bool GetAttrib<T>(Type classType, string fieldName, out T attribOut) where T : Attribute {
|
||||||
// If we can't find field in the first run, it's probably a private field in a base class.
|
// If we can't find field in the first run, it's probably a private field in a base class.
|
||||||
FieldInfo field = classType.GetField(fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
|
FieldInfo field = NodeEditorWindow.GetFieldInfo(classType, fieldName);
|
||||||
// Search base classes for private fields only. Public fields are found above
|
|
||||||
while (field == null && (classType = classType.BaseType) != typeof(XNode.Node)) field = classType.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
||||||
// This shouldn't happen. Ever.
|
// This shouldn't happen. Ever.
|
||||||
if (field == null) {
|
if (field == null) {
|
||||||
Debug.LogWarning("Field " + fieldName + " couldnt be found");
|
Debug.LogWarning("Field " + fieldName + " couldnt be found");
|
||||||
|
|||||||
@ -215,10 +215,6 @@ namespace XNode {
|
|||||||
foreach (NodePort port in Ports) port.ClearConnections();
|
foreach (NodePort port in Ports) port.ClearConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode() {
|
|
||||||
return JsonUtility.ToJson(this).GetHashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Attributes
|
#region Attributes
|
||||||
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
|
/// <summary> Mark a serializable field as an input port. You can access this through <see cref="GetInputPort(string)"/> </summary>
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user