/// <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); }
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); }