Ejemplo n.º 1
0
        /// <summary>
        /// 加载模型
        /// </summary>
        /// <param name="charator"></param>
        /// <param name="charatorName"></param>
        private static Task InitCharatorModel(Charator charator, string charatorName)
        {
            Task async = new Task();

            ///第一种方法
            ///开启一个协同分离加载和回调
            Instance.StartCoroutine(TempC(
                                        () =>
            {
                Task <GameObject> task = new Task <GameObject>();
                Instance.StartCoroutine(LoadModel(charatorName, task));
                return(task);
            },

                                        (model) =>
            {
                ///将模型挂在model节点下
                model.transform.SetParent(charator.transform);
                ///从实例化数据
                Data4Charator d4c = GetData(charatorName);
                ///添加数据
                charator.Set(d4c);
                async.IsDone = true;
            }
                                        ));

            ///第二种方法


            return(async);
        }
Ejemplo n.º 2
0
        private IEnumerator InitData()
        {
            ///等待一秒,以免卡死
            yield return(new WaitForSeconds(1));

            ///加载本地角色
            TextAsset ch = Loader.Load <TextAsset>(CFG.DataPath + "Charator");
            XElement  xe = XElement.Parse(ch.text);

            var collection = xe.Elements("char");

            lock (datadic)
            {
                foreach (var item in collection)
                {
                    Data4Charator da = new Data4Charator(item);
                    datadic[da.Name] = da;
                }

                IsInit = true;
            }
        }