protected override void Run(ETModel.Session session, M2C_AddUnits message) { int unittype = message.UnitType; switch (unittype) { case 0: UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); int oldcount0 = unitComponent.Count; foreach (UnitInfo unitInfo in message.Units) { if (unitComponent.Get(unitInfo.UnitId) != null) { continue; } Unit unit0 = UnitFactory.Create(unitInfo.UnitId); unit0.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); unit0.AddComponent <MovePositionComponent>(); unit0.AddComponent <UnitPositionComponent>(); if (unitInfo.UnitId == PlayerComponent.Instance.MyPlayer.UnitId) { ///20190621//将参数unit 传给组件CameraComponent awake方法 ETModel.Game.EventSystem.Awake <Unit>(ETModel.Game.Scene.GetComponent <CameraComponent>(), unit0); unit0.AddComponent <CharacterControllerComponent>().isCanControl = true; ///20190703 Game.Scene.AddComponent <OperaComponent>(); Game.Scene.AddComponent <RaycastHitComponent>(); Game.Scene.AddComponent <KeyboardSkillComponent>(); Debug.Log(" M2C_AddUnitHandler-47: " + unit0.Id); } } Debug.Log(" M2C_AddUnitHandler-42-Player: " + unittype + " : " + oldcount0 + " + " + message.Units.Count + " = " + unitComponent.Count); break; case 1: MonsterUnitComponent enemyunitComponent = ETModel.Game.Scene.GetComponent <MonsterUnitComponent>(); int oldcount1 = enemyunitComponent.Count; foreach (UnitInfo unitInfo in message.Units) { if (enemyunitComponent.Get(unitInfo.UnitId) != null) { continue; } Unit unit1 = MonsterUnitFactory.Create(unitInfo.UnitId); unit1.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z); } Debug.Log(" M2C_AddUnitHandler-53-Monster: " + unittype + " : " + oldcount1 + " + " + message.Units.Count + " = " + enemyunitComponent.Count); break; case 2: break; } }
protected override void Run(ETModel.Session session, M2C_RemoveUnits message) { int unittype = message.UnitType; switch (unittype) { case 0: UnitComponent unitComponent = ETModel.Game.Scene.GetComponent <UnitComponent>(); int oldcount0 = unitComponent.Count; foreach (UnitInfo unitInfo in message.Units) { if (unitComponent.Get(unitInfo.UnitId) == null) { continue; } Unit unit0 = unitComponent.Get(unitInfo.UnitId); GameObject unitGo0 = unit0.GameObject; if (unit0 != null && unit0.GameObject != null) { if (unitInfo.UnitId == ETModel.Game.Scene.GetComponent <PlayerComponent>().MyPlayer.UnitId) { unit0.Position = new Vector3(-40, 0, -20); } else { unitComponent.Remove(unit0.Id); GameObject.Destroy(unitGo0, 1.0f); } } } Debug.Log(" M2C_AddUnitHandler-35-Player: " + unittype + " : " + oldcount0 + " - " + message.Units.Count + " = " + unitComponent.Count); break; case 1: MonsterUnitComponent enemyunitComponent = ETModel.Game.Scene.GetComponent <MonsterUnitComponent>(); int oldcount1 = enemyunitComponent.Count; foreach (UnitInfo unitInfo in message.Units) { if (enemyunitComponent.Get(unitInfo.UnitId) == null) { continue; } Unit unit1 = enemyunitComponent.Get(unitInfo.UnitId); GameObject unitGo1 = unit1.GameObject; if (unit1 != null && unit1.GameObject != null) { enemyunitComponent.Remove(unit1.Id); GameObject.Destroy(unitGo1, 1.0f); } } Debug.Log(" M2C_AddUnitHandler-56-Monster: " + unittype + " : " + oldcount1 + " - " + message.Units.Count + " = " + enemyunitComponent.Count); break; } }