Exemple #1
0
        // 场景切换协程
        public static async ETTask SceneChangeTo(Scene zoneScene, string sceneName, long sceneInstanceId)
        {
            // zoneScene.RemoveComponent<AIComponent>();
            zoneScene.AddComponent <KeyCodeComponent>();
            CurrentScenesComponent currentScenesComponent = zoneScene.GetComponent <CurrentScenesComponent>();

            currentScenesComponent.Scene?.Dispose(); // 删除之前的CurrentScene,创建新的
            Scene currentScene = SceneFactory.CreateCurrentScene(sceneInstanceId, zoneScene.Zone, sceneName, currentScenesComponent);

            currentScene.AddComponent <UnitComponent>();
            currentScene.AddComponent <AOISceneComponent, int>(6);
            // 可以订阅这个事件中创建Loading界面
            using (ListComponent <ETTask> tasks = ListComponent <ETTask> .Create())
            {
                tasks.Add(WaitChangeScene(zoneScene, sceneName)); //等收到消息并且地图创建完成
                tasks.Add(WaitCreateMyUnit(zoneScene));           // 等待CreateMyUnit的消息
                await ETTaskHelper.WaitAll(tasks);
            }
            M2C_CreateMyUnit m2CCreateMyUnit = waitCreateMyUnit.Message;

            UnitFactory.Create(currentScene, m2CCreateMyUnit.Unit);
            // zoneScene.AddComponent<AIComponent,int>(1);

            await Game.EventSystem.PublishAsync(new EventType.SceneChangeFinish()
            {
                ZoneScene = zoneScene, CurrentScene = currentScene
            });

            // 通知等待场景切换的协程
            zoneScene.GetComponent <ObjectWait>().Notify(new WaitType.Wait_SceneChangeFinish());
        }
Exemple #2
0
        // 创建机器人,生命周期是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);
        }
Exemple #3
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);
                }
            }
        }