/// <summary> /// Updates the node name based on the Task type and it's width acording to name /// </summary> /// <param name="Tasktype">Task type to get Node data</param> protected void UpdateName(System.Type Tasktype) { if (Tasktype != null && !NameChanged) { name = MoonReflection.GetNodeData(Tasktype).Name; NameChanged = true; } }
/// <summary> /// Node item constructor /// </summary> /// <param name="NodeType"></param> public NodeItem(System.Type NodeType, NodeGraph Graph) { _NodeType = NodeType; InfoAttribute info = MoonReflection.GetNodeData(NodeType); _Name = (info != null) ? (string.IsNullOrEmpty(info.Name) ? NodeType.Name : info.Name) : NodeType.Name; _Category = (info == null || string.IsNullOrEmpty(info.Category)) ? "No category" : info.Category; _icon = MoonResources.LoadIcon(Graph.GetIconName(NodeType.BaseType)); }
private void OnEnable() { n = (Node)target; if (n != null) { TaskInspector = CreateEditor(n.Task); TaskInfo = MoonReflection.GetNodeData(n.Task.GetType()); } tooltipPosition = serializedObject.FindProperty("tooltipPosition"); Tooltip = serializedObject.FindProperty("Tooltip"); Nodedoc = MoonReflection.GetAttribute(n.Task.GetType(), typeof(HelpURLAttribute), true) as HelpURLAttribute; }
/// <summary> /// Gets all aviable nodes /// </summary> /// <returns>Nodes array</returns> public static NodeItem[] GetAllNodes(NodeGraph Graph) { System.Type[] NodeTypes = MoonReflection.GetAllDerivedTypes(Graph.TaskType).Where ((System.Type tt) => !tt.IsAbstract).ToArray(); List <NodeItem> items = new List <NodeItem>(); for (int i = 0; i < NodeTypes.Length; i++) { items.Add(new NodeItem(NodeTypes[i], Graph)); } items.Sort((NodeItem x, NodeItem y) => x.Category.CompareTo(y.Category)); return(items.ToArray()); }
public override void OnInspectorGUI() { serializedObject.Update(); // Draw inspector for each filter for (int i = 0; i < Filters.arraySize; i++) { SerializedProperty currentf = Filters.GetArrayElementAtIndex(i); GUILayout.BeginHorizontal(); currentf.isExpanded = EditorGUILayout.Foldout(currentf.isExpanded, new GUIContent(ObjectNames.NicifyVariableName(currentf.objectReferenceValue.GetType().Name))); GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", EditorStyles.miniButton)) { DestroyImmediate(currentf.objectReferenceValue, true); AssetDatabase.SaveAssets(); Filters.DeleteArrayElementAtIndex(i); Filters.DeleteArrayElementAtIndex(i); serializedObject.ApplyModifiedProperties(); continue; } GUILayout.EndHorizontal(); if (currentf.isExpanded) { Editor m_editor = CreateEditor(currentf.objectReferenceValue); GUILayout.Space(5); m_editor.OnInspectorGUI(); } MoonGUILayout.Separator(); } GUILayout.Space(5); // add buttun filter if (GUILayout.Button("Add Filter", GUILayout.Height(20))) { GenericMenu Menu = new GenericMenu(); // Gets all aviable filters via reflection List <System.Type> m_types = MoonReflection.GetAllDerivedTypes(typeof(SensorFilter)).ToList(); for (int i = 0; i < m_types.Count; i++) { System.Type currt = m_types[i]; if (currt != null) { Menu.AddItem(new GUIContent(currt.Name), false, new GenericMenu.MenuFunction(() => { int index = Filters.arraySize; SensorFilter filter = CreateInstance(currt) as SensorFilter; filter.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; AssetDatabase.AddObjectToAsset(filter, target); AssetDatabase.SaveAssets(); Filters.InsertArrayElementAtIndex(index); SerializedProperty curr = Filters.GetArrayElementAtIndex(index); curr.objectReferenceValue = filter; serializedObject.ApplyModifiedProperties(); })); } } Menu.ShowAsContext(); } serializedObject.ApplyModifiedProperties(); }
/// <summary> /// Displays the toolbar menu /// </summary> public void DoMenu() { GUILayout.BeginHorizontal(EditorStyles.toolbar); if (GUILayout.Button("New", EditorStyles.toolbarDropDown, GUILayout.Width(MenuBtnWidth))) { System.Type[] foundmodules = MoonReflection.GetAllDerivedTypes(typeof(NodeGraph)).ToArray(); GenericMenu menu = new GenericMenu(); for (int i = 0; i < foundmodules.Length; i++) { System.Type curr = foundmodules[i]; var atr = (GraphModuleAttribute)MoonReflection.GetAttribute(curr, typeof(GraphModuleAttribute), true); if (atr != null) { atr.Init(curr); menu.AddItem(new GUIContent(atr.Name), false, OnNewGraph, atr); } } menu.DropDown(new Rect(5, 15, 0, 0)); } if (GUILayout.Button("Open", EditorStyles.toolbarButton, GUILayout.Width(MenuBtnWidth))) { canvas.HideAddNode(); CurrentGUIState = (int)GUIState.Open; FoundGraphs = MoonIO.GetAllGraphs(); } if (WorkingGraph != null) { if (GUILayout.Button("Save", EditorStyles.toolbarDropDown, GUILayout.Width(MenuBtnWidth))) { GenericMenu men = new GenericMenu(); men.AddItem(new GUIContent("Save"), false, new GenericMenu.MenuFunction(() => { AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); })); men.AddItem(new GUIContent("Save as..."), false, new GenericMenu.MenuFunction(() => { CurrentGUIState = (int)GUIState.SaveAs; })); float x = (MenuBtnWidth * 2) + 5; men.DropDown(new Rect(x, 15, 0, 0)); } DoZoomArea(); GUILayout.Space(5); WorkingGraph.OnMenuGUI(); } GUILayout.FlexibleSpace(); if (WorkingGraph != null) { WorkingGraph.OnToolBarGUI(); } else { GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); }
private void OnEnable() { MemoryItems = serializedObject.FindProperty("MemoryItems"); memoryfield = MoonReflection.GetField("memory", target); MemoryList = new ReorderableList(serializedObject, MemoryItems, true, true, true, true); MemoryList.elementHeight = 50; MemoryList.drawHeaderCallback = (Rect r) => { EditorGUI.LabelField(r, new GUIContent("Memory Elements", "User pre-defined memory elements")); }; MemoryList.drawElementCallback = (Rect rect, int index, bool isactive, bool isfocused) => { SerializedProperty current = MemoryItems.GetArrayElementAtIndex(index); Rect toprect = new Rect(rect.x, rect.y + 2, rect.width, 20); SerializedProperty type = current.FindPropertyRelative("type"); ItemType itype = (ItemType)type.enumValueIndex; // key gui GUI.BeginGroup(toprect); GUIContent labelcont = new GUIContent(MemoryItem.ConvertType(itype).Name); float w = GUI.skin.FindStyle("AssetLabel").CalcSize(labelcont).x; GUI.Label(new Rect(0, 0, w, 16), labelcont, GUI.skin.FindStyle("AssetLabel")); GUI.Label(new Rect(w + 5, 0, 30, 16), "key:"); SerializedProperty key = current.FindPropertyRelative("Key"); key.stringValue = EditorGUI.TextField(new Rect(w + 40, 0, toprect.width - (w + 40), 16), key.stringValue); GUI.EndGroup(); // value gui Rect buttunrect = new Rect(rect.x, toprect.yMax + 2, rect.width, 20); GUI.BeginGroup(buttunrect); GUI.Label(new Rect(0, 0, 50, 15), "Value"); Rect ValueRect = new Rect(60, 0, buttunrect.width - 60, 16); switch (itype) { case ItemType.BOOLEAN: SerializedProperty BoolValue = current.FindPropertyRelative("BoolValue"); BoolValue.boolValue = EditorGUI.Toggle(new Rect(ValueRect.position, Vector2.one * 16), BoolValue.boolValue); break; case ItemType.STRING: SerializedProperty StringValue = current.FindPropertyRelative("StringValue"); StringValue.stringValue = EditorGUI.TextField(ValueRect, StringValue.stringValue); break; case ItemType.FLOAT: SerializedProperty floatValue = current.FindPropertyRelative("floatValue"); floatValue.floatValue = EditorGUI.FloatField(ValueRect, floatValue.floatValue); break; case ItemType.INT: SerializedProperty intValue = current.FindPropertyRelative("intValue"); intValue.intValue = EditorGUI.IntField(ValueRect, intValue.intValue); break; case ItemType.VECTOR2: SerializedProperty Vector2Value = current.FindPropertyRelative("Vector2Value"); Vector2Value.vector2Value = EditorGUI.Vector2Field(ValueRect, "", Vector2Value.vector2Value); break; case ItemType.VECTOR3: SerializedProperty Vector3Value = current.FindPropertyRelative("Vector3Value"); Vector3Value.vector3Value = EditorGUI.Vector3Field(ValueRect, "", Vector3Value.vector3Value); break; case ItemType.VECTOR4: SerializedProperty Vector4Value = current.FindPropertyRelative("Vector4Value"); Vector4Value.vector4Value = EditorGUI.Vector4Field(ValueRect, "", Vector4Value.vector4Value); break; case ItemType.COLOR: SerializedProperty ColorValue = current.FindPropertyRelative("ColorValue"); ColorValue.colorValue = EditorGUI.ColorField(ValueRect, ColorValue.colorValue); break; case ItemType.OBJECT: SerializedProperty objectValue = current.FindPropertyRelative("objectValue"); objectValue.objectReferenceValue = EditorGUI.ObjectField(ValueRect, "", objectValue.objectReferenceValue, typeof(Object), true); break; case ItemType.LAYERMASK: SerializedProperty LayerValue = current.FindPropertyRelative("LayerValue"); EditorGUI.PropertyField(ValueRect, LayerValue, GUIContent.none, true); break; } GUI.EndGroup(); }; MemoryList.onAddDropdownCallback = (Rect btnrect, ReorderableList list) => { int targetindex = list.serializedProperty.arraySize; GenericMenu menu = new GenericMenu(); string[] opcs = System.Enum.GetNames(typeof(ItemType)); for (int i = 0; i < opcs.Length; i++) { string elementName = opcs[i]; menu.AddItem(new GUIContent(elementName), false, new GenericMenu.MenuFunction(() => { list.serializedProperty.InsertArrayElementAtIndex(targetindex); serializedObject.ApplyModifiedProperties(); SerializedProperty current = MemoryItems.GetArrayElementAtIndex(targetindex); SerializedProperty type = current.FindPropertyRelative("type"); for (int j = 0; j < type.enumNames.Length; j++) { if (string.Equals(elementName, type.enumNames[j])) { list.serializedProperty.serializedObject.Update(); type.enumValueIndex = j; current.FindPropertyRelative("Key").stringValue = string.Empty; list.serializedProperty.serializedObject.ApplyModifiedProperties(); break; } } })); } menu.DropDown(btnrect); }; }
/// <summary> /// Displays open graph panel /// </summary> /// <param name="scrollpoint">Open graph scroll point</param> /// <param name="searchfilter">Open graph search filter</param> /// <param name="Graphs">Graphs list</param> /// <param name="OnOpen">On open action</param> /// <param name="OnCancel">On cancel action</param> /// <param name="OnDelete">On delete action</param> public static void OpenGraphPanel(ref Vector2 scrollpoint, ref string searchfilter, NodeGraph[] Graphs, System.Action <NodeGraph> OnOpen, System.Action OnCancel, System.Action OnDelete) { Vector2 size = new Vector2(350, 320); Rect r = new Rect((Screen.width / 2) - (size.x / 2), (Screen.height / 2) - (size.y / 2), size.x, size.y); GUI.Box(r, "", GUI.skin.FindStyle("WindowBackground")); GUI.BeginGroup(r); GUI.Box(new Rect(0, 0, r.width - 50, 15), "", EditorStyles.toolbar); GUI.Label(new Rect(5, 0, 100, 20), "Open Graph"); if (GUI.Button(new Rect(r.width - 50, 0, 50, 15), "Close", EditorStyles.toolbarButton)) { OnCancel.Invoke(); } Rect searchRect = new Rect(10, 28, r.width - 20, 15); searchfilter = MoonGUI.SearchTextField(searchRect, searchfilter); //EditorGUI.DrawRect(searchRect, Color.blue); Rect ScrollRect = new Rect(5, 50, r.width - 15, r.height - 60); GUI.Box(ScrollRect, "", GUI.skin.FindStyle("AnimationKeyframeBackground")); scrollpoint = GUI.BeginScrollView(ScrollRect, scrollpoint, new Rect(0, 0, ScrollRect.width - 20, Graphs.Length * 25), false, true); if (Graphs != null && Graphs.Length > 0) { for (int i = 0; i < Graphs.Length; i++) { Rect baserect = new Rect(ScrollRect.x, i * 25, ScrollRect.width - 25, 20); NodeGraph current = Graphs[i]; if (current != null) { GraphModuleAttribute module = MoonReflection.GetAttribute(current.GetType(), typeof(GraphModuleAttribute), true) as GraphModuleAttribute; if (module != null) { GUI.Box(baserect, ""); GUI.BeginGroup(baserect); Rect labelrect = new Rect(5, 0, baserect.width * 0.8f, baserect.height); Rect namerect = new Rect(labelrect.x, labelrect.y, labelrect.width * 0.55f, labelrect.height); //EditorGUI.DrawRect(namerect, Color.blue); GUI.Label(namerect, current.name); Rect TypeRect = new Rect(namerect.xMax + 5, labelrect.y, labelrect.width * 0.45f, labelrect.height); GUI.Label(TypeRect, module.Name, GUI.skin.FindStyle("PreToolbar")); //EditorGUI.DrawRect(TypeRect, Color.red); Rect loadrect = new Rect(TypeRect.xMax + 5, TypeRect.y + 2, 15, 15); if (GUI.Button(loadrect, new GUIContent("", "Load"), GUI.skin.FindStyle("OL Plus"))) { OnOpen.Invoke(current); } Rect removerect = new Rect(loadrect.xMax + 5, loadrect.y, 15, 15); if (GUI.Button(removerect, new GUIContent("", "Remove"), GUI.skin.FindStyle("OL Minus"))) { bool ok = EditorUtility.DisplayDialog("Delete", "Are you sure to DELETE the graph '" + current.name + "' ?", "Yes", "No"); if (ok) { AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(current)); OnDelete.Invoke(); } } GUI.EndGroup(); } } else { OnDelete.Invoke(); } } } GUI.EndScrollView(); GUI.EndGroup(); }