Exemplo n.º 1
0
        public void DeserializeData()
        {
            BehaviorTreeBlueprintData mainData = editorWindow.CurrentData;

            if (mainData == null)
            {
                throw new Exception("No current data to deserialize!");
            }

            stopwatch.Restart();

            //Clear everything
            BehaviorTreeNodeAttribute.RescanAttributes();
            graphView.DeleteAllElements();
            RecalculateNodeInfo();

            //Setup data
            allData = mainData.allNodes;

            //Start
            for (int i = 0; i < mainData.rootNodes.Length; i++)
            {
                DeserializeNode(allData[mainData.rootNodes[i]]);                 //Deserialize branch
            }

            stopwatch.Stop();
            DebugHelper.Log($"Deserialized in {stopwatch.Elapsed.TotalMilliseconds} ms.");
        }
Exemplo n.º 2
0
        public static void Open(BehaviorTreeBlueprintData data)
        {
            var window = GetWindow <TreeGraphEditorWindow>("Graph Editor");

            window.CurrentData = data;
            window.minSize     = new Vector2(500f, 300f);
        }
Exemplo n.º 3
0
        public void SerializeCurrent()
        {
            BehaviorTreeBlueprintData mainData = editorWindow.CurrentData;

            if (mainData == null)
            {
                throw new Exception("No current data to serialize!");
            }

            stopwatch.Restart();

            //Clear
            if (mainData.allNodes == null)
            {
                mainData.allNodes = new List <TreeNodeData>();
            }
            allData = mainData.allNodes;

            allData.Clear();

            //Start
            foreach (TreeGraphNode rootNode in from nativeNode in graphView.nodes.ToList()
                     let node = (TreeGraphNode)nativeNode
                                where node.ParentPort == null || !node.ParentPort.connected
                                select node)
            {
                int index = SerializeNode(rootNode);                 //Serialize branch

                if (rootNode is RootNode)
                {
                    mainData.mainRootNode = index;
                }
                rootNodesIndexCache.Add(index);
            }

            mainData.rootNodes = rootNodesIndexCache.ToArray();
            rootNodesIndexCache.Clear();

            EditorUtility.SetDirty(mainData);

            stopwatch.Stop();
            DebugHelper.Log($"Serialized in {stopwatch.Elapsed.TotalMilliseconds} ms.");
        }