Example #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);
        }
Example #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);
        }
Example #3
0
        protected BTNode(BTRoot ai, BTNodeData config)
        {
            m_Config = config;
            m_Ai     = ai;

            m_LuaTable = m_LuaEnv.NewTable();
            LuaTable meta = m_LuaEnv.NewTable();

            meta.Set("__index", m_LuaEnv.Global);
            m_LuaTable.SetMetaTable(meta);
            meta.Dispose();

            m_LuaTable.Set("self", this);
            m_LuaEnv.DoString(config.script, "AINode", m_LuaTable);
            m_LuaTable.Get("detect", out m_DetectAction);
            if (m_DetectAction == null)
            {
                throw new System.Exception("must need function detect");
            }
            m_LuaTable.Get("enter", out m_EnterAction);
            m_LuaTable.Get("update", out m_UpdateAction);
            m_LuaTable.Get("trigger", out m_TriggerAction);
            m_LuaTable.Get("exit", out m_ExitAction);
        }
Example #4
0
 public BTControlNode(BTRoot ai, BTNodeData config) : base(ai, config)
 {
 }