コード例 #1
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);
        }
コード例 #2
0
ファイル: CoroutineHelper.cs プロジェクト: x00568/ET
        // 有了这个方法,就可以直接await Unity的AsyncOperation了
        public static async ETTask GetAwaiter(this AsyncOperation asyncOperation)
        {
            ETTask task = ETTask.Create(true);

            asyncOperation.completed += _ => { task.SetResult(); };
            await task;
        }
コード例 #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);
        }
コード例 #4
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();
        }
コード例 #5
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);
        }
コード例 #6
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;
            }
コード例 #7
0
ファイル: TimerComponent.cs プロジェクト: chanayy123/ET
        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);
        }
コード例 #8
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;
        }
コード例 #9
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);
        }
コード例 #10
0
        public static ETAsyncTaskMethodBuilder Create()
        {
            ETAsyncTaskMethodBuilder builder = new ETAsyncTaskMethodBuilder()
            {
                tcs = ETTask.Create(true)
            };

            return(builder);
        }
コード例 #11
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);
        }
コード例 #12
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);
        }
コード例 #13
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;
        }
コード例 #14
0
ファイル: UnityWebRequestAsync.cs プロジェクト: zwinter/ET
        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;
        }
コード例 #15
0
ファイル: FUI_BottomBtn.cs プロジェクト: wqaetly/ET
        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);
        }
コード例 #16
0
ファイル: XAssetUpdater.cs プロジェクト: wqaetly/ET
        public ETTask StartUpdate()
        {
            ETTask etTask = ETTask.Create(true);

            Updater.ResPreparedCompleted += () =>
            {
                etTask.SetResult();
            };
            Updater.StartUpdate();
            return(etTask);
        }
コード例 #17
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);
        }
コード例 #18
0
ファイル: DMoveComponentSystem.cs プロジェクト: chengxu-yh/ET
        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);
        }
コード例 #19
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);
        }
コード例 #20
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);
        }
コード例 #21
0
        public static async ETTask <CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
        {
            CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                coroutineLockQueueType.Add(key, self.AddChildWithId <CoroutineLockQueue>(++self.idGenerator, true));
                return(self.CreateCoroutineLock(coroutineLockType, key, time, 1));
            }
            ETTask <CoroutineLock> tcs = ETTask <CoroutineLock> .Create(true);

            queue.Add(tcs, time);
            return(await tcs);
        }
コード例 #22
0
ファイル: MoveComponentSystem.cs プロジェクト: zzjfengqing/ET
        public static async ETTask <bool> MoveToAsync(this MoveComponent self, List <Vector3> target, float speed, int turnTime = 100, ETCancellationToken cancellationToken = null)
        {
            self.Stop();

            foreach (Vector3 v in target)
            {
                self.Targets.Add(v);
            }

            self.IsTurnHorizontal = true;
            self.TurnTime         = turnTime;
            self.Speed            = speed;
            ETTask <bool> tcs = ETTask <bool> .Create();

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

            Game.EventSystem.Publish(new EventType.MoveStart()
            {
                Unit = self.GetParent <Unit>()
            }).Coroutine();

            self.StartMove();

            void CancelAction()
            {
                self.Stop();
            }

            bool moveRet;

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

            if (moveRet)
            {
                Game.EventSystem.Publish(new EventType.MoveStop()
                {
                    Unit = self.GetParent <Unit>()
                }).Coroutine();
            }
            return(moveRet);
        }
コード例 #23
0
        public override void Awake(DirectRectSelectComponent self)
        {
            self.waiter = ETTask <GameObject> .Create();

            string path = "GameAssets/SkillPreview/Prefabs/DirectRectSelectManager.prefab";

            GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) =>
            {
                self.gameObject = obj;
                self.DirectObj  = obj.transform.GetChild(0).gameObject;
                self.AreaObj    = self.DirectObj.transform.GetChild(0).gameObject;
                self.waiter.SetResult(obj);
                self.waiter = null;
            }).Coroutine();
            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }
コード例 #24
0
        public override void Awake(PointSelectComponent self)
        {
            self.waiter = ETTask <GameObject> .Create();

            string path = "GameAssets/SkillPreview/Prefabs/PointSelectManager.prefab";

            GameObjectPoolComponent.Instance.GetGameObjectAsync(path, (obj) =>
            {
                self.gameObject     = obj;
                self.RangeCircleObj = obj.transform.Find("RangeCircle").gameObject;
                self.SkillPointObj  = obj.transform.Find("SkillPointPreview").gameObject;
                self.waiter.SetResult(obj);
                self.waiter = null;
            }).Coroutine();
            self.HeroObj = UnitHelper.GetMyUnitFromZoneScene(self.ZoneScene()).GetComponent <GameObjectComponent>().GameObject;
        }
コード例 #25
0
        public static async ETTask <CoroutineLock> Wait(this CoroutineLockComponent self, int coroutineLockType, long key, int time = 60000)
        {
            CoroutineLockQueueType coroutineLockQueueType = self.list[coroutineLockType];

            CoroutineLockQueue queue = coroutineLockQueueType.GetChild <CoroutineLockQueue>(key);

            if (queue == null)
            {
                CoroutineLockQueue coroutineLockQueue = coroutineLockQueueType.AddChildWithId <CoroutineLockQueue>(key, true);
                return(self.CreateCoroutineLock(coroutineLockQueue, coroutineLockType, key, time, 1));
            }
            ETTask <CoroutineLock> tcs = ETTask <CoroutineLock> .Create(true);

            queue.Add(tcs, time);
            return(await tcs);
        }
コード例 #26
0
        /// <summary>
        /// 异步加载资源,path需要是全路径
        /// </summary>
        /// <param name="path"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public static ETTask <T> LoadAssetAsync <T>(string path) where T : UnityEngine.Object
        {
            ETTask <T> tcs = ETTask <T> .Create(true);

            AssetRequest assetRequest = Assets.LoadAssetAsync(path, typeof(T));

            //如果已经加载完成则直接返回结果(适用于编辑器模式下的异步写法和重复加载),下面的API如果有需求可按照此格式添加相关代码
            if (assetRequest.isDone)
            {
                tcs.SetResult((T)assetRequest.asset);
                return(tcs);
            }

            //+=委托链,否则会导致前面完成委托被覆盖
            assetRequest.completed += (arq) => { tcs.SetResult((T)arq.asset); };
            return(tcs);
        }
コード例 #27
0
        private static async ETTask SynAsync(GetRouterComponent self, long gateid, long channelid)
        {
            self.CancellationToken = new ETCancellationToken();
            self.Tcs = ETTask <string> .Create();

            //value是对应gate的scene.
            var  insid      = new InstanceIdStruct(gateid);
            uint localConn  = (uint)((ulong)channelid & uint.MaxValue);
            var  routerlist = await GetRouterListFake();

            if (routerlist == null)
            {
                self.Tcs?.SetResult("");
                self.Tcs = null;
                Log.Error("从cdn获取路由失败");
                return;
            }
            Log.Debug("路由数量:" + routerlist.Length.ToString());
            Log.Debug("gateid:" + insid.Value.ToString());
            byte[] buffer = self.cache;
            buffer.WriteTo(0, KcpProtocalType.RouterSYN);
            buffer.WriteTo(1, localConn);
            buffer.WriteTo(5, insid.Value);
            for (int i = 0; i < self.ChangeTimes; i++)
            {
                string router = routerlist.RandomArray();
                Log.Debug("router:" + router);
                self.socket.SendTo(buffer, 0, 9, SocketFlags.None, NetworkHelper.ToIPEndPoint(router));
                var returnbool = await TimerComponent.Instance.WaitAsync(300, self.CancellationToken);

                if (returnbool == false)
                {
                    Log.Debug("提前取消了.可能连接上了");
                    return;
                }
            }
            await TimerComponent.Instance.WaitAsync(1300, self.CancellationToken);

            self.Tcs?.SetResult("");
            self.Tcs = null;
            Log.Debug("三次失败.获取路由失败");
        }
コード例 #28
0
        public static ETTask <bool> DownloadAll(this DownloadComponent self)
        {
            if (self.tcs == null)
            {
                self.tcs = ETTask <bool> .Create(true);

                self.IsDownloading = true;
                ThreadPool.QueueUserWorkItem((_) =>
                {
                    while (true)
                    {
                        if (!self.IsDownloading)
                        {
                            return;
                        }
                        HTTPManager.OnUpdate();
                        self.UpdateThread();
                        Thread.Sleep(1);
                    }
                });
            }
            return(self.tcs);
        }
コード例 #29
0
 public ResultCallback()
 {
     this.tcs = ETTask <K> .Create(true);
 }
コード例 #30
0
ファイル: Session.cs プロジェクト: suziye123/ET
 public RpcInfo(IRequest request)
 {
     this.Request = request;
     this.Tcs     = ETTask <IResponse> .Create(true);
 }