public void ServerCreateUnits() { Vector2 sz = Utils.HalfCameraSize; // 创建玩家单位 foreach (GamePlayerController ctrl in GameManager.AllPlayers.Values) { Player playerInfo = ctrl.Player; SyncUnitInfo syncInfo = new SyncUnitInfo(Utils.IdGen.nextId, ResourceManager.instance.LoadUnit(string.Format("Units/[Player{0}]", ctrl.playerId), playerInfo.heroData)); syncInfo.hp = (float)syncInfo.baseInfo.maxHp; syncInfo.force = playerInfo.force; syncInfo.position = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2)); Unit unit = World.Current.CreateUnit(syncInfo, ctrl.playerId); PlayerUnitController.Current.Controlling = unit; // create 2nd test player unit syncInfo = new SyncUnitInfo(Utils.IdGen.nextId, ResourceManager.instance.LoadUnit(null, m_heroes[Utils.Random.Next(m_heroes.Count)].text)); syncInfo.hp = (float)syncInfo.baseInfo.maxHp; syncInfo.force = playerInfo.force; syncInfo.position = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2)); World.Current.CreateUnit(syncInfo, ctrl.playerId); } // 随即创建单位 StartCoroutine(RepeatCreateUnit("CreateTestUnit")); //CreateOneTestUnit(); // 世界开始运转 World.Current.StartWorld(); }
void CreateTestUnit() { Vector2 sz = Utils.HalfCameraSize; // 创建普通单位 SyncUnitInfo syncInfo = new SyncUnitInfo(Utils.IdGen.nextId, ResourceManager.instance.LoadUnit(null, m_testUnits[Utils.Random.Next(m_testUnits.Count)].text)); syncInfo.position = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2)); syncInfo.hp = (float)syncInfo.baseInfo.maxHp; syncInfo.force = Utils.Random.Next(8); World.Current.CreateUnit(syncInfo); }
void CreateOneTestUnit() { string path = "Units/Arcane"; Vector2 sz = Utils.HalfCameraSize; SyncUnitInfo syncInfo = new SyncUnitInfo(Utils.IdGen.nextId, ResourceManager.instance.LoadUnit(path)); syncInfo.position = new Vector2((float)(-sz.x + Utils.Random.NextDouble() * sz.x * 2), (float)(-sz.y + Utils.Random.NextDouble() * sz.y * 2)); syncInfo.hp = (float)syncInfo.baseInfo.maxHp; syncInfo.force = Utils.Random.Next(8); World.Current.CreateUnit(syncInfo); }
public SyncUnitControlVM(SyncUnitInfo unitInfo, int index) : this() { this._unitInfo = unitInfo; this.TrainBg = $"/Resources/zhuanxiang{index + 1}.png"; this._unitId = unitInfo.unit_id; this.SyncTypeName = unitInfo.unit_name; this.SyncTypeNumName = $"{unitInfo.paper_num ?? "0"}篇课文"; }
public SyncCreateUnit(SyncUnitInfo syncInfo, int playerId) { this.syncInfo = syncInfo; this.playerId = playerId; }
public void CreatePlayerUnit(SyncUnitInfo syncInfo, int playerId = 0) { }
/// <summary> /// Server发起 /// </summary> /// <param name="syncInfo"></param> /// <param name="playerId"></param> public Unit CreateUnit(SyncUnitInfo syncInfo, int playerId = 0) { localClient.ServerAddSyncAction(new SyncCreateUnit(syncInfo, playerId)); GamePlayerController player; GameManager.AllPlayers.TryGetValue(playerId, out player); GameObject obj = GameObjectPool.instance.Instantiate(unitPrefab); UnitNode node = obj.GetComponent <UnitNode>(); Unit unit = obj.GetComponent <Unit>(); ResourceManager.instance.LoadUnitModel(syncInfo.baseInfo.model); // high time cost ResourceManager.instance.AssignModelToUnitNode(syncInfo.baseInfo.model, node); unit.m_id = syncInfo.id; node.m_id = syncInfo.id; AddUnit(unit); unit.m_model = syncInfo.baseInfo.model; if (isServer) { unit.AI = UnitAI.instance; } unit.Name = syncInfo.baseInfo.name; unit.InitHp(syncInfo.hp, (float)syncInfo.baseInfo.maxHp); if (syncInfo.baseInfo.attackSkill.valid) { AttackAct atk = new AttackAct(syncInfo.baseInfo.attackSkill.name, (float)syncInfo.baseInfo.attackSkill.cd, new AttackValue(AttackValue.NameToType(syncInfo.baseInfo.attackSkill.type), (float)syncInfo.baseInfo.attackSkill.value), (float)syncInfo.baseInfo.attackSkill.vrange); atk.CastRange = (float)syncInfo.baseInfo.attackSkill.range; atk.CastHorizontal = syncInfo.baseInfo.attackSkill.horizontal; foreach (string ani in syncInfo.baseInfo.attackSkill.animations) { atk.AddCastAnimation(ModelNode.NameToId(ani)); } atk.ProjectileTemplate = ResourceManager.instance.LoadProjectile(syncInfo.baseInfo.attackSkill.projectile); unit.AddActiveSkill(atk); } node.position = syncInfo.position; node.SetFlippedX(syncInfo.flippedX); unit.force.Force = syncInfo.force; unit.MoveSpeedBase = (float)syncInfo.baseInfo.move; unit.Revivable = syncInfo.baseInfo.revivable; unit.Fixed = syncInfo.baseInfo.isfixed; unit.level.MaxLevel = 100; unit.level.Level = 10; if (player != null) { // 玩家单位 Debug.LogFormat("CreateUnit, unitId({0}) <-> playerId({1}).", unit.Id, player.playerId); if (player == localClient) { Debug.LogFormat("That's Me, {0}.", unit.Name); } // TEST !!!! unit.InitHp(5000, 5000); unit.AttackSkill.coolDownBase = 2.0f; unit.AttackSkill.coolDownSpeedCoeff = 2; unit.CriticalRateBase = 0.2f; unit.CriticalDamageBase = 20.0f; SplashPas splash = new SplashPas("SplashAttack", 0.5f, new Coeff(0.75f, 0), 1f, new Coeff(0.25f, 0)); unit.AddPassiveSkill(splash); if (player == localClient) { BattleWorldUI.Current.portraitGroup.AddPortrait(unit); } } node.SetFrame(ModelNode.kFrameDefault); CreateUnitHUD(unit); return(unit); }