Exemplo n.º 1
0
        private void Run(TimerAction timerAction)
        {
            switch (timerAction.TimerClass)
            {
            case TimerClass.OnceTimer:
            {
                ETTask <bool> tcs = timerAction.Object as ETTask <bool>;
                this.Remove(timerAction.Id);
                tcs.SetResult(true);
                break;
            }

            case TimerClass.RepeatedTimer:
            {
                int  type     = timerAction.Type;
                long tillTime = TimeHelper.ServerNow() + timerAction.Time;
                this.AddTimer(tillTime, timerAction);

                ITimer timer = this.timerActions[type];
                if (timer == null)
                {
                    Log.Error($"not found timer action: {type}");
                    return;
                }
                timer.Handle(timerAction.Object);
                break;
            }
            }
        }
Exemplo n.º 2
0
        public async ETTask <bool> WaitTillAsync(long tillTime, ETCancellationToken cancellationToken = null)
        {
            if (TimeHelper.ServerNow() >= tillTime)
            {
                return(true);
            }

            ETTask <bool> tcs = ETTask <bool> .Create(true);

            TimerAction timer = this.AddChild <TimerAction, TimerClass, long, object>(TimerClass.OnceWaitTimer, 0, tcs, true);

            this.AddTimer(tillTime, timer);
            long timerId = timer.Id;

            void CancelAction()
            {
                if (this.Remove(timerId))
                {
                    tcs.SetResult(false);
                }
            }

            bool ret;

            try
            {
                cancellationToken?.Add(CancelAction);
                ret = await tcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }
            return(ret);
        }
Exemplo n.º 3
0
        async static ETTask <int> ShowMsgBoxView(this UIUpdateView self, string content, string confirmBtnText, string cancelBtnText)
        {
            ETTask <int> tcs = ETTask <int> .Create();

            Action confirmBtnFunc = () =>
            {
                tcs.SetResult(self.BTN_CONFIRM);
            };

            Action cancelBtnFunc = () =>
            {
                tcs.SetResult(self.BTN_CANCEL);
            };

            I18NComponent.Instance.I18NTryGetText(content, out self.para.Content);
            I18NComponent.Instance.I18NTryGetText(confirmBtnText, out self.para.ConfirmText);
            I18NComponent.Instance.I18NTryGetText(cancelBtnText, out self.para.CancelText);
            self.para.ConfirmCallback = confirmBtnFunc;
            self.para.CancelCallback  = cancelBtnFunc;
            await UIManagerComponent.Instance.OpenWindow <UIMsgBoxWin, UIMsgBoxWin.MsgBoxPara>(UIMsgBoxWin.PrefabPath,
                                                                                               self.para, UILayerNames.TipLayer);

            var result = await tcs;
            await UIManagerComponent.Instance.CloseWindow <UIMsgBoxWin>();

            return(result);
        }
Exemplo n.º 4
0
        private void Run(TimerAction timerAction)
        {
            switch (timerAction.TimerClass)
            {
            case TimerClass.OnceWaitTimer:
            {
                ETTask <bool> tcs = timerAction.Callback as ETTask <bool>;
                this.Remove(timerAction.Id);
                tcs.SetResult(true);
                break;
            }

            case TimerClass.OnceTimer:
            {
                Action action = timerAction.Callback as Action;
                this.Remove(timerAction.Id);
                action?.Invoke();
                break;
            }

            case TimerClass.RepeatedTimer:
            {
                Action action   = timerAction.Callback as Action;
                long   tillTime = TimeHelper.ServerNow() + timerAction.Time;
                this.AddTimer(tillTime, timerAction);
                action?.Invoke();
                break;
            }
            }
        }
Exemplo n.º 5
0
        public static async ETTask <IActorResponse> Call(
            this ActorMessageSenderComponent self,
            long actorId,
            int rpcId,
            MemoryStream memoryStream,
            bool needException = true
            )
        {
            if (actorId == 0)
            {
                throw new Exception($"actor id is 0: {memoryStream.ToActorMessage()}");
            }

            var tcs = ETTask <IActorResponse> .Create(true);

            self.requestCallback.Add(rpcId, new ActorMessageSender(actorId, memoryStream, tcs, needException));

            self.Send(actorId, memoryStream);

            long           beginTime = TimeHelper.ServerFrameTime();
            IActorResponse response  = await tcs;
            long           endTime   = TimeHelper.ServerFrameTime();

            long costTime = endTime - beginTime;

            if (costTime > 200)
            {
                Log.Warning("actor rpc time > 200: {0} {1}", costTime, memoryStream.ToActorMessage());
            }

            return(response);
        }
Exemplo n.º 6
0
 public void Add(ETTask <CoroutineLock> tcs, int time)
 {
     this.queue.Enqueue(new CoroutineLockInfo()
     {
         Tcs = tcs, Time = time
     });
 }
Exemplo n.º 7
0
 public static void Add(this CoroutineLockQueue self, ETTask <CoroutineLock> tcs, int time)
 {
     self.queue.Enqueue(new CoroutineLockInfo()
     {
         Tcs = tcs, Time = time
     });
 }
Exemplo n.º 8
0
        // 有了这个方法,就可以直接await Unity的AsyncOperation了
        public static async ETTask GetAwaiter(this AsyncOperation asyncOperation)
        {
            ETTask task = ETTask.Create(true);

            asyncOperation.completed += _ => { task.SetResult(); };
            await task;
        }
Exemplo n.º 9
0
            public async ETTask WaitAsync()
            {
                --this.count;
                if (this.count < 0)
                {
                    return;
                }

                if (this.count == 0)
                {
                    List <ETTask> t = this.tcss;
                    this.tcss = null;
                    foreach (ETTask ttcs in t)
                    {
                        ttcs.SetResult();
                    }

                    return;
                }

                ETTask tcs = ETTask.Create(true);

                tcss.Add(tcs);
                await tcs;
            }
Exemplo n.º 10
0
        private static void Run(this TimerComponent self, TimerAction timerAction)
        {
            switch (timerAction.TimerClass)
            {
            case TimerClass.OnceTimer:
            {
                int type = timerAction.Type;
                Game.EventSystem.Callback(type, timerAction.Object);
                break;
            }

            case TimerClass.OnceWaitTimer:
            {
                ETTask <bool> tcs = timerAction.Object as ETTask <bool>;
                self.Remove(timerAction.Id);
                tcs.SetResult(true);
                break;
            }

            case TimerClass.RepeatedTimer:
            {
                int  type     = timerAction.Type;
                long tillTime = TimeHelper.ServerNow() + timerAction.Time;
                self.AddTimer(tillTime, timerAction);
                Game.EventSystem.Callback(type, timerAction.Object);
                break;
            }
            }
        }
Exemplo n.º 11
0
            static CanceledETTaskCache()
            {
                ETTaskCompletionSource tcs = new ETTaskCompletionSource();

                tcs.TrySetCanceled();
                Task = tcs.Task;
            }
Exemplo n.º 12
0
            public void SetResult(K k)
            {
                var t = tcs;

                this.tcs = null;
                t.SetResult(k);
            }
Exemplo n.º 13
0
        public static async ETTask <bool> WaitTillAsync(this TimerComponent self, long tillTime, ETCancellationToken cancellationToken = null)
        {
            if (self.timeNow >= tillTime)
            {
                return(true);
            }

            ETTask <bool> tcs = ETTask <bool> .Create(true);

            TimerAction timer = self.AddChild <TimerAction, TimerClass, long, int, object>(TimerClass.OnceWaitTimer, tillTime - self.timeNow, 0, tcs, true);

            self.AddTimer(tillTime, timer);
            long timerId = timer.Id;

            void CancelAction()
            {
                if (self.Remove(timerId))
                {
                    tcs.SetResult(false);
                }
            }

            bool ret;

            try
            {
                cancellationToken?.Add(CancelAction);
                ret = await tcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }
            return(ret);
        }
Exemplo n.º 14
0
        public override void Awake(GalGameEngineComponent self)
        {
            GalGameEngineComponent.Instance = self;
            self.CancelToken           = new ETCancellationToken();
            self.Speed                 = GalGameEngineComponent.NormalSpeed;
            self.StageRoleMap          = new Dictionary <string, string>();
            self.RoleExpressionMap     = new Dictionary <string, string>();
            self.RoleExpressionPathMap = new Dictionary <string, Dictionary <string, string> >();
            self.WaitInput             = ETTask <KeyCode> .Create();

            self.ReviewItems = new List <GalGameEngineComponent.ReviewItem>();
            for (int i = 0; i < RoleExpressionConfigCategory.Instance.GetAllList().Count; i++)
            {
                var item = RoleExpressionConfigCategory.Instance.GetAllList()[i];
                if (!self.RoleExpressionPathMap.ContainsKey(item.NameKey))
                {
                    self.RoleExpressionPathMap.Add(item.NameKey, new Dictionary <string, string>());
                }
                self.RoleExpressionPathMap[item.NameKey].Add(item.Expression, item.Path);
            }
            self.StagePosMap = new Dictionary <string, Vector3>();
            for (int i = 0; i < StagePosConfigCategory.Instance.GetAllList().Count; i++)
            {
                var item = StagePosConfigCategory.Instance.GetAllList()[i];
                self.StagePosMap.Add(item.NameKey, new Vector3(item.Position[0], item.Position[1], 0));
            }
            self.FSM = self.AddComponent <FSMComponent>();
            self.FSM.AddState <GalGameEngineReadyState>();
            self.FSM.AddState <GalGameEngineFastForwardState>();
            self.FSM.AddState <GalGameEngineRunningState>();
            self.FSM.AddState <GalGameEngineSuspendedState>();
            self.FSM.ChangeState <GalGameEngineReadyState>().Coroutine();
        }
Exemplo n.º 15
0
        public static async ETTask ChangeSceneAsync(this SceneChangeComponent self, string sceneName)
        {
            self.tcs = ETTask.Create(true);
            // 加载map
            self.loadMapOperation = SceneManager.LoadSceneAsync(sceneName);

            await self.tcs;
        }
Exemplo n.º 16
0
 public ActorMessageSender(long actorId, MemoryStream memoryStream, ETTask <IActorResponse> tcs, bool needException)
 {
     this.ActorId       = actorId;
     this.MemoryStream  = memoryStream;
     this.CreateTime    = TimeHelper.ServerNow();
     this.Tcs           = tcs;
     this.NeedException = needException;
 }
        public static ETAsyncTaskMethodBuilder Create()
        {
            ETAsyncTaskMethodBuilder builder = new ETAsyncTaskMethodBuilder()
            {
                tcs = ETTask.Create(true)
            };

            return(builder);
        }
Exemplo n.º 18
0
        public static async ETTask <UnityEngine.Object[]> UnityLoadAssetAsync(AssetBundle assetBundle)
        {
            var tcs = ETTask <UnityEngine.Object[]> .Create(true);

            AssetBundleRequest request = assetBundle.LoadAllAssetsAsync();

            request.completed += operation => { tcs.SetResult(request.allAssets); };
            return(await tcs);
        }
Exemplo n.º 19
0
        public static async ETTask <GObject> CreateGObjectAsync(Scene scene, string packageName, string resName)
        {
            await scene.GetComponent <FGUIPackageComponent>().AddPackageAsync(packageName);

            ETTask <GObject> tcs = ETTask <GObject> .Create(true);

            UIPackage.CreateObjectAsync(packageName, resName, (go) => { tcs.SetResult(go); });
            return(await tcs);
        }
Exemplo n.º 20
0
        public static async ETTask <AssetBundle> UnityLoadBundleAsync(string path)
        {
            var tcs = ETTask <AssetBundle> .Create(true);

            AssetBundleCreateRequest request = AssetBundle.LoadFromFileAsync(path);

            request.completed += operation => { tcs.SetResult(request.assetBundle); };
            return(await tcs);
        }
Exemplo n.º 21
0
            public void SetResult()
            {
                var t = tcs;

                this.tcs = null;
                t.SetResult(new K()
                {
                    Error = WaitTypeError.Destroy
                });
            }
Exemplo n.º 22
0
        public override void Awake(TargetSelectComponent self)
        {
            //CursorImage = GetComponent<Image>();
            self.CursorColor = Color.white;
            self.waiter      = ETTask <GameObject> .Create();

            self.Init().Coroutine();

            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }
Exemplo n.º 23
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);
        }
Exemplo n.º 24
0
        public ETTask StartUpdate()
        {
            ETTask etTask = ETTask.Create(true);

            Updater.ResPreparedCompleted += () =>
            {
                etTask.SetResult();
            };
            Updater.StartUpdate();
            return(etTask);
        }
Exemplo n.º 25
0
        public async ETTask DownloadAsync(string url)
        {
            this.tcs = ETTask.Create(true);

            url          = url.Replace(" ", "%20");
            this.Request = UnityWebRequest.Get(url);
            this.Request.certificateHandler = certificateHandler;
            this.Request.SendWebRequest();

            await this.tcs;
        }
Exemplo n.º 26
0
        public static ETTask <FUI_BottomBtn> CreateInstanceAsync(Entity domain)
        {
            ETTask <FUI_BottomBtn> tcs = ETTask <FUI_BottomBtn> .Create(true);

            CreateGObjectAsync((go) =>
            {
                tcs.SetResult(Entity.Create <FUI_BottomBtn, GObject>(domain, go));
            });

            return(tcs);
        }
Exemplo n.º 27
0
        public static async ETTask <bool> MoveToAsync(this DMoveComponent self, Vector3 target, float speedValue, ETCancellationToken cancellationToken = null)
        {
            await ETTask.CompletedTask;

            DUnit unit = self.GetParent <DUnit>();

            if ((target - self.Target).magnitude < 0.1f)
            {
                return(true);
            }

            self.Target = target;


            self.StartPos  = unit.Position;
            self.StartTime = TimeHelper.ClientNow();
            float distance = (self.Target - self.StartPos).magnitude;

            if (Math.Abs(distance) < 0.1f)
            {
                return(true);
            }

            self.needTime = (long)(distance / speedValue * 1000);

            ETTask <bool> moveTcs = ETTask <bool> .Create();

            self.Callback = (ret) => { moveTcs.SetResult(ret); };

            void CancelAction()
            {
                if (self.Callback != null)
                {
                    Action <bool> callback = self.Callback;
                    self.Callback = null;
                    callback.Invoke(false);
                }
            }

            bool moveRet;

            try
            {
                cancellationToken?.Add(CancelAction);
                moveRet = await moveTcs;
            }
            finally
            {
                cancellationToken?.Remove(CancelAction);
            }

            return(moveRet);
        }
Exemplo n.º 28
0
        //预加载prefab
        private static ETTask StartPreloadGameObject(this SceneLoadComponent self, string path, int count)
        {
            ETTask task = ETTask.Create();

            GameObjectPoolComponent.Instance.PreLoadGameObjectAsync(path, count, () =>
            {
                self.FinishCount++;
                self.ProgressCallback?.Invoke((float)self.FinishCount / self.Total);
                task.SetResult();
            }).Coroutine();
            return(task);
        }
Exemplo n.º 29
0
        //预加载图集
        private static ETTask StartPreloadImage(this SceneLoadComponent self, string path)
        {
            ETTask task = ETTask.Create();

            ImageLoaderComponent.Instance.LoadImageAsync(path, (go) =>
            {
                self.FinishCount++;
                self.ProgressCallback?.Invoke((float)self.FinishCount / self.Total);
                task.SetResult();
            }).Coroutine();
            return(task);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 加载场景,path需要是全路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static ETTask <SceneAssetRequest> LoadSceneAsync(string path)
        {
            ETTask <SceneAssetRequest> tcs = ETTask <SceneAssetRequest> .Create(true);

            SceneAssetRequest sceneAssetRequest = Assets.LoadSceneAsync(path, false);

            sceneAssetRequest.completed += (arq) =>
            {
                tcs.SetResult(sceneAssetRequest);
            };
            return(tcs);
        }