Exemple #1
0
 public void AddUnitButton(GameObject unit, ActualDataUnit unitData)
 {
     var unitButton = Instantiate(UnitButtonPrefab);
     unitButton.transform.SetParent(UnitsPanel.transform, false);
     var unitButtonComponent = unitButton.GetComponent<UnitButton>();
     unitButtonComponent.UnitType = unitData.type_unit;
     unitButtonComponent.Unit = unit;
     unitButtonComponent.CameraScript = MainCamera.GetComponent<ViewDrag>();
 }
 private void UpdateUnit(IDictionary<int, GameObject> gameObjects, ActualDataUnit unitData, ICollection<int> processedIds)
 {
     if (gameObjects.ContainsKey(unitData.id_unit))
     {
         AdjustUnitData(gameObjects[unitData.id_unit], unitData);
     }
     else
     {
         GameObject unit;
         if (unitData.type_unit == UnitType.Knight)
         {
             unit = CreateKnight(unitData);
             _knights.Add(unitData.id_unit, unit);
             if (GameInfo.Role == PlayerRole.Attacker)
                 UIManager.AddUnitButton(unit, unitData);
         }
         else
         {
             unit = CreateTower(unitData);
             _towers.Add(unitData.id_unit, unit);
             if (GameInfo.Role == PlayerRole.Defender)
                 UIManager.AddUnitButton(unit, unitData);
         }
     }
     processedIds.Add(unitData.id_unit);
 }
 /// <summary>
 /// Создаёт башню.
 /// </summary>
 /// <param name="unitData">Позиция башни.</param>
 /// <returns>Компонент управления башней.</returns>
 private GameObject CreateTower(ActualDataUnit unitData)
 {
     var towerPosition = new Vector3(unitData.position_y, 0, unitData.position_x);
     var tower = (GameObject)Instantiate(TowerPrefab, towerPosition, Quaternion.identity);
     //SetMinimumHealth(unitData, tower);
     return tower;
 }
 /// <summary>
 /// Создаёт рыцаря.
 /// </summary>
 /// <param name="unitData">Позиция рыцаря.</param>
 /// <returns>Компонент управления рыцарем.</returns>
 private GameObject CreateKnight(ActualDataUnit unitData)
 {
     var knightPosition = new Vector3(unitData.position_y, 0, unitData.position_x);
     var knight = (GameObject)Instantiate(KnightPrefab, knightPosition, Quaternion.identity);
     SetMinimumHealth(unitData, knight);
     knight.GetComponent<KnightScript>().SetNewPosition(knightPosition);
     return knight;
 }
 private static void SetMinimumHealth(ActualDataUnit unitData, GameObject unit)
 {
     var healthComponent = unit.GetComponent<EnemyHealth>();
     healthComponent.MaxHealth = unitData.hit_point;
     healthComponent.SetHealth(unitData.hit_point);
 }
        private static void AdjustUnitData(GameObject unit, ActualDataUnit unitData)
        {
            if (unitData.type_unit == UnitType.Knight)
            {
                var unitPosition = new Vector3(unitData.position_y, 0, unitData.position_x);
                //unit.transform.position = unitPosition;

                var knightScript = unit.GetComponent<KnightScript>();
                knightScript.SetNewPosition(unitPosition);

                float rotationAngle = DirectionAnglesDictionary[unitData.direction];
                unit.transform.eulerAngles = new Vector3(0, rotationAngle, 0);

                var healthScript = unit.GetComponent<EnemyHealth>();
                healthScript.SetHealth(unitData.hit_point);
            }
        }