예제 #1
0
        public static async ETTask <RobotCase> New(this RobotCaseComponent self)
        {
            await ETTask.CompletedTask;
            RobotCase robotCase = EntityFactory.CreateWithParent <RobotCase>(self);

            return(robotCase);
        }
예제 #2
0
        public async ETTask <bool> WaitAsync(long time, ETCancellationToken cancellationToken)
        {
            long tillTime = TimeHelper.Now() + time;

            if (TimeHelper.Now() > tillTime)
            {
                return(true);
            }

            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            long instanceId = timer.InstanceId;

            cancellationToken.Register(() =>
            {
                if (instanceId != timer.InstanceId)
                {
                    return;
                }

                timer.Run(false);

                this.Remove(timer.Id);
            });
            return(await tcs.Task);
        }
예제 #3
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 = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, 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);
        }
예제 #4
0
        public void LoadOneBundle(string assetBundleName)
        {
            //Log.Debug($"---------------load one bundle {assetBundleName}");
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                return;
            }

            if (!Define.IsAsync)
            {
                string[] realPath = null;
#if UNITY_EDITOR
                realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    AddResource(assetBundleName, assetName, resource);
                }

                abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                this.bundles[assetBundleName] = abInfo;
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (File.Exists(p))
            {
                assetBundle = AssetBundle.LoadFromFile(p);
            }
            else
            {
                p           = Path.Combine(PathHelper.AppResPath, assetBundleName);
                assetBundle = AssetBundle.LoadFromFile(p);
            }

            if (assetBundle == null)
            {
                throw new Exception($"assets bundle not found: {assetBundleName}");
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets = assetBundle.LoadAllAssets();
                foreach (UnityEngine.Object asset in assets)
                {
                    AddResource(assetBundleName, asset.name, asset);
                }
            }

            abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
            this.bundles[assetBundleName] = abInfo;
        }
예제 #5
0
        public virtual Session OnAccept(AChannel channel)
        {
            Session session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.Sessions.Add(session.Id, session);
            channel.Start();
            return(session);
        }
예제 #6
0
        public long NewOnceTimer(long tillTime, Action action)
        {
            OnceTimer timer = EntityFactory.CreateWithParent <OnceTimer, Action>(this, action);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            return(timer.Id);
        }
예제 #7
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(IPEndPoint ipEndPoint)
        {
            AChannel channel = this.Service.ConnectChannel(ipEndPoint);
            Session  session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.Sessions.Add(session.Id, session);
            channel.Start();
            return(session);
        }
예제 #8
0
        /// <summary>
        /// 创建一个新Session
        /// </summary>
        public Session Create(string address)
        {
            AChannel channel = this.Service.ConnectChannel(address);
            Session  session = EntityFactory.CreateWithParent <Session, AChannel>(this, channel);

            this.Sessions.Add(session.Id, session);
            channel.Start();
            return(session);
        }
예제 #9
0
        public async ETTask <bool> WaitAsync(long time)
        {
            long tillTime = TimeHelper.Now() + time;
            ETTaskCompletionSource <bool> tcs = new ETTaskCompletionSource <bool>();
            OnceWaitTimer timer = EntityFactory.CreateWithParent <OnceWaitTimer, ETTaskCompletionSource <bool> >(this, tcs);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            return(await tcs.Task);
        }
예제 #10
0
        public override async ETTask <UI> OnCreate(UIComponent uiComponent)
        {
            ResourcesComponent.Instance.LoadBundle(UIType.UILobby.StringToAB());
            GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby);
            GameObject gameObject       = UnityEngine.Object.Instantiate(bundleGameObject);
            UI         ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILobby, gameObject);

            ui.AddComponent <UILobbyComponent>();
            return(ui);
        }
예제 #11
0
        public long NewOnceTimer(long tillTime, Action action)
        {
            if (tillTime < TimeHelper.ServerNow())
            {
                Log.Error($"new once time too small: {tillTime}");
            }
            TimerAction timer = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, TimerClass.OnceTimer, 0, action, true);

            this.AddTimer(tillTime, timer);
            return(timer.Id);
        }
예제 #12
0
파일: DUIHelper.cs 프로젝트: chengxu-yh/ET
        public static async ETTask <UI> InstantiateFromBundle(UIComponent uiComponent, string uiBundle)
        {
            await ResourcesComponent.Instance.LoadBundleAsync(uiBundle.StringToAB());

            GameObject bundleGameObject = (GameObject)ResourcesComponent.Instance.GetAsset(uiBundle.StringToAB(), uiBundle);
            GameObject gameObject       = UnityEngine.Object.Instantiate(bundleGameObject);

            UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, uiBundle, gameObject);

            return(ui);
        }
예제 #13
0
        /// <summary>
        /// 创建一个RepeatedTimer
        /// </summary>
        private long NewRepeatedTimerInner(long time, Action action)
        {
#if NOT_CLIENT
            if (time < 100)
            {
                throw new Exception($"repeated timer < 100, timerType: time: {time}");
            }
#endif
            long        tillTime = TimeHelper.ServerNow() + time;
            TimerAction timer    = EntityFactory.CreateWithParent <TimerAction, TimerClass, long, object>(this, TimerClass.RepeatedTimer, time, action, true);
            this.AddTimer(tillTime, timer);
            return(timer.Id);
        }
예제 #14
0
        /// <summary>
        /// 创建一个RepeatedTimer
        /// </summary>
        /// <param name="time"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public long NewRepeatedTimer(long time, Action <bool> action)
        {
            if (time < 30)
            {
                throw new Exception($"repeated time < 30");
            }
            long          tillTime = TimeHelper.Now() + time;
            RepeatedTimer timer    = EntityFactory.CreateWithParent <RepeatedTimer, long, Action <bool> >(this, time, action);

            this.timers[timer.Id] = timer;
            AddToTimeId(tillTime, timer.Id);
            return(timer.Id);
        }
예제 #15
0
        public override async ETTask <UI> OnCreate(UIComponent uiComponent)
        {
            await ETTask.CompletedTask;

            ResourcesComponent.Instance.LoadBundle(UIType.UILogin.StringToAB());

            UnityEngine.Object bundleGameObject = ResourcesComponent.Instance.GetAsset(UIType.UILogin.StringToAB(), UIType.UILogin);

            GameObject gameObject = UnityEngine.Object.Instantiate(bundleGameObject) as GameObject;

            UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILogin, gameObject);

            ui.AddComponent <UILoginComponent>();

            return(ui);
        }
예제 #16
0
        public async ETTask <CoroutineLock> Wait(CoroutineLockType coroutineLockType, long key)
        {
            CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                queue = EntityFactory.Create <CoroutineLockQueue>(this.Domain);
                coroutineLockQueueType.Add(key, queue);

                return(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key));
            }

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

            queue.Enqueue(tcs);
            return(await tcs.Task);
        }
예제 #17
0
        public override async ETTask <UI> OnCreate(UIComponent uiComponent)
        {
            try
            {
                GameObject bundleGameObject = ((GameObject)Resources.Load("KV")).Get <GameObject>(UIType.UILoading);
                GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
                go.layer = LayerMask.NameToLayer(LayerNames.UI);
                UI ui = EntityFactory.CreateWithParent <UI, string, GameObject>(uiComponent, UIType.UILoading, go);

                ui.AddComponent <UILoadingComponent>();
                return(ui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
예제 #18
0
        public void Notify(CoroutineLockType coroutineLockType, long key)
        {
            CoroutineLockQueueType coroutineLockQueueType = this.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                throw new Exception($"first work notify not find queue");
            }
            if (queue.Count == 0)
            {
                coroutineLockQueueType.Remove(key);
                queue.Dispose();
                return;
            }

            ETTaskCompletionSource <CoroutineLock> tcs = queue.Dequeue();

            tcs.SetResult(EntityFactory.CreateWithParent <CoroutineLock, CoroutineLockType, long>(this, coroutineLockType, key));
        }
예제 #19
0
        public static Skill Create(Entity parent, int configid)
        {
            Skill skill = EntityFactory.CreateWithParent <Skill, int>(parent, configid);

            return(skill);
        }
예제 #20
0
        private async ETTask LoadOneBundleAsync(string assetBundleName, bool isScene)
        {
            assetBundleName = assetBundleName.BundleNameToLower();
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                return;
            }

            string      p           = "";
            AssetBundle assetBundle = null;

            if (!Define.IsAsync)
            {
#if UNITY_EDITOR
                if (isScene)
                {
                    p = Path.Combine(Application.dataPath, "../../AssetBundles/Windows_Scene/", assetBundleName);
                    if (File.Exists(p)) // 如果场景有预先打包
                    {
                        using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.CreateWithParent <AssetsBundleLoaderAsync>(this))
                        {
                            assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
                        }

                        if (assetBundle == null)
                        {
                            // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
                            Log.Warning($"Scene bundle not found: {assetBundleName}");
                            return;
                        }

                        abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
                        this.bundles[assetBundleName] = abInfo;
                    }
                }
                else
                {
                    string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                    foreach (string s in realPath)
                    {
                        string             assetName = Path.GetFileNameWithoutExtension(s);
                        UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                        AddResource(assetBundleName, assetName, resource);
                    }

                    if (realPath.Length > 0)
                    {
                        abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                        this.bundles[assetBundleName] = abInfo;
                        //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                    }
                    else
                    {
                        Log.Error("Bundle not exist! BundleName: " + assetBundleName);
                    }
                }
                // 编辑器模式也不能同步加载
                await TimerComponent.Instance.WaitAsync(20);
#endif
                return;
            }


            p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            if (!File.Exists(p))
            {
                Log.Error("Async load bundle not exist! BundleName : " + p);
                return;
            }

            using (AssetsBundleLoaderAsync assetsBundleLoaderAsync = EntityFactory.CreateWithParent <AssetsBundleLoaderAsync>(this))
            {
                assetBundle = await assetsBundleLoaderAsync.LoadAsync(p);
            }

            if (assetBundle == null)
            {
                // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
                Log.Warning($"assets bundle not found: {assetBundleName}");
                return;
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = EntityFactory.CreateWithParent <AssetsLoaderAsync, AssetBundle>(this, assetBundle))
                {
                    assets = await assetsLoaderAsync.LoadAllAssetsAsync();
                }

                foreach (UnityEngine.Object asset in assets)
                {
                    AddResource(assetBundleName, asset.name, asset);
                }
            }

            abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
            this.bundles[assetBundleName] = abInfo;

            //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
        }
예제 #21
0
        private async ETTask <ABInfo> LoadOneBundleAsync(string assetBundleName)
        {
            assetBundleName = assetBundleName.BundleNameToLower();
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                return(null);
            }

            string      p           = "";
            AssetBundle assetBundle = null;

            if (!Define.IsAsync)
            {
#if UNITY_EDITOR
                string[] realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    AddResource(assetBundleName, assetName, resource);
                }

                if (realPath.Length > 0)
                {
                    abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                    this.bundles[assetBundleName] = abInfo;
                    //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                }
                else
                {
                    Log.Error("Bundle not exist! BundleName: " + assetBundleName);
                }

                // 编辑器模式也不能同步加载
                await TimerComponent.Instance.WaitAsync(100);
#endif
                return(abInfo);
            }

            p = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            if (!File.Exists(p))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

            Log.Debug("Async load bundle BundleName : " + p);

            // if (!File.Exists(p))
            // {
            //     Log.Error("Async load bundle not exist! BundleName : " + p);
            //     return null;
            // }

            assetBundle = await AssetBundleHelper.UnityLoadBundleAsync(p);

            if (assetBundle == null)
            {
                // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
                Log.Warning($"assets bundle not found: {assetBundleName}");
                return(null);
            }

            abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
            this.bundles[assetBundleName] = abInfo;
            return(abInfo);
            //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
        }
예제 #22
0
        private void LoadOneBundle(string assetBundleName)
        {
            assetBundleName = assetBundleName.BundleNameToLower();
            ABInfo abInfo;

            if (this.bundles.TryGetValue(assetBundleName, out abInfo))
            {
                ++abInfo.RefCount;
                //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                return;
            }

            if (!Define.IsAsync)
            {
#if UNITY_EDITOR
                string[] realPath = null;
                realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName);
                foreach (string s in realPath)
                {
                    string             assetName = Path.GetFileNameWithoutExtension(s);
                    UnityEngine.Object resource  = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s);
                    AddResource(assetBundleName, assetName, resource);
                }

                if (realPath.Length > 0)
                {
                    abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null);
                    this.bundles[assetBundleName] = abInfo;
                    //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
                }
                else
                {
                    Log.Error($"assets bundle not found: {assetBundleName}");
                }
#endif
                return;
            }

            string      p           = Path.Combine(PathHelper.AppHotfixResPath, assetBundleName);
            AssetBundle assetBundle = null;
            if (File.Exists(p))
            {
                assetBundle = AssetBundle.LoadFromFile(p);
            }
            else
            {
                p           = Path.Combine(PathHelper.AppResPath, assetBundleName);
                assetBundle = AssetBundle.LoadFromFile(p);
            }

            if (assetBundle == null)
            {
                // 获取资源的时候会抛异常,这个地方不直接抛异常,因为有些地方需要Load之后判断是否Load成功
                Log.Warning($"assets bundle not found: {assetBundleName}");
                return;
            }

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                var assets = assetBundle.LoadAllAssets();
                foreach (UnityEngine.Object asset in assets)
                {
                    AddResource(assetBundleName, asset.name, asset);
                }
            }

            abInfo = EntityFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, assetBundle);
            this.bundles[assetBundleName] = abInfo;

            //Log.Debug($"---------------load one bundle {assetBundleName} refcount: {abInfo.RefCount}");
        }
예제 #23
0
        public static Trigger Create(Entity parent, TriggerType type)
        {
            Trigger trigger = EntityFactory.CreateWithParent <Trigger, TriggerType>(parent, type);

            return(trigger);
        }