コード例 #1
0
        public void LoadXML(string xml)
        {
            if (rootNode == null && (rootNode = nodes.Find((Node n) => n.GetID == EditorAIRootNode.ID) as EditorAIRootNode) == null)
            {
                rootNode = Node.Create(EditorAIRootNode.ID, Vector2.zero, this) as EditorAIRootNode;
            }

            Debug.Log("Loading");

            XmlSerializer ser = new XmlSerializer(typeof(AINode), nodeTypes);
            StringReader  sr  = new StringReader(xml);

            try
            {
                object o = ser.Deserialize(sr);
                if (o is AINode)
                {
                    EditorAINode editorNode = LoadNode(o as AINode);
                    editorNode.Parent.ApplyConnection(rootNode.child);

                    LayoutNodes(rootNode, 0, 10, 0, 100);
                    AdjustLayout(rootNode, -rootNode.position);

                    Debug.Log("Done");
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            sr.Close();
        }
コード例 #2
0
        private void SaveNode(EditorAIRootNode node)
        {
            try
            {
                string fileName = node.treeName;
                if (fileName == "*")
                {
                    fileName = Path.GetFileName(saveName);
                }

                XmlSerializer ser = new XmlSerializer(typeof(AINode), nodeTypes);
                StringWriter  sw  = new StringWriter();
                ser.Serialize(sw, node.GetTreeNode());
                string xml = sw.ToString();
                //Debug.Log(xml);
                sw.Close();
                string dir = Application.dataPath + "/AI/Resources/AITree/";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                string path = dir + fileName + ".xml";
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
                File.WriteAllText(path, xml);
            }
            catch (Exception e)
            {
                //Debug.LogError(e.ToString());
            }
        }
コード例 #3
0
 protected override void OnCreate()
 {
     base.OnCreate();
     rootNode = nodes.Find(x => x.GetType() == typeof(EditorAIRootNode)) as EditorAIRootNode;
     if (rootNode == null)
     {
         rootNode = Node.Create(EditorAIRootNode.ID, Vector2.zero, this) as EditorAIRootNode;
     }
 }
コード例 #4
0
        public override void OnBeforeSavingCanvas()
        {
            string output = "";

            foreach (var node in nodes)
            {
                output += node.GetType().ToString() + "\n";
                EditorAIRootNode rootNode = node as EditorAIRootNode;
                if (rootNode != null)
                {
                    SaveNode(rootNode);
                }
            }
            base.OnBeforeSavingCanvas();
        }
コード例 #5
0
        protected override void ValidateSelf()
        {
            DynamicInit();
            if (rootNode == null && (rootNode = nodes.Find((Node n) => n.GetID == EditorAIRootNode.ID) as EditorAIRootNode) == null)
            {
                rootNode = Node.Create(EditorAIRootNode.ID, Vector2.zero, this) as EditorAIRootNode;
            }
            base.ValidateSelf();

            if (filepath != "")
            {
                try
                {
                    File.WriteAllText(filepath, rootNode.GetXML());
                }
                catch
                {
                }
            }
        }