protected override void 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;
                }
                UnitData unitData = new UnitData();

                unitData.groupIndex = (GroupIndex)unitInfo.GroupIndex;
                unitData.layerMask  = (UnitLayerMask)unitInfo.LayerMask;
                unitData.unitLayer  = (UnitLayer)unitInfo.UnitLayer;
                unitData.unitTag    = (UnitTag)unitInfo.UnitTag;
                Unit unit = UnitFactory.Create(unitInfo.UnitId, 1001, unitData);

                NumericComponent numericComponent = unit.GetComponent <NumericComponent>();
                foreach (var v in unitInfo.UnitNumerics)
                {
                    numericComponent.Set((NumericType)v.Type, v.Value);
                }
                BattleEventHandler.LoadAssets(unit);


                Vector3 postion = new Vector3(unitInfo.Position.X, unitInfo.Position.Y, unitInfo.Position.Z);
                unit.GameObject.transform.forward = new Vector3(unitInfo.Dir.X, unitInfo.Dir.Y, unitInfo.Dir.Z);
                unit.Position = postion;
                Dictionary <Type, IProperty> unitStateList = new Dictionary <Type, IProperty>();
                P_Position property_Position = new P_Position();
                property_Position.Value = postion; // 防止掉下去
                unitStateList.Add(typeof(P_Position), property_Position);
                unit.GetComponent <UnitStateComponent>().Init(unitStateList);
            }
        }
예제 #2
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);
            }

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