コード例 #1
0
ファイル: EventSystem.cs プロジェクト: chanayy123/ET
        public async ETTask Publish <T>(T a) where T : struct
        {
            List <object> iEvents;

            if (!this.allEvents.TryGetValue(typeof(T), out iEvents))
            {
                return;
            }

            using (var list = ListComponent <ETTask> .Create())
            {
                foreach (object obj in iEvents)
                {
                    if (!(obj is AEvent <T> aEvent))
                    {
                        Log.Error($"event error: {obj.GetType().Name}");
                        continue;
                    }

                    list.List.Add(aEvent.Handle(a));
                }
                try
                {
                    await ETTaskHelper.WaitAll(list.List);
                }
                catch (Exception e)
                {
                    Log.Error(e);
                }
            }
        }
コード例 #2
0
        //场景加载结束:后续资源准备(预加载等)
        //注意:这里使用协程,子类别重写了,需要加载的资源添加到列表就可以了
        public static async ETTask OnPrepare(this SceneLoadComponent self, Action <float> progress_callback)
        {
            for (int i = 0; i < self.Total; i++)
            {
                switch (self.Types[i])
                {
                case SceneLoadComponent.LoadType.Image:
                    self.PreLoadTask.Add(self.StartPreloadImage(self.Paths[i]));
                    break;

                case SceneLoadComponent.LoadType.Material:
                    self.PreLoadTask.Add(self.StartPreloadMaterial(self.Paths[i]));
                    break;

                case SceneLoadComponent.LoadType.GameObject:
                    self.PreLoadTask.Add(self.StartPreloadGameObject(self.Paths[i], self.ObjCount[self.Paths[i]]));
                    break;

                default:
                    break;
                }
            }
            self.ProgressCallback = progress_callback;
            if (self.Total <= 0)
            {
                return;
            }
            await ETTaskHelper.WaitAll(self.PreLoadTask);
        }
コード例 #3
0
        //销毁指定窗口所有窗口
        public static async ETTask DestroyWindowExceptNames(this UIManagerComponent self, string[] type_names = null)
        {
            Dictionary <string, bool> dict_ui_names = new Dictionary <string, bool>();

            if (type_names != null)
            {
                for (int i = 0; i < type_names.Length; i++)
                {
                    dict_ui_names[type_names[i]] = true;
                }
            }
            var keys = self.windows.Keys.ToArray();

            using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
            {
                for (int i = self.windows.Count - 1; i >= 0; i--)
                {
                    if (!dict_ui_names.ContainsKey(keys[i]))
                    {
                        TaskScheduler.Add(self.DestroyWindow(keys[i]));
                    }
                }
                await ETTaskHelper.WaitAll(TaskScheduler);
            }
        }
コード例 #4
0
        public static async ETTask CloseWindowByLayer(this UIManagerComponent self, UILayerNames layer, params string[] except_ui_names)
        {
            Dictionary <string, bool> dict_ui_names = null;

            if (except_ui_names != null && except_ui_names.Length > 0)
            {
                dict_ui_names = new Dictionary <string, bool>();
                for (int i = 0; i < except_ui_names.Length; i++)
                {
                    dict_ui_names[except_ui_names[i]] = true;
                }
            }

            using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
            {
                foreach (var item in self.windows)
                {
                    if (item.Value.Layer == layer && (dict_ui_names == null || !dict_ui_names.ContainsKey(item.Key)))
                    {
                        TaskScheduler.Add(self.CloseWindow(item.Key));
                    }
                }
                await ETTaskHelper.WaitAll(TaskScheduler);
            }
        }
コード例 #5
0
        public static async ETTask Init(this TargetSelectComponent self)
        {
            string path       = "GameAssets/SkillPreview/Prefabs/TargetSelectManager.prefab";
            string targetPath = "GameAssets/SkillPreview/Prefabs/TargetIcon.prefab";

            using (ListComponent <ETTask <GameObject> > tasks = ListComponent <ETTask <GameObject> > .Create())
            {
                tasks.Add(GameObjectPoolComponent.Instance.GetGameObjectAsync(targetPath, (obj) =>
                {
                    self.CursorImage = obj.GetComponent <Image>();
                    self.CursorImage.transform.parent =
                        UIManagerComponent.Instance.GetLayer(UILayerNames.TipLayer).transform;
                    self.CursorImage.transform.localPosition        = Vector3.zero;
                    self.CursorImage.rectTransform.anchoredPosition = Input.mousePosition;
                }));
                tasks.Add(GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) =>
                {
                    self.RangeCircleObj = obj.transform.Find("RangeCircle").gameObject;
                    self.gameObject     = obj;
                }));
                await ETTaskHelper.WaitAll(tasks);

                self.waiter.SetResult(self.gameObject);
                self.waiter = null;
            }
        }
コード例 #6
0
ファイル: ConfigComponentSystem.cs プロジェクト: wqaetly/ET
        public static async ETTask LoadAsync(this ConfigComponent self)
        {
            self.AllConfig.Clear();
            HashSet <Type> types = Game.EventSystem.GetTypes(typeof(ConfigAttribute));

            Dictionary <string, byte[]> configBytes = new Dictionary <string, byte[]>();

            self.ConfigLoader.GetAllConfigBytes(configBytes);


            async ETTask Load(Type configType, Dictionary <string, byte[]> configBytes)
            {
                await ETTask.CompletedTask;

                self.LoadOneInThread(configType, configBytes);
            }

            MonoListComponent <ETTask> tasks = MonoListComponent <ETTask> .Create();

            foreach (var item in types)
            {
                tasks.List.Add(Load(item, configBytes));                //好像这么写还是同步加载
            }

            await ETTaskHelper.WaitAll(tasks.List);

            tasks.Dispose();
        }
コード例 #7
0
ファイル: RobotCaseSystem.cs プロジェクト: wikieden/ET
        // 创建机器人,生命周期是RobotCase
        public static async ETTask NewRobot(this RobotCase self, int count, List <Scene> scenes)
        {
            ETTask[] tasks = new ETTask[count];
            for (int i = 0; i < count; ++i)
            {
                tasks[i] = self.NewRobot(scenes);
            }

            await ETTaskHelper.WaitAll(tasks);
        }
コード例 #8
0
        public static async ETTask DestroyAllWindow(this UIManagerComponent self)
        {
            var keys = self.windows.Keys.ToArray();

            using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
            {
                for (int i = self.windows.Count - 1; i >= 0; i--)
                {
                    TaskScheduler.Add(self.DestroyWindow(self.windows[keys[i]].Name));
                }
                await ETTaskHelper.WaitAll(TaskScheduler);
            }
        }
コード例 #9
0
        /// <summary>
        /// 异步加载assetbundle, 加载ab包分两部分,第一部分是从硬盘加载,第二部分加载all assets。两者不能同时并发
        /// </summary>
        public static async ETTask LoadBundleAsync(this ResourcesComponent self, string assetBundleName)
        {
            assetBundleName = assetBundleName.BundleNameToLower();

            string[] dependencies = self.GetSortedDependencies(assetBundleName);
            //Log.Debug($"-----------dep load async start {assetBundleName} dep: {dependencies.ToList().ListToString()}");

            using (ListComponent <ABInfo> abInfos = ListComponent <ABInfo> .Create())
            {
                async ETTask LoadDependency(string dependency, List <ABInfo> abInfosList)
                {
                    CoroutineLock coroutineLock = null;

                    try
                    {
                        coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode());

                        ABInfo abInfo = await self.LoadOneBundleAsync(dependency);

                        if (abInfo == null || abInfo.RefCount > 1)
                        {
                            return;
                        }

                        abInfosList.Add(abInfo);
                    }
                    finally
                    {
                        coroutineLock?.Dispose();
                    }
                }

                // LoadFromFileAsync部分可以并发加载
                using (ListComponent <ETTask> tasks = ListComponent <ETTask> .Create())
                {
                    foreach (string dependency in dependencies)
                    {
                        tasks.Add(LoadDependency(dependency, abInfos));
                    }
                    await ETTaskHelper.WaitAll(tasks);

                    // ab包从硬盘加载完成,可以再并发加载all assets
                    tasks.Clear();
                    foreach (ABInfo abInfo in abInfos)
                    {
                        tasks.Add(self.LoadOneBundleAllAssets(abInfo));
                    }
                    await ETTaskHelper.WaitAll(tasks);
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// 销毁隐藏状态的窗口
 /// </summary>
 /// <param name="self"></param>
 public static async ETTask DestroyUnShowWindow(this UIManagerComponent self)
 {
     using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
     {
         foreach (var key in self.windows.Keys.ToList())
         {
             if (!self.windows[key].Active)
             {
                 TaskScheduler.Add(self.DestroyWindow(key));
             }
         }
         await ETTaskHelper.WaitAll(TaskScheduler);
     }
 }
コード例 #11
0
 //预加载一系列资源
 public static async ETTask LoadDependency(this GameObjectPoolComponent self, List <string> res)
 {
     if (res.Count <= 0)
     {
         return;
     }
     using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
     {
         for (int i = 0; i < res.Count; i++)
         {
             TaskScheduler.Add(self.PreLoadGameObjectAsync(res[i], 1));
         }
         await ETTaskHelper.WaitAll(TaskScheduler);
     }
 }
コード例 #12
0
        //销毁指定层级外层级所有窗口
        public static async ETTask DestroyWindowExceptLayer(this UIManagerComponent self, UILayerNames layer)
        {
            var keys = self.windows.Keys.ToArray();

            using (ListComponent <ETTask> TaskScheduler = ListComponent <ETTask> .Create())
            {
                for (int i = self.windows.Count - 1; i >= 0; i--)
                {
                    if (self.windows[keys[i]].Layer != layer)
                    {
                        TaskScheduler.Add(self.DestroyWindow(keys[i]));
                    }
                }
                await ETTaskHelper.WaitAll(TaskScheduler);
            }
        }
コード例 #13
0
ファイル: ResourcesComponent.cs プロジェクト: yingrenEdu/ET
 /// <summary>
 /// 异步加载assetbundle
 /// </summary>
 /// <param name="assetBundleName"></param>
 /// <param name="isScene"></param>
 /// <returns></returns>
 public async ETTask LoadBundleAsync(string assetBundleName, bool isScene = false)
 {
     assetBundleName = assetBundleName.BundleNameToLower();
     
     string[] dependencies = GetSortedDependencies(assetBundleName);
     //Log.Debug($"-----------dep load async start {assetBundleName} dep: {dependencies.ToList().ListToString()}");
     using var tasts = ListComponent<ETTask>.Create();
     async ETTask loadDependency(string dependency)
     {
         using (await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, dependency.GetHashCode()))
         {
             await this.LoadOneBundleAsync(dependency, isScene);
         }
     }
     foreach (string dependency in dependencies)
     {
         if (string.IsNullOrEmpty(dependency))
         {
             continue;
         }
         tasts.List.Add(loadDependency(dependency));
     }
     await ETTaskHelper.WaitAll(tasts.List);
 }