示例#1
0
        public static Unit Create(Entity domain, UnitInfo unitInfo)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

            unit.AddComponent <MoveComponent>();
            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            for (int i = 0; i < unitInfo.Ks.Count; ++i)
            {
                numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]);
            }

            unit.AddComponent <ObjectWait>();

            unit.AddComponent <XunLuoPathComponent>();

            UnitComponent unitComponent = domain.GetComponent <UnitComponent>();

            unitComponent.Add(unit);

            Game.EventSystem.Publish(new EventType.AfterUnitCreate()
            {
                Unit = unit
            });
            return(unit);
        }
示例#2
0
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(scene, IdGenerater.Instance.GenerateId(), 1001);

            unit.AddComponent <MoveComponent>();
            unit.Position = new Vector3(-10, 0, -10);

            NumericComponent numericComponent = unit.AddComponent <NumericComponent>();

            numericComponent.Set(NumericType.Speed, 6f);             // 速度是6米每秒

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            scene.GetComponent <UnitComponent>().Add(unit);
            response.UnitId = unit.Id;

            // 把自己广播给周围的人
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            createUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
            MessageHelper.Broadcast(unit, createUnits);

            // 把周围的人通知给自己
            createUnits.Units.Clear();
            Unit[] units = scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                createUnits.Units.Add(UnitHelper.CreateUnitInfo(u));
            }
            MessageHelper.SendActor(unit.GetComponent <UnitGateComponent>().GateSessionActorId, createUnits);

            reply();
        }
        protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
        {
            Unit unit = EntityFactory.CreateWithId <Unit>(scene, IdGenerater.GenerateId());

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.Position = new Vector3(-10, 0, -10);

            unit.AddComponent <MailBoxComponent>();
            await unit.AddLocation();

            unit.AddComponent <UnitGateComponent, long>(request.GateSessionId);
            scene.GetComponent <UnitComponent>().Add(unit);
            response.UnitId = unit.Id;


            // 广播创建的unit
            M2C_CreateUnits createUnits = new M2C_CreateUnits();

            Unit[] units = scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                UnitInfo unitInfo = new UnitInfo();
                unitInfo.X      = u.Position.x;
                unitInfo.Y      = u.Position.y;
                unitInfo.Z      = u.Position.z;
                unitInfo.UnitId = u.Id;
                createUnits.Units.Add(unitInfo);
            }
            MessageHelper.Broadcast(unit, createUnits);

            reply();
        }
示例#4
0
 public override void Awake(CoroutineLockComponent self)
 {
     CoroutineLockComponent.Instance = self;
     for (int i = 0; i < self.list.Capacity; ++i)
     {
         self.list.Add(EntityFactory.CreateWithId <CoroutineLockQueueType>(self.Domain, ++self.idGenerator));
     }
 }
示例#5
0
        public static CoroutineLock CreateCoroutineLock(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time, int count)
        {
            CoroutineLock coroutineLock = EntityFactory.CreateWithId <CoroutineLock, CoroutineLockType, long, int>(self.Domain, ++self.idGenerator, coroutineLockType, key, count, true);

            if (time > 0)
            {
                self.AddTimer(TimeHelper.ClientFrameTime() + time, coroutineLock);
            }
            return(coroutineLock);
        }
示例#6
0
        private static ActorLocationSender Get(this ActorLocationSenderComponent self, long id)
        {
            if (id == 0)
            {
                throw new Exception($"actor id is 0");
            }
            if (self.Children.TryGetValue(id, out Entity actorLocationSender))
            {
                return((ActorLocationSender)actorLocationSender);
            }

            actorLocationSender        = EntityFactory.CreateWithId <ActorLocationSender>(self.Domain, id);
            actorLocationSender.Parent = self;
            return((ActorLocationSender)actorLocationSender);
        }
示例#7
0
        public static Unit Create(Entity domain, long id)
        {
            Unit unit = EntityFactory.CreateWithId <Unit>(domain, id);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <UnitPathComponent>();

            Game.EventSystem.Run(EventIdType.AfterUnitCreate, unit);

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
示例#8
0
        public static Unit Create(Entity domain, long id)
        {
            Unit unit = EntityFactory.CreateWithId <Unit>(domain, id);

            unit.AddComponent <TurnComponent>();

            Game.EventSystem.Publish(new EventType.AfterUnitCreate()
            {
                Unit = unit
            });

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
示例#9
0
        public static async ETTask <CoroutineLock> Wait(this CoroutineLockComponent self, CoroutineLockType coroutineLockType, long key, int time = 60000)
        {
            CoroutineLockQueueType coroutineLockQueueType = self.list[(int)coroutineLockType];

            if (!coroutineLockQueueType.TryGetValue(key, out CoroutineLockQueue queue))
            {
                coroutineLockQueueType.Add(key, EntityFactory.CreateWithId <CoroutineLockQueue>(self.Domain, ++self.idGenerator, true));
                return(self.CreateCoroutineLock(coroutineLockType, key, time, 1));
            }

            ETTask <CoroutineLock> tcs = ETTask <CoroutineLock> .Create(true);

            queue.Add(tcs, time);

            return(await tcs);
        }
示例#10
0
        public static async ETVoid OnLoginAsync(Entity domain, string address, string account)
        {
            try
            {
                // 创建一个ETModel层的Session
                Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(address);

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = EntityFactory.Create <Session, Session>(domain, session);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = account, Password = "******"
                });

                realmSession.Dispose();

                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;

                // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中
                Game.Scene.AddComponent <SessionComponent>().Session = EntityFactory.Create <Session, 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          = EntityFactory.CreateWithId <Player>(Game.Scene, g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = 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);
            }
        }
示例#11
0
文件: UnitFactory.cs 项目: wryl/ET
        public static Unit Create(Entity domain, UnitInfo unitInfo)
        {
            Unit unit = EntityFactory.CreateWithId <Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <UnitPathComponent>();

            UnitComponent unitComponent = domain.GetComponent <UnitComponent>();

            unitComponent.Add(unit);

            Game.EventSystem.Publish(new EventType.AfterUnitCreate()
            {
                Unit = unit
            });
            return(unit);
        }
示例#12
0
        public static Unit Create(Entity domain, UnitInfo unitInfo)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = bundleGameObject.Get <GameObject>("Skeleton");

            GameObject go   = UnityEngine.Object.Instantiate(prefab);
            Unit       unit = EntityFactory.CreateWithId <Unit, GameObject>(domain, unitInfo.UnitId, go);

            unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

            unit.AddComponent <MoveComponent>();
            unit.AddComponent <TurnComponent>();
            unit.AddComponent <UnitPathComponent>();
            unit.AddComponent <AnimatorComponent>();

            UnitComponent unitComponent = Game.Scene.GetComponent <UnitComponent>();

            unitComponent.Add(unit);
            return(unit);
        }
示例#13
0
        protected override async ETTask Run(Session session, C2R_Register request, R2C_Register response, Action reply)
        {
            string account  = request.Account;
            string password = request.Password;

            if (string.IsNullOrEmpty(account) || string.IsNullOrEmpty(password))
            {
                response.Error = ErrorCode.ERR_AccountOrPasswordError;
                reply();
                return;
            }

            var accountList = await session.DomainScene().GetComponent <DBComponent>().Query <AccountInfo>(d => d.Account == account);

            if (accountList.Count > 0)
            {
                response.Error = ErrorCode.ERR_AccountOrPasswordError;
                reply();
                return;
            }
            try
            {
                AccountInfo accountInfo = EntityFactory.CreateWithId <AccountInfo>(session, IdGenerater.Instance.GenerateId());
                accountInfo.Account  = account;
                accountInfo.Password = password;

                await session.DomainScene().GetComponent <DBComponent>().Save(accountInfo);
            }
            catch (Exception e)
            {
                Log.Error(e);
                response.Error   = ErrorCode.ERR_AccountOrPasswordError;
                response.Message = e.ToString();
                reply();
                return;
            }
            response.Error = ErrorCode.ERR_Success;
            reply();
            await ETTask.CompletedTask;
        }
示例#14
0
        public static async ETVoid OnLoginAsync()
        {
            try
            {
                UILoginComponent login = Game.Scene.GetComponent <UIComponent>().Get(UIType.UILogin).GetComponent <UILoginComponent>();

                // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息
                Session   realmSession = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);
                R2C_Login r2CLogin     = (R2C_Login)await realmSession.Call(new C2R_Login()
                {
                    Account = "abc", Password = "******"
                });

                realmSession.Dispose();
                Log.Info("正在登录中...");

                //判断Realm服务器返回结果
                if (r2CLogin.Error == ErrorCode.ERR_AccountOrPasswordError)
                {
                    Log.Info("登录失败,账号或密码错误");
                    login.account.text  = "";
                    login.password.text = "";
                    return;
                }


                // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中
                Session gateSession = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);
                Game.Scene.AddComponent <SessionComponent>().Session = gateSession;
                SessionComponent.Instance.Session = gateSession;

                G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await gateSession.Call(
                    new C2G_LoginGate()
                {
                    Key = r2CLogin.Key, GateId = r2CLogin.GateId
                });

                //判断登陆Gate服务器返回结果
                if (g2CLoginGate.Error == ErrorCode.ERR_ConnectGateKeyError)
                {
                    Log.Info("连接网关服务器超时");
                    login.account.text  = "";
                    login.password.text = "";
                    gateSession.Dispose();
                    return;
                }
                //判断通过则登陆Gate成功
                Log.Info("登陆gate成功!");

                // 创建Player
                Player          player          = EntityFactory.CreateWithId <Player>(Game.Scene, g2CLoginGate.PlayerId);
                PlayerComponent playerComponent = 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);
            }
        }