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. FieldInfo field = NodeEditorWindow.GetFieldInfo(classType, fieldName); // This shouldn't happen. Ever. if (field == null) { Debug.LogWarning("Field " + fieldName + " couldnt be found"); attribOut = null; return(false); } object[] attribs = field.GetCustomAttributes(typeof(T), true); return(GetAttrib(attribs, out attribOut)); }
/// <summary> /// Add items for the context menu when right-clicking this node. Override to add custom menu items. /// </summary> public virtual void AddContextMenuItems(GenericMenu menu) { // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode); } // Add actions to any number of selected nodes menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes); menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; NodeEditorWindow.AddCustomContextMenuItems(menu, node); } }
private static System.Type GetType(SerializedProperty property) { System.Type parentType = property.serializedObject.targetObject.GetType(); System.Reflection.FieldInfo fi = NodeEditorWindow.GetFieldInfo(parentType, property.name); return(fi.FieldType); }