Exemplo n.º 1
0
        public static ETTask <Texture2D> ScreenShoot()
        {
            var task = ETTask <Texture2D> .Create();

            YuoAwait_Mono.Instance.StartCoroutine(IScreenShoot(task));
            return(task);
        }
Exemplo n.º 2
0
        //检查catalog的更新
        public ETTask <string> CheckForCatalogUpdates()
        {
            ETTask <string> result = ETTask <string> .Create();

            var handle = Addressables.CheckForCatalogUpdates(false);

            handle.Completed += (res) =>
            {
                if (handle.Status == AsyncOperationStatus.Succeeded)
                {
                    if (handle.Result != null && handle.Result.Count > 0)
                    {
                        result.SetResult(handle.Result[0]);
                    }
                    else
                    {
                        Debug.LogError("handle.Result == null || handle.Result.Count == 0, Check catalog_1.hash is exist");
                        result.SetResult(null);
                    }
                }
                else
                {
                    Debug.LogError("handle.Status == AsyncOperationStatus.Succeeded");
                    result.SetResult(null);
                }
                Addressables.Release(handle);
            };
            return(result);
        }
        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.º 4
0
        public ETTask <T> LoadAssetAsync <T>(string addressPath) where T : UnityEngine.Object
        {
            ETTask <T> tTask = ETTask <T> .Create();

            var label = GetAssetSkinLabel(addressPath);

            processingAddressablesAsyncLoaderCount += 1;
            if (!string.IsNullOrEmpty(label))
            {
                var res = Addressables.LoadAssetsAsync <T>(new List <string> {
                    addressPath, label
                }, null, Addressables.MergeMode.Intersection);
                res.Completed += (loader) =>
                {
                    var obj = OnAddressablesAsyncLoaderDone(loader);
                    tTask.SetResult(obj);
                };
            }
            else
            {
                var res = Addressables.LoadAssetAsync <T>(addressPath);
                res.Completed += (loader) =>
                {
                    var obj = OnAddressablesAsyncLoaderDone(loader);
                    tTask.SetResult(obj);
                };
            }
            return(tTask);
        }
Exemplo n.º 5
0
        public override ETTask <GameObject> Load(string path, Transform parent)
        {
            var tcs = ETTask <GameObject> .Create(true);

            tcs.SetResult(GameObject.Instantiate(Resources.Load <GameObject>(path), parent));
            return(tcs);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     读取图片
        /// </summary>
        public static ETTask <Texture2D> LoadTexture(string path)
        {
            var task = ETTask <Texture2D> .Create(true);

            YuoAwait_Mono.Instance.StartCoroutine(LoadTexture(task, path));
            return(task);
        }
Exemplo n.º 7
0
        private static ETTask <T> ToAwaiter <T>(T enumerator) where T : IEnumerator
        {
            var task = ETTask <T> .Create();

            YuoAwait_Mono.Instance.StartCoroutine(ToAwaiter(enumerator, task));
            return(task);
        }
Exemplo n.º 8
0
        public static ETTask <T> GetAwaiter <T>(this ResourceRequest request) where T : Object
        {
            var task = ETTask <T> .Create(true);

            YuoAwait_Mono.Instance.StartCoroutine(LoadAsset(request, task));
            return(task);
        }
Exemplo n.º 9
0
        public static async ETTask GetAwaiter(this AsyncOperation asyncOperation)
        {
            var task = ETTask.Create(true);

            asyncOperation.completed += _ => { task.SetResult(); };
            await task;
        }
Exemplo n.º 10
0
            public ETTask WaitDown()
            {
                var tcs = ETTask.Create();

                InputTcs.Add(tcs);
                return(tcs);
            }
Exemplo n.º 11
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;
 }
Exemplo n.º 12
0
        private static IEnumerator LoadAsset <T>(ResourceRequest request, ETTask <T> tcs) where T : Object
        {
            yield return(request);

            var go = request.asset as T;

            tcs.SetResult(go);
        }
Exemplo n.º 13
0
        private static IEnumerator ToAwaiter <T>(T enumerator, ETTask <T> task) where T : IEnumerator
        {
            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }

            task.SetResult(enumerator);
        }
Exemplo n.º 14
0
        //下载更新资源
        public ETTask <Dictionary <string, string> > CheckUpdateContent(List <string> keys, int iMergeMode)
        {
            Addressables.MergeMode mergeMode             = (Addressables.MergeMode)iMergeMode;
            ETTask <Dictionary <string, string> > result = ETTask <Dictionary <string, string> > .Create();

            var handle = Addressables.LoadResourceLocationsAsync(keys, mergeMode);

            handle.Completed += (res) =>
            {
                if (handle.Status == AsyncOperationStatus.Succeeded)
                {
                    if (handle.Result != null && handle.Result.Count > 0)
                    {
                        var downlocations = handle.Result;

                        string bundleName3;
                        string path;
                        AssetBundleRequestOptions data;
                        var needLoadInfo = new Dictionary <string, string>();
                        if (downlocations != null && downlocations.Count > 0)
                        {
                            foreach (var item in downlocations)
                            {
                                if (item.HasDependencies)
                                {
                                    foreach (var dep in item.Dependencies)
                                    {
                                        bundleName3 = Path.GetFileName(dep.InternalId);
                                        if (dep.Data != null)
                                        {
                                            data = dep.Data as AssetBundleRequestOptions;
                                            path = AssetBundleMgr.GetInstance().TransformAssetBundleLocation(dep.InternalId, bundleName3, data.Hash);
                                            if (UnityEngine.ResourceManagement.Util.ResourceManagerConfig.ShouldPathUseWebRequest(path))
                                            {
                                                needLoadInfo[bundleName3] = data.Hash;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        result.SetResult(needLoadInfo);
                    }
                    else
                    {
                        result.SetResult(null);
                    }
                }
                else
                {
                    result.SetResult(null);
                }
                Addressables.Release(handle);
            };
            return(result);
        }
Exemplo n.º 15
0
        private static ETTask <ActorMessageInfo> GetAsync(this MailBoxComponent self)
        {
            if (self.Queue.Count > 0)
            {
                return(ETTask.FromResult(self.Queue.Dequeue()));
            }

            self.Tcs = new ETTaskCompletionSource <ActorMessageInfo>();
            return(self.Tcs.Task);
        }
Exemplo n.º 16
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.º 17
0
        public override ETTask <GameObject> Load(string path, Transform parent)
        {
            ETTask <GameObject> tcs = ETTask <GameObject> .Create();

            Addressables.InstantiateAsync(path, parent).Completed += go =>
            {
                go.Result.gameObject.Hide();
                tcs.SetResult(go.Result);
            };
            return(tcs);
        }
Exemplo n.º 18
0
        private static ETTask <ActorTask> GetAsync(this ActorLocationSender self)
        {
            if (self.WaitingTasks.Count > 0)
            {
                ActorTask task = self.WaitingTasks.Peek();
                return(ETTask.FromResult(task));
            }

            self.Tcs = new ETTaskCompletionSource <ActorTask>();
            return(self.Tcs.Task);
        }
Exemplo n.º 19
0
        private static ETTask <bool> WaitLock(this LockComponent self)
        {
            if (self.status == LockStatus.Locked)
            {
                return(ETTask.FromResult(true));
            }

            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();

            self.queue.Enqueue(tcs);
            return(tcs.Task);
        }
        public ETTask <KeyValuePair <RedisChannel, RedisValue> > Get(RedisEventSolverComponent self)
        {
            if (self.receivedQueue.TryDequeue(out var kp))
            {
                return(ETTask.FromResult(kp));
            }

            ETTaskCompletionSource <KeyValuePair <RedisChannel, RedisValue> > t = new ETTaskCompletionSource <KeyValuePair <RedisChannel, RedisValue> >();

            self.tcs = t;
            return(t.Task);
        }
Exemplo n.º 21
0
        //下载catalogs
        public ETTask <bool> UpdateCatalogs(string catalog)
        {
            ETTask <bool> result = ETTask <bool> .Create();

            var handle = Addressables.UpdateCatalogs(new string[] { catalog }, false);

            handle.Completed += (res) =>
            {
                Addressables.Release(handle);
                result.SetResult(handle.Status == AsyncOperationStatus.Succeeded);
            };
            return(result);
        }
Exemplo n.º 22
0
        public static ETTask Lock(this MasterComponent self, IPEndPoint address)
        {
            if (self.lockedAddress == null)
            {
                self.lockedAddress = address;
                return(ETTask.FromResult(true));
            }

            ETTaskCompletionSource tcs = new ETTaskCompletionSource();
            LockInfo lockInfo          = new LockInfo(address, tcs);

            self.queue.Enqueue(lockInfo);
            return(tcs.Task);
        }
Exemplo n.º 23
0
        /// <summary>
        ///     截屏
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        private static IEnumerator IScreenShoot(ETTask <Texture2D> task)
        {
            //图片大小
            var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true);

            //截取下一帧
            yield return(new WaitForEndOfFrame());

            tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, true); //读像素
            tex.Apply();
            yield return(tex);

            task.SetResult(tex);
        }
Exemplo n.º 24
0
        public ETTask LoadSceneAsync(string addressPath, bool isAdditive)
        {
            ETTask tTask = ETTask.Create();

            Addressables.LoadSceneAsync(addressPath, isAdditive ? UnityEngine.SceneManagement.LoadSceneMode.Additive : UnityEngine.SceneManagement.LoadSceneMode.Single).Completed +=
                (loader) =>
            {
                OnAddressablesAsyncLoaderDone(loader);
                tTask.SetResult();
            };
            processingAddressablesAsyncLoaderCount += 1;

            return(tTask);
        }
Exemplo n.º 25
0
    public async ETTask <Color> GetColorAsync()
    {
        Color tempColor = colorRing.Color;

        rect.anchoredPosition = Input.mousePosition;
        Show();
        var tcs = ETTask <Color> .Create();

        Confirm.onClick.RemoveAllListeners();
        Confirm.onClick.AddListener(Hide);
        Cancell.onClick.RemoveAllListeners();
        Cancell.onClick.AddListener(Hide);
        Confirm.onClick.AddListener(() => tcs.SetResult(colorRing.Color));
        Cancell.onClick.AddListener(() => tcs.SetResult(tempColor));
        return(await tcs);
    }
Exemplo n.º 26
0
        private static IEnumerator LoadTexture(ETTask <Texture2D> task, string path)
        {
            var webRequest = UnityWebRequestTexture.GetTexture(path);

            yield return(webRequest.SendWebRequest());

            if (webRequest.result != UnityWebRequest.Result.Success)
            {
                path.Log();
                Debug.LogError("LoadTexture Error:" + webRequest.downloadHandler.error);
                task.SetException(new Exception("LoadTexture Error"));
            }
            else
            {
                task.SetResult(DownloadHandlerTexture.GetContent(webRequest));
            }
        }
Exemplo n.º 27
0
        //根据key来获取下载大小
        public ETTask <long> GetDownloadSizeAsync(string key)
        {
            ETTask <long> result = ETTask <long> .Create();

            var handle = Addressables.GetDownloadSizeAsync(key);

            handle.Completed += (res) =>
            {
                Addressables.Release(handle);
                if (handle.Status == AsyncOperationStatus.Failed)
                {
                    result.SetResult(-1);
                }
                else
                {
                    result.SetResult(handle.Result);
                }
            };
            return(result);
        }