Esempio n. 1
0
        /// <summary>
        /// 通过AINodeConfigData根节点生成AINode
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="owner"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public static BTNode Create(BTNodeData data, BTRoot ai)
        {
            BTNode    node = null;
            TextAsset txt  = Resources.Load <TextAsset>(data.scriptName);

            data.script = txt.text;
            if (data.listAINodeConfigData.Count > 0)
            {
                node = new BTControlNode(ai, data);
                foreach (var c in data.listAINodeConfigData)
                {
                    var child = Create(c, ai);
                    node.Add(child);
                }
            }
            else
            {
                node = new BTActionNode(ai, data);
            }
            return(node);
        }
Esempio n. 2
0
        public static BTNode Create(byte[] bytes, BTRoot ai)
        {
            BTNode     node   = null;
            ByteBuffer buffer = new ByteBuffer(bytes);
            BTNodeData config = new BTNodeData();

            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 BTControlNode(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 BTActionNode(ai, config);
            }
            return(node);
        }