Exemple #1
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);
        }
Exemple #2
0
        public static UI Create(string uiType)
        {
            try
            {
                ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
                resourcesComponent.LoadBundle(uiType.StringToAB());
                GameObject bundleGameObject = (GameObject)resourcesComponent.GetAsset(uiType.StringToAB(), uiType);
                GameObject gameObject       = UnityEngine.Object.Instantiate(bundleGameObject);

                UI ui = EntityFactory.Create <UI, string, GameObject>(Game.Scene, uiType, gameObject);

                return(ui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
        public override async ETTask C2G_LoginGateHandler(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
        {
            Console.WriteLine("C2G_LoginGateHandler");
            Scene scene = Game.Scene.Get(request.GateId);

            if (scene == null)
            {
                return;
            }

            string account = scene.GetComponent <GateSessionKeyComponent>().Get(request.Key);

            if (account == null)
            {
                response.Error   = ErrorCode.ERR_ConnectGateKeyError;
                response.Message = "Gate key验证失败!";
                reply();
                return;
            }

            var results = await DBComponent.Instance.Query <Player>(x => x.Account == account);

            Player player = null;

            if (results.Count > 0)
            {
                player = results[0];
            }
            else
            {
                player = EntityFactory.Create <Player, string>(Game.Scene, account);
                DBComponent.Instance.Save(player).Coroutine();
            }
            scene.GetComponent <PlayerComponent>().Add(player);
            session.AddComponent <SessionPlayerComponent>().Player = player;
            session.AddComponent <MailBoxComponent, MailboxType>(MailboxType.GateSession);

            response.PlayerId = player.Id;
            reply();

            //session.Send(new G2C_TestHotfixMessage() { Info = "recv hotfix message success" });
            await ETTask.CompletedTask;
        }
Exemple #4
0
        public static async ETVoid Login(string account)
        {
            // 创建一个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>(Game.Scene, 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
            });

            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;

            // 测试消息有成员是class类型
            G2C_PlayerInfo g2CPlayerInfo = (G2C_PlayerInfo)await SessionComponent.Instance.Session.Call(new C2G_PlayerInfo());

            // 逻辑层不应该去调用UI,逻辑层只关心逻辑并且抛出事件,由UI层自己去订阅事件,而且注意事件名字
            // 很多人容易把这个事件取名成LoginFinishiCreateLobbyUI,这是不对的,事件抛出去不可能知道谁订阅了这个事件,
            // 也不会知道别人订阅这个事件是干什么的,这里只知道我Login Finish
            Game.EventSystem.Run(EventIdType.LoginFinish);
        }
Exemple #5
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);
        }
        public static void Check(this ActorLocationSenderComponent self)
        {
            using (ListComponent <long> list = EntityFactory.Create <ListComponent <long> >(self.Domain))
            {
                long timeNow = TimeHelper.Now();
                foreach ((long key, Entity value) in self.Children)
                {
                    ActorLocationSender actorLocationMessageSender = (ActorLocationSender)value;

                    if (timeNow > actorLocationMessageSender.LastSendOrRecvTime + ActorLocationSenderComponent.TIMEOUT_TIME)
                    {
                        list.List.Add(key);
                    }
                }

                foreach (long id in list.List)
                {
                    self.Remove(id);
                }
            }
        }
Exemple #7
0
        public static FUI CreateFUI(string uiType)
        {
            try
            {
                ETModel.Game.Scene.GetComponent <FUIPackageComponent>().AddPackage(uiType);

                FUI fui = EntityFactory.Create <FUI, string, GObject>(Game.Scene, uiType, UIPackage.CreateObject(uiType, uiType));
                fui.Name = uiType;

                // 挂上窗口组件就成了窗口
                FUIWindowComponent fWindow = fui.AddComponent <FUIWindowComponent>();
                fWindow.Modal = true;
                fWindow.Show();

                return(fui);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(null);
            }
        }
Exemple #8
0
        public static async ETVoid MoveTo(this UnitPathComponent self, Vector3 target)
        {
            if ((self.Target - target).magnitude < 0.1f)
            {
                return;
            }

            self.Target = target;

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

            PathfindingComponent pathfindingComponent = self.Domain.GetComponent <PathfindingComponent>();

            self.ABPath = EntityFactory.Create <ABPathWrap, Vector3, Vector3>(self.Domain, unit.Position, new Vector3(target.x, target.y, target.z));
            pathfindingComponent.Search(self.ABPath);
            Log.Debug($"find result: {self.ABPath.Result.ListToString()}");

            self.CancellationTokenSource?.Cancel();
            self.CancellationTokenSource = EntityFactory.Create <ETCancellationTokenSource>(self.Domain);
            await self.MoveAsync(self.ABPath.Result);

            self.CancellationTokenSource.Dispose();
            self.CancellationTokenSource = null;
        }
Exemple #9
0
 public override void Awake(FUIComponent self)
 {
     self.Root = EntityFactory.Create <FUI, GObject>(self, GRoot.inst);
 }