Exemplo n.º 1
0
        protected override async Task 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();
        }
        private ActorLocationSender Get(long id)
        {
            if (id == 0)
            {
                throw new Exception($"actor id is 0");
            }
            if (Children.TryGetValue(id, out Entity actorLocationSender))
            {
                return((ActorLocationSender)actorLocationSender);
            }

            actorLocationSender        = EntityFactory.CreateWithId <ActorLocationSender>(Domain, id);
            actorLocationSender.Parent = this;
            return((ActorLocationSender)actorLocationSender);
        }
Exemplo n.º 3
0
 protected override async Task Run(Scene scene, M2M_TrasferUnitRequest request, M2M_TrasferUnitResponse response, Action reply)
 {
     if (request.Unit != null)
     {
         Unit unit = EntityFactory.CreateWithId <Unit, UnitType>(scene, request.Unit.UnitId, request.Unit.UnitType);
         unit.Position = new UnityEngine.Vector3(request.Unit.X, request.Unit.Y, request.Unit.Z);
         // 将unit加入事件系统
         Log.Debug(DCETRuntime.MongoHelper.ToJson(request.Unit));
         // 这里不需要注册location,因为unlock会更新位置
         unit.AddComponent <MailBoxComponent>();
         scene.GetComponent <UnitComponent>().Add(unit);
         response.InstanceId = unit.InstanceId;
         reply();
         await Task.CompletedTask;
     }
 }
Exemplo n.º 4
0
        public static Unit Create(Entity domain, long id)
        {
            ResourcesComponent resourcesComponent = Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            GameObject         prefab             = GameObjectHelper.GetGameObject(bundleGameObject, "Skeleton");

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

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

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

            unitComponent.Add(unit);
            return(unit);
        }
Exemplo n.º 5
0
        public static async void OnLoginAsync(string account)
        {
            try
            {
                Log.Debug($"服务器地址:{GlobalConfigComponent.Instance.GlobalProto.Address}");
                Session session = Game.Scene.GetComponent <NetOuterComponent>().Create(GlobalConfigComponent.Instance.GlobalProto.Address);

                R2C_Login r2CLogin = (R2C_Login)await session.Call(new C2R_Login()
                {
                    Account = account, Password = "******"
                });

                session.Dispose();

                SessionComponent.Instance.Session = Game.Scene.GetComponent <NetOuterComponent>().Create(r2CLogin.Address);

                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.Exception(e);
            }
        }