Beispiel #1
0
        public static DashGraph CreateEmptyGraph()
        {
            DashGraph graph = ScriptableObject.CreateInstance <DashGraph>();

            ((IInternalGraphAccess)graph).SetVersion(DashCore.GetVersionNumber());
            return(graph);
        }
Beispiel #2
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 #3
0
 public NodeBase Clone(DashGraph p_graph)
 {
     NodeBase node = Create(GetType(), p_graph);
     node._model = _model.Clone();
     node.ValidateUniqueId();
     return node;
 }
Beispiel #4
0
        public static List <NodeBase> DuplicateNodes(DashGraph p_graph, List <NodeBase> p_nodes)
        {
            if (p_nodes == null || p_nodes.Count == 0)
            {
                return(null);
            }

            List <NodeBase> newNodes = new List <NodeBase>();

            foreach (NodeBase node in p_nodes)
            {
                NodeBase clone = node.Clone(p_graph);
                clone.rect = new Rect(node.rect.x + 20, node.rect.y + 20, 0, 0);
                p_graph.Nodes.Add(clone);
                newNodes.Add(clone);
            }

            DashGraph originalGraph = p_nodes[0].Graph;

            // Recreate connections within duplicated part
            foreach (NodeBase node in p_nodes)
            {
                List <NodeConnection> connections =
                    originalGraph.Connections.FindAll(c => c.inputNode == node && p_nodes.Contains(c.outputNode));
                foreach (NodeConnection connection in connections)
                {
                    p_graph.Connect(newNodes[p_nodes.IndexOf(connection.inputNode)], connection.inputIndex,
                                    newNodes[p_nodes.IndexOf(connection.outputNode)], connection.outputIndex);
                }
            }

            return(newNodes);
        }
Beispiel #5
0
        public static void UnpackNodesFromSubGraph(DashGraph p_graph, SubGraphNode p_subGraphNode)
        {
            List <NodeConnection> oldInputConnections =
                p_graph.Connections.FindAll(c => c.inputNode == p_subGraphNode);
            List <NodeConnection> oldOutputConnections =
                p_graph.Connections.FindAll(c => c.outputNode == p_subGraphNode);

            List <NodeBase> newNodes    = DuplicateNodes(p_graph, p_subGraphNode.SubGraph.Nodes);
            List <NodeBase> inputNodes  = newNodes.FindAll(n => n is InputNode);
            List <NodeBase> outputNodes = newNodes.FindAll(n => n is OutputNode);

            foreach (var connection in oldInputConnections)
            {
                var oldConnection = p_graph.Connections.Find(c => c.outputNode == inputNodes[connection.inputIndex]);
                p_graph.Connect(oldConnection.inputNode, oldConnection.inputIndex, connection.outputNode,
                                connection.outputIndex);
            }

            foreach (var connection in oldOutputConnections)
            {
                var oldConnection = p_graph.Connections.Find(c => c.inputNode == outputNodes[connection.outputIndex]);
                p_graph.Connect(connection.inputNode, connection.inputIndex, oldConnection.outputNode,
                                oldConnection.outputIndex);
            }

            inputNodes.ForEach(n => p_graph.DeleteNode(n));
            outputNodes.ForEach(n => p_graph.DeleteNode(n));
            p_graph.DeleteNode(p_subGraphNode);
        }
Beispiel #6
0
        static public NodeBase Create(Type p_nodeType, DashGraph p_graph)
        {
            NodeBase node = (NodeBase)Activator.CreateInstance(p_nodeType);
            node._graph = p_graph;
            node.CreateModel();

            return node;
        }
Beispiel #7
0
        public static NodeBase DuplicateNode(DashGraph p_graph, NodeBase p_node)
        {
            NodeBase clone = p_node.Clone(p_graph);

            clone.rect = new Rect(p_node.rect.x + 20, p_node.rect.y + 20, 0, 0);
            p_graph.Nodes.Add(clone);
            return(clone);
        }
Beispiel #8
0
        public static void CopySelectedNodes(DashGraph p_graph)
        {
            if (p_graph == null || selectedNodes.Count == 0)
            {
                return;
            }

            copiedNodes = selectedNodes.Select(i => p_graph.Nodes[i]).ToList();
        }
Beispiel #9
0
        public static void ImportJSON(DashGraph p_graph)
        {
            string path = EditorUtility.OpenFilePanel("Load JSON", Application.dataPath, "json");

            byte[]        content = File.ReadAllBytes(path);
            List <Object> references = new Object[] { p_graph }.ToList(); // refactor to serialize to acquire all correct ones before deserialization

            p_graph.DeserializeFromBytes(content, DataFormat.JSON, ref references);
        }
Beispiel #10
0
        void InstanceAssetGraph()
        {
            if (_assetGraph == null)
            {
                return;
            }

            _graphInstance = _assetGraph.Clone();
        }
Beispiel #11
0
        public static void EditGraph(DashGraph p_graph, string p_graphPath = "")
        {
            SelectionManager.ClearSelection();

            EditorConfig.editingRootGraph  = p_graph;
            EditorConfig.editingGraphPath  = p_graphPath;
            EditorConfig.editingGraph      = GraphUtils.GetGraphAtPath(p_graph, p_graphPath);
            EditorConfig.editingController = null;
        }
Beispiel #12
0
        public static void CopyNode(NodeBase p_node, DashGraph p_graph)
        {
            if (p_graph == null)
            {
                return;
            }

            copiedNodes.Clear();
            copiedNodes.Add(p_node);
        }
Beispiel #13
0
        public static void ClearSelection()
        {
            DashGraph graph = DashEditorCore.EditorConfig.editingGraph;

            if (graph != null)
            {
                selectedNodes.FindAll(i => i < graph.Nodes.Count).ForEach(n => graph.Nodes[n].Unselect());
            }
            selectedNodes.Clear();
        }
Beispiel #14
0
        public static NodeBase GetSelectedNode(DashGraph p_graph)
        {
            if (p_graph == null)
            {
                return(null);
            }

            return((selectedNodes != null && selectedNodes.Count == 1)
                ? selectedNodes[0] < p_graph.Nodes.Count ? p_graph.Nodes[selectedNodes[0]] : null
                : null);
        }
Beispiel #15
0
        void InstanceAssetGraph()
        {
            if (Model.graphAsset == null)
            {
                return;
            }

            _subGraphInstance = Model.graphAsset.Clone();
            ((IInternalGraphAccess)_subGraphInstance).SetParentGraph(Graph);
            _subGraphInstance.name = Model.id;
        }
Beispiel #16
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 #17
0
        public static DashGraph CreateGraphAsAssetFromPath(string p_path, DashGraph p_graph = null)
        {
            if (p_graph == null)
            {
                p_graph = CreateEmptyGraph();
            }

            AssetDatabase.CreateAsset(p_graph, p_path);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            return(p_graph);
        }
Beispiel #18
0
        void InstanceBoundGraph()
        {
            _graphInstance = ScriptableObject.CreateInstance <DashGraph>();

            // Empty graphs don't self reference
            if (_selfReferenceIndex != -1)
            {
                _boundGraphReferences[_selfReferenceIndex] = _graphInstance;
            }

            _graphInstance.DeserializeFromBytes(_boundGraphData, DataFormat.Binary, ref _boundGraphReferences);
            _graphInstance.isBound = true;
            _graphInstance.name    = "Bound";
        }
Beispiel #19
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 #20
0
        public void BindGraph(DashGraph p_graph)
        {
            _assetGraph           = null;
            _graphInstance        = null;
            _selfReferenceIndex   = -1;
            _boundGraphData       = null;
            _boundGraphReferences = null;

            if (p_graph != null)
            {
                DashGraph graph = p_graph.Clone();
                _boundGraphData     = graph.SerializeToBytes(DataFormat.Binary, ref _boundGraphReferences);
                _selfReferenceIndex = _boundGraphReferences.FindIndex(r => r == graph);
            }
        }
Beispiel #21
0
        public void ChangeGraph(DashGraph p_graph)
        {
            if (Graph != null)
            {
                Graph?.Stop();
            }

            _boundGraphData = new byte[0];
            _assetGraph     = p_graph;

            if (Graph != null)
            {
                Graph.Initialize(this);
            }
        }
Beispiel #22
0
        public static DashGraph CreateGraphAsAssetFile(DashGraph p_graph = null)
        {
            var path = EditorUtility.SaveFilePanelInProject(
                "Create Dash graph",
                "DashGraph",
                "asset",
                "Enter name for new Dash graph.");

            if (path.Length != 0)
            {
                return(CreateGraphAsAssetFromPath(path, p_graph));
            }

            return(null);
        }
Beispiel #23
0
        public static void ExportJSON(DashGraph p_graph)
        {
            var path = EditorUtility.SaveFilePanel(
                "Export Graph JSON",
                Application.dataPath,
                "",
                "json");

            if (!path.IsNullOrWhitespace())
            {
                List <Object> references = new List <Object>();
                byte[]        bytes      = p_graph.SerializeToBytes(DataFormat.JSON, ref references);
                File.WriteAllBytes(path, bytes);
            }
        }
Beispiel #24
0
        void InstanceBoundGraph()
        {
            _subGraphInstance = ScriptableObject.CreateInstance <DashGraph>();

            // Empty graphs don't self reference
            if (_selfReferenceIndex != -1)
            {
                _boundSubGraphReferences[_selfReferenceIndex] = _subGraphInstance;
                _subGraphInstance.DeserializeFromBytes(_boundSubGraphData, DataFormat.Binary, ref _boundSubGraphReferences);
            }

            ((IInternalGraphAccess)_subGraphInstance).SetParentGraph(Graph);
            _subGraphInstance.isBound = true;
            _subGraphInstance.name    = Model.id;
        }
Beispiel #25
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 #26
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 #27
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 #28
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 #29
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 #30
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();
        }