public HitData(BattleUnit unitSource, WeaponBase weaponSource, int damage)
 {
     this.unitSource   = unitSource;
     this.weaponSource = weaponSource;
     this.damage       = damage;
 }
Esempio n. 2
0
 private void RespawnUnit(BattleUnit initiator, UnitSpawnData spawnData)
 {
     Spawn(spawnData.OriginalPrefab, spawnData);
     Destroy(initiator.gameObject);
 }
Esempio n. 3
0
        public void Spawn(BattleUnit unitPrefab, UnitSpawnData?spawnData = null)
        {
            Transform spawnPoint    = null;
            Vector3   spawnPosition = Vector3.zero;

            if (spawnData.HasValue)
            {
                spawnPoint    = spawnData.Value.SpawnPoint;
                spawnPosition = spawnPoint.position;
            }
            else
            {
                if (_isExcludeSpawnPoints)
                {
                    if (_spawnPointList != null && !_spawnPointList.Any())
                    {
                        _spawnPointList = null;
                    }

                    if (_spawnPointList == null)
                    {
                        var pointsCopy = _spawnPoints.ToList();
                        pointsCopy.Shuffle();
                        _spawnPointList = new LinkedList <SpawnPoint>(pointsCopy);
                    }

                    var randomPoint = _spawnPointList.LastOrDefault();

                    Assert.IsNotNull(randomPoint, "randomPoint != null");
                    spawnPosition = randomPoint.transform.position;
                    spawnPoint    = randomPoint.transform;
                    _spawnPointList.Remove(randomPoint);
                }
                else
                {
                    spawnPoint    = _spawnPoints[Random.Range(0, _spawnPoints.Length)].transform;
                    spawnPosition = spawnPoint.position;
                }
            }


            var unitInstance = Instantiate(unitPrefab);

            unitInstance.transform.position = spawnPosition;

            var respawnableUnit = unitInstance.GetComponentInChildren <IRespawnableUnit>(true);

            if (respawnableUnit != null)
            {
                if (spawnData.HasValue)
                {
                    respawnableUnit.InitRespawnBehaviour(spawnData.Value);

                    unitInstance.TeamController.SetTeam(spawnData.Value.TeamType);
                }
                else
                {
                    respawnableUnit.InitRespawnBehaviour(new UnitSpawnData(
                                                             unitPrefab, this, spawnPoint, TeamType.TEAM_1
                                                             ));
                }
            }

            var setupableComponents = unitInstance.GetComponentsInChildren <ISetupable>(true);

            foreach (var setupable in setupableComponents)
            {
                if (setupable != null)
                {
                    setupable.Setup();
                }
            }

            InitUnit(unitInstance);

            OnSpawned?.Invoke(unitInstance);
        }
Esempio n. 4
0
        private IEnumerator RespawnUnitByTime(BattleUnit initiator, UnitSpawnData spawnData, float time)
        {
            yield return(new WaitForSeconds(time));

            RespawnUnit(initiator, spawnData);
        }