Esempio n. 1
0
 void OnFocus()
 {
     current     = this;
     graphEditor = NodeGraphEditor.GetEditor(graph);
     if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave)
     {
         AssetDatabase.SaveAssets();
     }
 }
Esempio n. 2
0
        /// <summary> Create editor window </summary>
        public static NodeEditorWindow Init()
        {
            NodeEditorWindow w = CreateInstance <NodeEditorWindow>();

            w.titleContent   = new GUIContent("xNode");
            w.wantsMouseMove = true;
            w.Show();
            return(w);
        }
 public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Edit graph", GUILayout.Height(40)))
     {
         SerializedProperty graphProp = serializedObject.FindProperty("graph");
         NodeEditorWindow   w         = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
         w.Home(); // Focus selected node
     }
     base.OnInspectorGUI();
 }
Esempio n. 4
0
 public static bool OnOpen(int instanceID, int line)
 {
     XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph;
     if (nodeGraph != null)
     {
         NodeEditorWindow w = Init();
         w.graph = nodeGraph;
         return(true);
     }
     return(false);
 }
Esempio n. 5
0
        void OnFocus()
        {
            current = this;
            ValidateGraphEditor();
            if (graphEditor != null)
            {
                graphEditor.OnWindowFocus();
            }

            dragThreshold = Math.Max(1f, Screen.width / 1000f);
        }
Esempio n. 6
0
        public static void TryOpen(XNode.NodeGraph graph)
        {
            NodeEditorWindow w = Init();

            w.wantsMouseMove = true;

            if (graph != null)
            {
                w.graph = graph;
            }
        }
Esempio n. 7
0
 /// <summary> Create a node and save it in the graph asset </summary>
 public virtual XNode.Node CreateNode(Type type, Vector2 position) {
     Undo.RecordObject(target, "Create Node");
     XNode.Node node = target.AddNode(type);
     Undo.RegisterCreatedObjectUndo(node, "Create Node");
     node.position = position;
     if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);
     if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(target))) AssetDatabase.AddObjectToAsset(node, target);
     if (NodeEditorPreferences.GetSettings().autoSave) AssetDatabase.SaveAssets();
     NodeEditorWindow.RepaintAll();
     return node;
 }
Esempio n. 8
0
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Edit graph", GUILayout.Height(40)))
            {
                NodeEditorWindow.Open(serializedObject.targetObject as XNode.NodeGraph);
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight);
            GUILayout.Label("Raw data", "BoldLabel");

            base.OnInspectorGUI();
        }
        /// <summary> Create a node and save it in the graph asset </summary>
        public virtual void CreateNode(Type type, Vector2 position)
        {
            INode node = Target.AddNode(type);

            node.Position = position;
            node.Name     = UnityEditor.ObjectNames.NicifyVariableName(type.Name);
            if (NodeEditorPreferences.GetSettings().autoSave)
            {
                AssetDatabase.SaveAssets();
            }
            NodeEditorWindow.RepaintAll();
        }
Esempio n. 10
0
        private static void TypeColorsGUI()
        {
            //Label
            EditorGUILayout.LabelField("Type colors", EditorStyles.boldLabel);

            //Get saved type keys
            string[] typeKeys = new string[typeColors.Count];
            typeColors.Keys.CopyTo(typeKeys, 0);
            //Display saved type colors
            foreach (var key in typeKeys)
            {
                EditorGUILayout.BeginHorizontal();
                if (!EditorGUILayout.Toggle(new GUIContent(key, key), true))
                {
                    typeColors.Remove(key);
                    SavePrefs();
                    EditorGUILayout.EndHorizontal();
                    continue;
                }
                Color col = typeColors[key];
                col             = EditorGUILayout.ColorField(col);
                typeColors[key] = col;
                EditorGUILayout.EndHorizontal();
            }
            if (GUI.changed)
            {
                SavePrefs();
                NodeEditorWindow.RepaintAll();
            }

            //Get generated type keys
            string[] generatedTypeKeys = new string[generatedTypeColors.Count];
            generatedTypeColors.Keys.CopyTo(generatedTypeKeys, 0);
            //Display generated type colors
            foreach (var key in generatedTypeKeys)
            {
                EditorGUILayout.BeginHorizontal();
                if (EditorGUILayout.Toggle(new GUIContent(key, key), false))
                {
                    typeColors.Add(key, generatedTypeColors[key]);
                    generatedTypeColors.Remove(key);
                    SavePrefs();
                    EditorGUILayout.EndHorizontal();
                    continue;
                }
                Color col = generatedTypeColors[key];
                EditorGUI.BeginDisabledGroup(true);
                col = EditorGUILayout.ColorField(col);
                EditorGUI.EndDisabledGroup();

                EditorGUILayout.EndHorizontal();
            }
        }
Esempio n. 11
0
 public static bool OnOpen(int instanceID, int line)
 {
     XNode.NodeGraph nodeGraph = EditorUtility.InstanceIDToObject(instanceID) as XNode.NodeGraph;
     if (nodeGraph != null)
     {
         NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;
         w.wantsMouseMove = true;
         w.graph          = nodeGraph;
         return(true);
     }
     return(false);
 }
Esempio n. 12
0
        /// <summary>Open the provided graph in the NodeEditor</summary>
        public static void Open(XNode.NodeGraph graph)
        {
            if (!graph)
            {
                return;
            }

            NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "xNode", true) as NodeEditorWindow;

            w.wantsMouseMove = true;
            w.graph          = graph;
        }
Esempio n. 13
0
 private static void NodeSettingsGUI(string key, Settings settings)
 {
     //Label
     EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
     settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
     settings.noodleType     = (NoodleType)EditorGUILayout.EnumPopup("Noodle type", (Enum)settings.noodleType);
     if (GUI.changed)
     {
         SavePrefs(key, settings);
         NodeEditorWindow.RepaintAll();
     }
     EditorGUILayout.Space();
 }
Esempio n. 14
0
        /// <summary>Open the provided graph in the NodeEditor</summary>
        public static NodeEditorWindow Open(XNode.NodeGraph graph)
        {
            if (!graph)
            {
                return(null);
            }

            NodeEditorWindow w = GetWindow(typeof(NodeEditorWindow), false, "Dialog Ediitor", true) as NodeEditorWindow;

            w.wantsMouseMove = true;
            w.graph          = graph;
            return(w);
        }
Esempio n. 15
0
 void OnFocus()
 {
     current = this;
     ValidateGraphEditor();
     if (graphEditor != null)
     {
         graphEditor.OnWindowFocus();
         if (NodeEditorPreferences.GetSettings().autoSave)
         {
             AssetDatabase.SaveAssets();
         }
     }
 }
Esempio n. 16
0
        /// <summary> Delete all prefs </summary>
        public static void ResetPrefs()
        {
            if (EditorPrefs.HasKey("xNode.Settings"))
            {
                EditorPrefs.DeleteKey("xNode.Settings");
            }

            settings      = LoadPrefs();
            typeColors    = new Dictionary <string, Color>();
            _gridTexture  = NodeEditorResources.GenerateGridTexture(settings.gridLineColor, settings.gridBgColor);
            _crossTexture = NodeEditorResources.GenerateCrossTexture(settings.gridLineColor);
            NodeEditorWindow.RepaintAll();
        }
Esempio n. 17
0
 /// <summary> Delete all prefs </summary>
 public static void ResetPrefs()
 {
     if (EditorPrefs.HasKey(lastKey))
     {
         EditorPrefs.DeleteKey(lastKey);
     }
     if (settings.ContainsKey(lastKey))
     {
         settings.Remove(lastKey);
     }
     typeColors = new Dictionary <Type, Color>();
     VerifyLoaded();
     NodeEditorWindow.RepaintAll();
 }
Esempio n. 18
0
        public override void OnInspectorGUI()
        {
            if (GUILayout.Button("Edit graph", GUILayout.Height(40)))
            {
                SerializedProperty graphProp = serializedObject.FindProperty("graph");
                NodeEditorWindow   w         = NodeEditorWindow.Open(graphProp.objectReferenceValue as XNode.NodeGraph);
                w.Home(); // Focus selected node
            }

            GUILayout.Space(EditorGUIUtility.singleLineHeight);
            GUILayout.Label("Raw data", "BoldLabel");

            base.OnInspectorGUI();
        }
Esempio n. 19
0
 /// <summary> Create a node and save it in the graph asset </summary>
 public virtual void CreateNode(Type type, Vector2 position)
 {
     XNode.Node node = target.AddNode(type);
     node.position = position;
     if (string.IsNullOrEmpty(node.name))
     {
         node.name = UnityEditor.ObjectNames.NicifyVariableName(type.Name);
     }
     AssetDatabase.AddObjectToAsset(node, target);
     if (NodeEditorPreferences.GetSettings().autoSave)
     {
         AssetDatabase.SaveAssets();
     }
     NodeEditorWindow.RepaintAll();
 }
Esempio n. 20
0
 /// <summary> Create a node and save it in the graph asset </summary>
 public virtual void CreateNode(Type type, Vector2 position)
 {
     XNode.Node node = target.AddNode(type);
     node.position = position;
     if (node.name == null || node.name.Trim() == "")
     {
         node.name = NodeEditorUtilities.NodeDefaultName(type);
     }
     AssetDatabase.AddObjectToAsset(node, target);
     if (NodeEditorPreferences.GetSettings().autoSave)
     {
         AssetDatabase.SaveAssets();
     }
     NodeEditorWindow.RepaintAll();
 }
Esempio n. 21
0
        void OnFocus()
        {
            current = this;
            ValidateGraphEditor();
            if (graphEditor != null)
            {
                graphEditor.OnWindowFocus();
                if (NodeEditorPreferences.GetSettings().autoSave)
                {
                    AssetDatabase.SaveAssets();
                }
            }

            dragThreshold = Math.Max(1f, Screen.width / 1000f);
        }
Esempio n. 22
0
        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));
        }
Esempio n. 23
0
 private static void NodeSettingsGUI(string key, Settings settings)
 {
     //Label
     EditorGUILayout.LabelField("Node", EditorStyles.boldLabel);
     settings.highlightColor = EditorGUILayout.ColorField("Selection", settings.highlightColor);
     settings.noodleType     = (NoodleType)EditorGUILayout.EnumPopup("Noodle type", (Enum)settings.noodleType);
     settings.portTooltips   = EditorGUILayout.Toggle("Port Tooltips", settings.portTooltips);
     settings.dragToCreate   = EditorGUILayout.Toggle(new GUIContent("Drag to Create", "Drag a port connection anywhere on the grid to create and connect a node"), settings.dragToCreate);
     if (GUI.changed)
     {
         SavePrefs(key, settings);
         NodeEditorWindow.RepaintAll();
     }
     EditorGUILayout.Space();
 }
Esempio n. 24
0
        private static void GridSettingsGUI(string key, Settings settings)
        {
            //Label
            EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel);
            settings.gridSnap = EditorGUILayout.Toggle("Snap", settings.gridSnap);

            settings.gridLineColor = EditorGUILayout.ColorField("Color", settings.gridLineColor);
            settings.gridBgColor   = EditorGUILayout.ColorField(" ", settings.gridBgColor);
            if (GUI.changed)
            {
                SavePrefs(key, settings);

                NodeEditorWindow.RepaintAll();
            }
            EditorGUILayout.Space();
        }
Esempio n. 25
0
        private static void GridSettingsGUI()
        {
            //Label
            EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel);
            settings.gridSnap = EditorGUILayout.Toggle("Snap", settings.gridSnap);

            settings.gridLineColor = EditorGUILayout.ColorField("Color", settings.gridLineColor);
            settings.gridBgColor   = EditorGUILayout.ColorField(" ", settings.gridBgColor);
            if (GUI.changed)
            {
                SavePrefs();
                _gridTexture  = NodeEditorResources.GenerateGridTexture(settings.gridLineColor, settings.gridBgColor);
                _crossTexture = NodeEditorResources.GenerateCrossTexture(settings.gridLineColor);
                NodeEditorWindow.RepaintAll();
            }
            EditorGUILayout.Space();
        }
Esempio n. 26
0
        void OnFocus()
        {
            current = this;
            ValidateGraphEditor();
            var set = NodeEditorPreferences.GetSettings();

            if (graphEditor != null && set != null && set.autoSave)
            {
                try
                {
                    AssetDatabase.SaveAssets();
                }catch (Exception ex)
                {
                    Debug.LogWarning(ex.Message);
                }
            }
        }
Esempio n. 27
0
        private static void GridSettingsGUI(string key, Settings settings)
        {
            //Label
            EditorGUILayout.LabelField("Grid", EditorStyles.boldLabel);
            settings.gridSnap      = EditorGUILayout.Toggle(new GUIContent("Snap", "Hold CTRL in editor to invert"), settings.gridSnap);
            settings.zoomToMouse   = EditorGUILayout.Toggle(new GUIContent("Zoom to Mouse", "Zooms towards mouse position"), settings.zoomToMouse);
            settings.zoomOutLimit  = EditorGUILayout.FloatField(new GUIContent("Zoom out Limit", "Upper limit to zoom"), settings.zoomOutLimit);
            settings.gridLineColor = EditorGUILayout.ColorField("Color", settings.gridLineColor);
            settings.gridBgColor   = EditorGUILayout.ColorField(" ", settings.gridBgColor);
            if (GUI.changed)
            {
                SavePrefs(key, settings);

                NodeEditorWindow.RepaintAll();
            }
            EditorGUILayout.Space();
        }
 public override void OnInspectorGUI()
 {
     if (sceneGraph.graph == null) {
         if (GUILayout.Button("New graph", GUILayout.Height(40))) {
             if (graphType == null) {
                 Type[] graphTypes = NodeEditorReflection.GetDerivedTypes(typeof(NodeGraph));
                 GenericMenu menu = new GenericMenu();
                 for (int i = 0; i < graphTypes.Length; i++) {
                     Type graphType = graphTypes[i];
                     menu.AddItem(new GUIContent(graphType.Name), false, () => CreateGraph(graphType));
                 }
                 menu.ShowAsContext();
             } else {
                 CreateGraph(graphType);
             }
         }
     } else {
         if (GUILayout.Button("Open graph", GUILayout.Height(40))) {
             NodeEditorWindow.Open(sceneGraph.graph);
         }
         if (removeSafely) {
             GUILayout.BeginHorizontal();
             GUILayout.Label("Really remove graph?");
             GUI.color = new Color(1, 0.8f, 0.8f);
             if (GUILayout.Button("Remove")) {
                 removeSafely = false;
                 Undo.RecordObject(sceneGraph, "Removed graph");
                 sceneGraph.graph = null;
             }
             GUI.color = Color.white;
             if (GUILayout.Button("Cancel")) {
                 removeSafely = false;
             }
             GUILayout.EndHorizontal();
         } else {
             GUI.color = new Color(1, 0.8f, 0.8f);
             if (GUILayout.Button("Remove graph")) {
                 removeSafely = true;
             }
             GUI.color = Color.white;
         }
     }
 }
Esempio n. 29
0
        private static void LoadPrefs()
        {
            //Load type colors
            generatedTypeColors = new Dictionary <string, Color>();

            if (!EditorPrefs.HasKey("unec_typecolors"))
            {
                EditorPrefs.SetString("unec_typecolors", "");
            }
            string[] data = EditorPrefs.GetString("unec_typecolors").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            typeColors = new Dictionary <string, Color>();
            for (int i = 0; i < data.Length; i += 2)
            {
                Color col;
                if (ColorUtility.TryParseHtmlString("#" + data[i + 1], out col))
                {
                    typeColors.Add(data[i], col);
                }
            }

            //Load grid colors
            if (!EditorPrefs.HasKey("unec_gridcolor0"))
            {
                EditorPrefs.SetString("unec_gridcolor0", ColorUtility.ToHtmlStringRGB(new Color(0.45f, 0.45f, 0.45f)));
            }
            ColorUtility.TryParseHtmlString("#" + EditorPrefs.GetString("unec_gridcolor0"), out _gridLineColor);
            if (!EditorPrefs.HasKey("unec_gridcolor1"))
            {
                EditorPrefs.SetString("unec_gridcolor1", ColorUtility.ToHtmlStringRGB(new Color(0.18f, 0.18f, 0.18f)));
            }
            ColorUtility.TryParseHtmlString("#" + EditorPrefs.GetString("unec_gridcolor1"), out _gridBgColor);

            //Load snap option
            if (EditorPrefs.HasKey("unec_gridsnap"))
            {
                _gridSnap = EditorPrefs.GetBool("unec_gridsnap");
            }

            _gridTexture  = NodeEditorResources.GenerateGridTexture(_gridLineColor, _gridBgColor);
            _crossTexture = NodeEditorResources.GenerateCrossTexture(_gridLineColor);
            NodeEditorWindow.RepaintAll();
            prefsLoaded = true;
        }
Esempio n. 30
0
        /// <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);
            }
        }