Beispiel #1
0
        public static void CreateBoxAroundSelectedNodes(DashGraph p_graph)
        {
            List <NodeBase> nodes  = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();
            Rect            region = nodes[0].rect;

            nodes.ForEach(n =>
            {
                if (n.rect.xMin < region.xMin)
                {
                    region.xMin = n.rect.xMin;
                }
                if (n.rect.yMin < region.yMin)
                {
                    region.yMin = n.rect.yMin;
                }
                if (n.rect.xMax > region.xMax)
                {
                    region.xMax = n.rect.xMax;
                }
                if (n.rect.yMax > region.yMax)
                {
                    region.yMax = n.rect.yMax;
                }
            });

            p_graph.CreateBox(region);

            DashEditorCore.SetDirty();
        }
Beispiel #2
0
 public virtual void DrawInspector()
 {
     bool invalidate = _model.DrawInspector();
     
     if (invalidate)
     {
         ValidateUniqueId();
         Invalidate();
         DashEditorCore.SetDirty();
     }
 }
Beispiel #3
0
        public override void DrawInspector()
        {
            GUI.color = new Color(1, 0.75f, 0.5f);
            if (GUILayout.Button("Open Editor", GUILayout.Height(40)))
            {
                if (DashEditorCore.EditorConfig.editingController != null)
                {
                    DashEditorCore.EditController(DashEditorCore.EditorConfig.editingController,
                                                  GraphUtils.AddChildPath(DashEditorCore.EditorConfig.editingGraphPath, Model.id));
                }
                else
                {
                    DashEditorCore.EditGraph(DashEditorCore.EditorConfig.editingRootGraph,
                                             GraphUtils.AddChildPath(DashEditorCore.EditorConfig.editingGraphPath, Model.id));
                }
            }

            GUI.color = Color.white;

            if (!Model.useAsset)
            {
                if (GUILayout.Button("Save to Asset"))
                {
                    DashGraph graph = GraphUtils.CreateGraphAsAssetFile(SubGraph);
                    if (graph != null)
                    {
                        Model.useAsset   = true;
                        Model.graphAsset = graph;

                        _subGraphInstance   = null;
                        _selfReferenceIndex = -1;
                        _boundSubGraphData  = null;
                        _boundSubGraphReferences.Clear();
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Bind Graph"))
                {
                    DashGraph graph = SubGraph.Clone();
                    _boundSubGraphData  = graph.SerializeToBytes(DataFormat.Binary, ref _boundSubGraphReferences);
                    _selfReferenceIndex = _boundSubGraphReferences.FindIndex(r => r == graph);

                    Model.useAsset   = false;
                    Model.graphAsset = null;
                }
            }

            GUI.color = Color.white;

            base.DrawInspector();
        }
Beispiel #4
0
        public static void UnpackSelectedSubGraphNode(DashGraph p_graph, SubGraphNode p_subGraphNode)
        {
            if (p_graph == null || p_subGraphNode == null)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Unpack SubGraph");
            selectedNodes.Clear();

            NodeUtils.UnpackNodesFromSubGraph(p_graph, p_subGraphNode);

            DashEditorCore.SetDirty();
        }
Beispiel #5
0
        public static void DuplicateSelectedNodes(DashGraph p_graph)
        {
            if (p_graph == null || selectedNodes.Count == 0)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Duplicate Nodes");

            List <NodeBase> nodes    = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();
            List <NodeBase> newNodes = NodeUtils.DuplicateNodes(p_graph, nodes);

            selectedNodes = newNodes.Select(n => n.Index).ToList();

            DashEditorCore.SetDirty();
        }
Beispiel #6
0
        public void StartPreview(NodeBase p_node)
        {
            // Debug.Log("EditorCore.StartPreview");

            if (Controller == null || _isPreviewing || !Controller.gameObject.activeSelf)
            {
                return;
            }

            _previewNodeIndex = DashEditorCore.EditorConfig.editingGraph.Nodes.IndexOf(p_node);

            _stage = PrefabStageUtility.GetCurrentPrefabStage();

            _controllerSelected = Selection.activeGameObject == Controller.gameObject;

            Controller.previewing = true;
            // Debug.Log("Set controller dirty");
            DashEditorCore.SetDirty();

            if (_stage == null)
            {
                // Debug.Log("Save Open Scenes");
                EditorSceneManager.SaveOpenScenes();
            }
            else
            {
                bool state = (bool)_stage.GetType()
                             .GetMethod("SavePrefab", BindingFlags.Instance | BindingFlags.NonPublic)
                             .Invoke(_stage, new object[] { });
            }

            _isPreviewing   = true;
            _previewStarted = false;

            ExpressionEvaluator.ClearCache();

            // Debug.Log("Fetch Global Variables");
            //VariableUtils.FetchGlobalVariables();

            // Debug.Log("Cloning preview graph");
            _previewGraph = DashEditorCore.EditorConfig.editingGraph.Clone();
            _previewGraph.Initialize(Controller);
            DashEditorCore.EditorConfig.editingGraph = _previewGraph;
            // Debug.Log("Start preview");

            EditorApplication.update += OnUpdate;
        }
Beispiel #7
0
        public void StopPreview()
        {
            DashTween.CleanAll();
            DashTweenCore.Uninitialize();
            DashCore.Instance.CleanPrefabPools();
            DashCore.Instance.CleanSequencers();

            EditorApplication.update -= OnUpdate;

            if (!_isPreviewing)
            {
                return;
            }

            _isPreviewing = false;

            if (_stage == null)
            {
                // Since we can do almost anything in preview we need to reload the scene before it
                EditorSceneManager.OpenScene(EditorSceneManager.GetActiveScene().path);

                DashController[] controllers = GameObject.FindObjectsOfType <DashController>();
                DashController   controller  = controllers.ToList().Find(c => c.previewing);
                DashEditorCore.EditController(controller, DashEditorCore.EditorConfig.editingGraphPath);
                controller.previewing = false;

                EditorUtility.SetDirty(controller);
                EditorSceneManager.SaveOpenScenes();

                Selection.activeGameObject = controller.gameObject;
            }
            else
            {
                _stage.GetType().GetMethod("ReloadStage", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_stage, new object[] {});

                DashController[] controllers = _stage.prefabContentsRoot.GetComponentsInChildren <DashController>();
                DashController   controller  = controllers.ToList().Find(c => c.previewing);
                DashEditorCore.EditController(controller, DashEditorCore.EditorConfig.editingGraphPath);
                controller.previewing = false;
                if (_controllerSelected)
                {
                    Selection.objects = new Object[] { controller.gameObject };
                }

                bool state = (bool)_stage.GetType().GetMethod("SavePrefab", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(_stage, new object[] {});
            }
        }
Beispiel #8
0
        public static void DeleteNode(NodeBase p_node, DashGraph p_graph)
        {
            if (p_graph == null)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Delete Node");

            int index = p_node.Index;

            p_graph.DeleteNode(p_node);
            selectedNodes.Remove(index);
            ReindexSelected(index);

            DashEditorCore.SetDirty();
        }
Beispiel #9
0
        public static void DeleteSelectedNodes(DashGraph p_graph)
        {
            if (p_graph == null || selectedNodes.Count == 0)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Delete Nodes");

            var nodes = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();

            nodes.ForEach(n => p_graph.DeleteNode(n));

            selectedNodes = new List <int>();

            DashEditorCore.SetDirty();
        }
Beispiel #10
0
        public static void DuplicateNode(NodeBase p_node, DashGraph p_graph)
        {
            if (p_graph == null)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Duplicate Node");

            NodeBase node = NodeUtils.DuplicateNode(p_graph, (NodeBase)p_node);

            selectedNodes = new List <int> {
                node.Index
            };

            DashEditorCore.SetDirty();
        }
Beispiel #11
0
        public static void CreateSubGraphFromSelectedNodes(DashGraph p_graph)
        {
            if (p_graph == null || selectedNodes.Count == 0)
            {
                return;
            }

            UndoUtils.RegisterCompleteObject(p_graph, "Create SubGraph");

            List <NodeBase> nodes        = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();
            SubGraphNode    subGraphNode = NodeUtils.PackNodesToSubGraph(p_graph, nodes);

            selectedNodes.Clear();
            selectedNodes.Add(subGraphNode.Index);

            DashEditorCore.SetDirty();
        }
Beispiel #12
0
        public void DrawGUI()
        {
            Rect offsetRect = new Rect(rect.x + Graph.viewOffset.x, rect.y + Graph.viewOffset.y, rect.width, rect.height);

            GUI.color = color;

            GUI.Box(offsetRect, "", DashEditorCore.Skin.GetStyle("GraphBox"));

            Rect titleRect = new Rect(offsetRect.x + 12, offsetRect.y, offsetRect.width, 40);

            if (Event.current.type == EventType.MouseDown && titleRect.Contains(Event.current.mousePosition))
            {
                if (EditorApplication.timeSinceStartup - _lastClickTime < 0.3)
                {
                    DashEditorCore.editingBoxComment = this;
                }
                _lastClickTime = EditorApplication.timeSinceStartup;
            }

            GUI.DrawTexture(new Rect(offsetRect.x + offsetRect.width - 32, offsetRect.y + offsetRect.height - 32, 32, 32), IconManager.GetIcon("Resize_Icon"));
            GUI.color = Color.white;
            GUIStyle style = new GUIStyle();

            style.fontStyle        = FontStyle.Bold;
            style.fontSize         = 24;
            style.normal.textColor = Color.white;
            style.alignment        = TextAnchor.LowerLeft;
            if (DashEditorCore.editingBoxComment == this)
            {
                EditorGUI.BeginChangeCheck();
                comment = GUI.TextField(titleRect, comment, style);
                if (EditorGUI.EndChangeCheck())
                {
                    DashEditorCore.SetDirty();
                }
            }
            else
            {
                GUI.Label(titleRect, comment, style);
            }
        }
Beispiel #13
0
        public static void PasteNodes(Vector3 p_mousePosition, DashGraph p_graph)
        {
            if (p_graph == null || copiedNodes.Count == 0)
            {
                return;
            }

            List <NodeBase> newNodes = NodeUtils.DuplicateNodes(p_graph, copiedNodes);

            newNodes[0].rect = new Rect(p_mousePosition.x * zoom - p_graph.viewOffset.x,
                                        p_mousePosition.y * zoom - p_graph.viewOffset.y, 0, 0);

            for (int i = 1; i < newNodes.Count; i++)
            {
                NodeBase node = newNodes[i];
                node.rect.x = newNodes[0].rect.x + (node.rect.x - copiedNodes[0].rect.x);
                node.rect.y = newNodes[0].rect.y + (node.rect.y - copiedNodes[0].rect.y);
            }

            selectedNodes = newNodes.Select(n => n.Index).ToList();

            DashEditorCore.SetDirty();
        }
Beispiel #14
0
        public static NodeBase CreateNode(DashGraph p_graph, Type p_nodeType, Vector2 p_position)
        {
            if (!NodeUtils.CanHaveMultipleInstances(p_nodeType) && p_graph.GetNodeByType(p_nodeType) != null)
            {
                return(null);
            }

            Undo.RegisterCompleteObjectUndo(p_graph, "Create " + NodeBase.GetNodeNameFromType(p_nodeType));

            NodeBase node = NodeBase.Create(p_nodeType, p_graph);

            if (node != null)
            {
                float zoom = DashEditorCore.EditorConfig.zoom;
                node.rect = new Rect(p_position.x, p_position.y, 0, 0);
                p_graph.Nodes.Add(node);
            }

            //Debug.Log(EditorUtility.IsDirty(p_graph));
            DashEditorCore.SetDirty();

            return(node);
        }
Beispiel #15
0
        public virtual bool DrawInspector()
        {
            bool initializeMinimization = false;

            if (groupsMinized == -1)
            {
                initializeMinimization = true;
                groupsMinized          = 0;
            }

            GUILayout.Space(5);

            GUIStyle minStyle = GUIStyle.none;

            minStyle.normal.textColor = Color.white;
            minStyle.fontSize         = 16;

            var fields = this.GetType().GetFields();

            Array.Sort(fields, GUIPropertiesUtils.GroupSort);
            string lastGroup          = "";
            bool   lastGroupMinimized = false;
            bool   invalidate         = false;
            int    groupIndex         = 0;

            foreach (var field in fields)
            {
                if (field.IsConstant())
                {
                    continue;
                }

                TitledGroupAttribute ga = field.GetCustomAttribute <TitledGroupAttribute>();
                string currentGroup     = ga != null ? ga.Group : "Properties";
                if (currentGroup != lastGroup)
                {
                    int groupMask = (int)Math.Pow(2, groupIndex);
                    groupIndex++;
                    if (initializeMinimization && ga != null && ga.Minimized && (groupsMinized & groupMask) == 0)
                    {
                        groupsMinized += groupMask;
                    }

                    GUIPropertiesUtils.Separator(16, 2, 4, new Color(0.1f, 0.1f, 0.1f));
                    GUILayout.Label(currentGroup, DashEditorCore.Skin.GetStyle("PropertyGroup"),
                                    GUILayout.Width(120));
                    Rect lastRect = GUILayoutUtility.GetLastRect();


                    if (GUI.Button(new Rect(lastRect.x + 302, lastRect.y - 25, 20, 20), (groupsMinized & groupMask) != 0 ? "+" : "-",
                                   minStyle))
                    {
                        groupsMinized = (groupsMinized & groupMask) == 0
                            ? groupsMinized + groupMask
                            : groupsMinized - groupMask;
                    }

                    lastGroup          = currentGroup;
                    lastGroupMinimized = (groupsMinized & groupMask) != 0;
                }

                if (lastGroupMinimized)
                {
                    continue;
                }

                invalidate = invalidate || GUIPropertiesUtils.PropertyField(field, this, null);
            }

            if (invalidate)
            {
                DashEditorCore.SetDirty();
            }

            return(invalidate);
        }
Beispiel #16
0
        private void DrawConnectors(Rect p_rect)
        {
            GUISkin skin = DashEditorCore.Skin;

            // Inputs
            int count = InputCount;
            for (int i = 0; i < count; i++)
            {
                bool isConnected = Graph.HasInputConnected(this, i);
                GUI.color = isConnected
                    ? DashEditorCore.EditorConfig.theme.ConnectorInputConnectedColor
                    : DashEditorCore.EditorConfig.theme.ConnectorInputDisconnectedColor;

                if (IsExecuting)
                    GUI.color = Color.cyan;

                var connectorRect = GetConnectorRect(true, i);
                
                if (GUI.Button(connectorRect, "", skin.GetStyle(isConnected ? "NodeConnectorOn" : "NodeConnectorOff")))
                {
                    if (Event.current.button == 0)
                    {
                        if (Graph.connectingNode != null && Graph.connectingNode != this)
                        {
                            Undo.RegisterCompleteObjectUndo(_graph, "Connect node");
                            Graph.Connect(this, i, Graph.connectingNode, Graph.connectingOutputIndex);
                            DashEditorCore.SetDirty();
                            Graph.connectingNode = null;
                        }
                    }
                }
            }
            
            // Outputs
            for (int i = 0; i < OutputCount; i++)
            {
                bool isConnected = Graph.HasOutputConnected(this, i);
                GUI.color = isConnected
                    ? DashEditorCore.EditorConfig.theme.ConnectorOutputConnectedColor
                    : DashEditorCore.EditorConfig.theme.ConnectorOutputDisconnectedColor;

                if (Graph.connectingNode == this && Graph.connectingOutputIndex == i)
                    GUI.color = Color.green;

                var connectorRect = GetConnectorRect(false, i);
                
                if (connectorRect.Contains(Event.current.mousePosition - new Vector2(p_rect.x, p_rect.y)))
                    GUI.color = Color.green;

                if (OutputLabels != null && OutputLabels.Length > i && DashEditorCore.DetailsVisible)
                {
                    GUIStyle style = new GUIStyle();
                    style.normal.textColor = Color.white;
                    style.alignment = TextAnchor.MiddleRight;
                    GUI.Label(new Rect(connectorRect.x - 100, connectorRect.y, 100, 20), OutputLabels[i], style);
                }

                if (GUI.Button(connectorRect, "", skin.GetStyle(isConnected ? "NodeConnectorOn" : "NodeConnectorOff")))
                {
                    Graph.connectingOutputIndex = i;
                    Graph.connectingNode = this;
                }
            }

            GUI.color = Color.white;
        }