Exemplo n.º 1
0
        //把npc加载到场景中
        public GameObject InitNPC(NPCInfo info, bool checkTask = true)
        {
            MTBNPCData npcdata = MTBNPCDataManager.Instance.getData(info.NPCId) as MTBNPCData;

            if (npcdata == null)
            {
                throw new Exception("当前npcId有误或者没有配置对应资源");
            }
            if (!checkRefreshNpc(info, checkTask))
            {
                return(null);
            }
            string     resPath = RESPATH + npcdata.resName;
            GameObject prefab  = Resources.Load(resPath) as GameObject;
            GameObject npc     = GameObject.Instantiate(prefab);

            npc.name = "NPC_" + info.NPCId;
            npc.transform.position = info.position;
            if (npc.GetComponent <AutoMoveController>() == null)
            {
                npc.AddComponent <AutoMoveController>();
            }
            addObj(npc, info);
            EventManager.SendEvent(EventMacro.NPC_INITED, info);
            return(npc);
        }
Exemplo n.º 2
0
        public void loadData()
        {
            XmlDocument npcData = new XmlDocument();

            npcData.LoadXml(Resources.Load(NPCDATA_PATH).ToString());
            XmlNodeList nodeList = npcData.GetElementsByTagName("NPCData")[0].ChildNodes;

            foreach (XmlElement xe in nodeList)
            {
                MTBNPCData data = new MTBNPCData();
                data.decode(xe);
                NPCDATALIST.Add(Convert.ToInt32(xe.GetAttribute("id")), data);
            }
        }