Example #1
0
 public void SetExecutingNode(AINode node)
 {
     if (!m_ListExecutingNodes.Contains(node))
     {
         m_ListExecutingNodes.Add(node);
     }
 }
Example #2
0
 public void RemoveExecutingNode(AINode node)
 {
     if (m_ListExecutingNodes.Contains(node))
     {
         m_ListExecutingNodes.Remove(node);
     }
 }
Example #3
0
        public AINode GetRoot()
        {
            AINode root = this;

            while (root.m_Parent != null)
            {
                root = root.m_Parent;
            }
            return(root);
        }
Example #4
0
        public List <AINode> GetGenerations()
        {
            List <AINode> gens = new List <AINode>();
            AINode        node = this;

            do
            {
                gens.Add(node);
                node = node.m_Parent;
            } while (node != null);
            gens.Reverse();
            return(gens);
        }
Example #5
0
        public static AINode Create(JsonData data, AI ai)
        {
            AINode           node   = null;
            AINodeConfigData config = new AINodeConfigData();

            config.name = data["name"].ToString();
            if (data.Keys.Contains("type"))
            {
                config.type = int.Parse(data["type"].ToString());
            }
            if (data.Keys.Contains("weight"))
            {
                config.weight = int.Parse(data["weight"].ToString());
            }
            if (data.Keys.Contains("scriptName"))
            {
                config.scriptName = data["scriptName"].ToString();
            }
            if (config.scriptName != "")
            {
                TextAsset txt = Resources.Load <TextAsset>(config.scriptName);
                config.script = txt.text;
            }
            else
            {
                config.script = "function detect()return true end";
            }
            if (data["children"].IsArray && data["children"].Count > 0)
            {
                node = new ControlNode(ai, config);
                foreach (JsonData childData in data["children"])
                {
                    var child = Create(childData, ai);
                    node.Config.listAINodeConfigData.Add(child.Config);
                    node.Add(child);
                }
            }
            else
            {
                node = new ActionNode(ai, config);
            }

            return(node);
        }
Example #6
0
        /// <summary>
        /// 通过AINodeConfigData根节点生成AINode
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="owner"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static AINode Create(AINodeConfigData data, AI ai)
        {
            AINode    node = null;
            TextAsset txt  = Resources.Load <TextAsset>(data.scriptName);

            data.script = txt.text;
            if (data.listAINodeConfigData.Count > 0)
            {
                node = new ControlNode(ai, data);
                foreach (var c in data.listAINodeConfigData)
                {
                    var child = Create(c, ai);
                    node.Add(child);
                }
            }
            else
            {
                node = new ActionNode(ai, data);
            }
            return(node);
        }
Example #7
0
        public static AINode Create(byte[] bytes, AI ai)
        {
            AINode           node   = null;
            ByteBuffer       buffer = new ByteBuffer(bytes);
            AINodeConfigData config = new AINodeConfigData();

            config.name       = buffer.ReadString();
            config.type       = buffer.ReadByte();
            config.scriptName = buffer.ReadString();
            config.weight     = buffer.ReadInt32();
            buffer.ReadFloat();
            buffer.ReadFloat();
            if (config.scriptName != "")
            {
                TextAsset txt = Resources.Load <TextAsset>(config.scriptName);
                config.script = txt.text;
            }
            else
            {
                config.script = "function detect()return true end";
            }
            int count = buffer.ReadInt32();

            if (count > 0)
            {
                node = new ControlNode(ai, config);
                for (int i = 0; i < count; ++i)
                {
                    var child = Create(buffer.ReadBytes(), ai);
                    node.Config.listAINodeConfigData.Add(child.Config);
                    node.Add(child);
                }
            }
            else
            {
                node = new ActionNode(ai, config);
            }
            return(node);
        }
Example #8
0
 public void Init()
 {
     m_Root = AINodeConfigData.Create(m_TextDataAiTree.bytes, this);
     m_Root.OnExitHandler = OnAiExitHandler;
 }
Example #9
0
 public bool Remove(AINode node)
 {
     m_IntChildWeight -= node.Config.weight;
     return(m_Children.Remove(node));
 }
Example #10
0
 public void Add(AINode node)
 {
     m_Children.Add(node);
     node.SetParent(this);
     m_IntChildWeight += node.Config.weight;
 }
Example #11
0
 public void SetParent(AINode parent)
 {
     m_Parent = parent;
 }