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

            while (root.m_Parent != null)
            {
                root = root.m_Parent;
            }
            return(root);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#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);
        }
示例#8
0
 public void Init()
 {
     m_Root = AINodeConfigData.Create(m_TextDataAiTree.bytes, this);
     m_Root.OnExitHandler = OnAiExitHandler;
 }
示例#9
0
 public bool Remove(AINode node)
 {
     m_IntChildWeight -= node.Config.weight;
     return(m_Children.Remove(node));
 }
示例#10
0
 public void Add(AINode node)
 {
     m_Children.Add(node);
     node.SetParent(this);
     m_IntChildWeight += node.Config.weight;
 }
示例#11
0
 public void SetParent(AINode parent)
 {
     m_Parent = parent;
 }