public static UI Create(Entity domain)
        {
            try
            {
                GameObject bundleGameObject = ((GameObject)ResourcesHelper.Load("KV")).Get <GameObject>(UIType.UILoading);
                GameObject go = UnityEngine.Object.Instantiate(bundleGameObject);
                go.layer = LayerMask.NameToLayer(LayerNames.UI);
                UI ui = EntityFactory.Create <UI, string, GameObject>(domain, UIType.UILoading, go);

                ui.AddComponent <UILoadingComponent>();
                return(ui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Example #2
0
        public UI Get(string name)
        {
            UI child;

            if (this.children.TryGetValue(name, out child))
            {
                return(child);
            }
            GameObject childGameObject = this.ViewGO.transform.Find(name)?.gameObject;

            if (childGameObject == null)
            {
                return(null);
            }
            child = EntityFactory.Create <UI, string, GameObject>(this.Domain, name, childGameObject);
            this.Add(child);
            return(child);
        }
Example #3
0
        public static UI Create()
        {
            try
            {
                ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
                resourcesComponent.LoadBundle(UIType.UILobby.StringToAB());
                GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(UIType.UILobby.StringToAB(), UIType.UILobby);
                GameObject gameObject       = UnityEngine.Object.Instantiate(bundleGameObject);
                UI         ui = EntityFactory.Create <UI, string, GameObject>(Game.Scene, UIType.UILobby, gameObject);

                ui.AddComponent <UILobbyComponent>();
                return(ui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Example #4
0
        /// <summary>
        /// 根据child的名字自动获取child的FUI类,如果child没有FUI,则给它创建一个
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public FUI Get(string name)
        {
            FUI child;

            if (this.children.TryGetValue(name, out child))
            {
                return(child);
            }

            if (!(this.GObject is GComponent gComponent))
            {
                throw new Exception($"this ui is not GComponent, so has not child, {this.Name}");
            }

            GObject gObject = gComponent.GetChild(name);

            child = EntityFactory.Create <FUI, GObject>(this, gObject);
            this.Add(child);

            return(child);
        }
Example #5
0
        public static async ETVoid OnLoginAsync(Entity domain, string account)
        {
            try
            {
                // 创建一个ETModel层的Session
                ETModel.Session session = ETModel.Game.Scene.GetComponent<NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
				
                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session realmSession = EntityFactory.Create<Session, ETModel.Session>(domain, session);
                R2C_Login r2CLogin = (R2C_Login) await realmSession.Call(new C2R_Login() { Account = account, Password = "******" });
                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                ETModel.Session gateSession = ETModel.Game.Scene.GetComponent<NetOuterComponent>().Create(r2CLogin.Address);
                ETModel.Game.Scene.AddComponent<ETModel.SessionComponent>().Session = gateSession;
				
                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent<SessionComponent>().Session = EntityFactory.Create<Session, ETModel.Session>(Game.Scene, gateSession);
				
                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(
                    new C2G_LoginGate() { Key = r2CLogin.Key, GateId = r2CLogin.GateId});

                Log.Info("登陆gate成功!");

                // 创建Player
                Player player = ETModel.EntityFactory.CreateWithId<Player>(ETModel.Game.Scene, g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = ETModel.Game.Scene.GetComponent<PlayerComponent>();
                playerComponent.MyPlayer = player;

                Game.EventSystem.Run(EventIdType.LoginFinish);

                // 测试消息有成员是class类型
                G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo) await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        } 
Example #6
0
        public static Monster Create(Entity domain)
        {
            Monster monster = null;

            try
            {
                monster = EntityFactory.Create <Monster>(domain);
                monster.AddComponent <TransformComponent>();
                monster.AddComponent <MoveComponent>();
                monster.AddComponent <EntitySyncComponent>();
                monster.AddComponent <HealthComponent>();
#if !BODY3D
                monster.AddComponent <Body2dComponent>().CreateBody(1, 1);
#else
                monster.AddComponent <Body3dComponent>();
#endif
            }
            catch (System.Exception e)
            {
                Log.Error(e);
            }
            return(monster);
        }
Example #7
0
        public async ETVoid Lock(long key, long instanceId, int time = 0)
        {
            CoroutineLock coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Location, key);

            LockInfo lockInfo = EntityFactory.Create <LockInfo, long, CoroutineLock>(this.Domain, instanceId, coroutineLock);

            lockInfo.Parent = this;
            this.lockInfos.Add(key, lockInfo);

            Log.Info($"location lock key: {key} instanceId: {instanceId}");

            if (time > 0)
            {
                long lockInfoInstanceId = lockInfo.InstanceId;
                await TimerComponent.Instance.WaitAsync(time);

                if (lockInfo.InstanceId != lockInfoInstanceId)
                {
                    return;
                }
                UnLock(key, instanceId, instanceId);
            }
        }
Example #8
0
        public async ETTask StartAsync()
        {
            // 获取远程的Version.txt
            string versionUrl = "";

            try
            {
                using (UnityWebRequestAsync webRequestAsync = EntityFactory.Create <UnityWebRequestAsync>(this.Domain))
                {
                    versionUrl = GlobalConfigComponent.Instance.GlobalProto.GetUrl() + "StreamingAssets/" + "Version.txt";
                    //Log.Debug(versionUrl);
                    await webRequestAsync.DownloadAsync(versionUrl);

                    remoteVersionConfig = JsonHelper.FromJson <VersionConfig>(webRequestAsync.Request.downloadHandler.text);
                    //Log.Debug(JsonHelper.ToJson(this.VersionConfig));
                }
            }
            catch (Exception e)
            {
                throw new Exception($"url: {versionUrl}", e);
            }

            // 获取streaming目录的Version.txt
            VersionConfig streamingVersionConfig;
            string        versionPath = Path.Combine(PathHelper.AppResPath4Web, "Version.txt");

            using (UnityWebRequestAsync request = EntityFactory.Create <UnityWebRequestAsync>(this.Domain))
            {
                await request.DownloadAsync(versionPath);

                streamingVersionConfig = JsonHelper.FromJson <VersionConfig>(request.Request.downloadHandler.text);
            }

            // 删掉远程不存在的文件
            DirectoryInfo directoryInfo = new DirectoryInfo(PathHelper.AppHotfixResPath);

            if (directoryInfo.Exists)
            {
                FileInfo[] fileInfos = directoryInfo.GetFiles();
                foreach (FileInfo fileInfo in fileInfos)
                {
                    if (remoteVersionConfig.FileInfoDict.ContainsKey(fileInfo.Name))
                    {
                        continue;
                    }

                    if (fileInfo.Name == "Version.txt")
                    {
                        continue;
                    }

                    fileInfo.Delete();
                }
            }
            else
            {
                directoryInfo.Create();
            }

            // 对比MD5
            foreach (FileVersionInfo fileVersionInfo in remoteVersionConfig.FileInfoDict.Values)
            {
                // 对比md5
                string localFileMD5 = GetBundleMD5(streamingVersionConfig, fileVersionInfo.File);
                if (fileVersionInfo.MD5 == localFileMD5)
                {
                    continue;
                }
                this.bundles.Enqueue(fileVersionInfo.File);
                this.TotalSize += fileVersionInfo.Size;
            }
        }
Example #9
0
 public override void Awake(FUIComponent self)
 {
     GRoot.inst.SetContentScaleFactor(1280, 720, UIContentScaler.ScreenMatchMode.MatchWidthOrHeight);
     self.Root = EntityFactory.Create <FUI, GObject>(self, GRoot.inst);
 }
Example #10
0
        public async ETTask LoadOneBundleAsync(string assetBundleName)
        {
            ABInfo abInfo;

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

            //Log.Debug($"---------------load one bundle {assetBundleName}");
            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))
            {
                p = Path.Combine(PathHelper.AppResPath, assetBundleName);
            }

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

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

            if (!assetBundle.isStreamedSceneAssetBundle)
            {
                // 异步load资源到内存cache住
                UnityEngine.Object[] assets;
                using (AssetsLoaderAsync assetsLoaderAsync = EntityFactory.Create <AssetsLoaderAsync, AssetBundle>(this.Domain, 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;
        }