Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }