Example #1
0
        protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message)
        {
            UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>();

            foreach (UnitInfo unitInfo in message.Units)
            {
                if (unitComponent.Get(unitInfo.UnitId) != null)
                {
                    continue;
                }
                Unit unit = UnitFactory.Create(unitInfo.UnitId);
                unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);

                SyncType type = Game.Scene.GetComponent <NetSyncComponent>().type;
                if (type == SyncType.Frame)
                {
                    if (PlayerComponent.Instance.MyPlayer.UnitId == unit.Id)
                    {
                        Game.Scene.GetComponent <CameraComponent>().Unit = unit;
                    }
                }
            }

            await ETTask.CompletedTask;
        }
        protected override void Run(Session session, Actor_CreateUnits message)
        {
            // 加载Unit资源
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();

            resourcesComponent.LoadBundle($"Unit.unity3d");

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

            foreach (UnitInfo unitInfo in message.Units)
            {
                if (unitComponent.Get(unitInfo.UnitId) != null)
                {
                    continue;
                }
                Unit unit = UnitFactory.Create(unitInfo.UnitId);
                unit.Position = new Vector3(unitInfo.X / 1000f, 0, unitInfo.Z / 1000f);
                unit.IntPos   = new VInt3(unitInfo.X, 0, unitInfo.Z);

                if (PlayerComponent.Instance.MyPlayer.UnitId == unit.Id)
                {
                    ETModel.Game.Scene.GetComponent <CameraComponent>().Unit = unit;
                }
            }

            Game.Scene.AddComponent <OperaComponent>();
        }
Example #3
0
        protected override async ETTask Run(ETModel.Session session, M2C_CreateUnits message)
        {
            UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>();

            foreach (UnitInfo unitInfo in message.Units)
            {
                if (unitComponent.Get(unitInfo.UnitId) != null)
                {
                    continue;
                }
                Unit unit = UnitFactory.Create(ETModel.Game.Scene, unitInfo.UnitId);
                unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
            }

            await ETTask.CompletedTask;
        }
        protected override async ETTask Run(Session session, G2M_EnterWorld request, M2G_EnterWorld response, Action reply)
        {
            Log.Info("Map服收到玩家请求进入的信息: " + request.Account);

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

            //查看玩家是否已经登录创建过
            if (unitComponent.UnitHaveBeCreated(request.Account))
            {
                enterUnit = unitComponent.getUnitByAccount(request.Account);
            }
            else
            {
                //添加一个单位
                enterUnit = UnitFactory.Create(request.Account);
                unitComponent.addUnitToDict(request.Account, enterUnit);

                enterUnit.InitPositionX = 0.0f;
                enterUnit.InitPositionY = 0.0f;
                enterUnit.InitPositionZ = 0.0f;
            }

            //Unit EmmpyUnit = UnitFactory.Create("EMMPY");
            //unitComponent.addUnitToDict("EMMPY", EmmpyUnit);
            //EmmpyUnit.InitPositionX = 20;
            //EmmpyUnit.InitPositionY = 200;
            //EmmpyUnit.InitPositionZ = 2000;

            //指定InstanceId
            enterUnit.GateInstanceId = request.PlayerGateInstanceId;

            response.Account = request.Account;

            response.PlayerMapInstanceId = enterUnit.InstanceId;

            reply();
            Log.Info("Map服创建实例完成,同意进入");

            await ETTask.CompletedTask;
        }
Example #5
0
        public void Awake()
        {
            otherPlayers = new List <Unit>();
            Game.Scene.GetComponent <GlobalConfigComponent>().networkPlayMode = false;
            Game.EventSystem.Run(EventIdType.LoadAssets);
            {
                UnitData playerData = new UnitData();
                playerData.groupIndex = GroupIndex.Player;
                playerData.layerMask  = UnitLayerMask.ALL;
                playerData.unitLayer  = UnitLayer.Character;
                playerData.unitTag    = UnitTag.Player;
                //创建主角
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, playerData);
                v.Position = new UnityEngine.Vector3(-10, 0, -10);
                UnitComponent.Instance.MyUnit = v;
                v.AddComponent <CameraComponent>();
                v.AddComponent <CommandComponent>();
                var input = v.AddComponent <InputComponent>();
                var list  = v.GetComponent <ActiveSkillComponent>().skillList.Keys.ToArray();
                input.AddSkillToHotKey("Q", list[0]);
                input.AddSkillToHotKey("W", list[1]);
                input.AddSkillToHotKey("E", list[2]);
                BattleEventHandler.LoadAssets(v);
            }
            UnitData monsterData = new UnitData();

            monsterData.groupIndex = GroupIndex.Monster;
            monsterData.layerMask  = UnitLayerMask.ALL;
            monsterData.unitLayer  = UnitLayer.Character;
            monsterData.unitTag    = UnitTag.Monster;
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(4.2f, 4, -15);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(-10, 0, 11);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }
            {
                //创建怪物
                Unit v = UnitFactory.Create(IdGenerater.GenerateId(), 1001, monsterData);
                v.Position = new UnityEngine.Vector3(-10, 0, 15);
                v.Rotation = UnityEngine.Quaternion.LookRotation(v.Position - UnitComponent.Instance.MyUnit.Position, Vector3.up);
                //v.AddComponent<PDynamicBodyComponent, Shape>(new CircleShape() { Radius = 0.5f });

                BattleEventHandler.LoadAssets(v);
                otherPlayers.Add(v);
            }

            //这里准备其他角色施放技能的参数
        }