Beispiel #1
0
        public void UnregisterChildKillable(Killable kill)
        {
            _childKillables.Remove(kill);

            deathDespawnBehavior = DeathDespawnBehavior.Disable;

            if (_childKillables.Count == 0 && invincibleWhileChildrenKillablesExist &&
                disableCollidersWhileChildrenKillablesExist) {
                EnableColliders();
            }

            // Diagnostic code to uncomment if things are going wrong.
            //Debug.Log("REMOVE - children of '" + name + "': " + childKillables.Count);
        }
Beispiel #2
0
        /// <summary>
        /// This method gets called whenever the object is spawned or starts in a Scene (from Awake event)
        /// </summary>
        /// <param name="spawned">True if spawned, false if in the Scene at beginning.</param>
        protected virtual void SpawnedOrAwake(bool spawned = true)
        {
            if (listener != null) {
                listener.Spawned(this);
            }

            KilledBy = null;
            _waitingToDestroy = false;

            _childrenToDestroy.Clear();

            if (parentDestroyedAction != SpawnerDestroyedBehavior.DoNothing && parentKillableForParentDestroyed != null) {
                parentKillableForParentDestroyed.RecordChildToDie(this);
            }

            // anything you want to do each time this is spawned.
            if (_timesRespawned == 0) {
                isVisible = false;
                _becameVisible = false;
            }

            _isDespawning = false;
            _spawnTime = Time.time;
            _isTemporarilyInvincible = false;

            if (respawnType != RespawnType.None && !_spawnLocationSet) {
                _respawnLocation = Trans.position;
                _spawnLocationSet = true;
            }

            // respawning from "respawn" setting.
            if (_timesRespawned > 0) {
                Trans.position = _respawnLocation;
            } else {
                // register child Killables with parent, if any
                var aParent = Trans.parent;
                while (aParent != null) {
                    _parentKillable = aParent.GetComponent<Killable>();
                    if (_parentKillable == null) {
                        aParent = aParent.parent;
                        continue;
                    }

                    _parentKillable.RegisterChildKillable(this);
                    break;
                }
            }

            currentHitPoints = hitPoints.Value;

            _damageTaken = 0;
            _damagePrefabsSpawned = 0;

            if (deathPrefabPoolName != null && deathPrefabSource == WaveSpecifics.SpawnOrigin.PrefabPool) {
                _deathPrefabWavePool = LevelSettings.GetFirstMatchingPrefabPool(deathPrefabPoolName);
                if (_deathPrefabWavePool == null) {
                    LevelSettings.LogIfNew("Death Prefab Pool '" + deathPrefabPoolName + "' not found for Killable '" +
                                           name + "'.");
                }
            }
            if (damagePrefabSpawnMode != DamagePrefabSpawnMode.None && damagePrefabPoolName != null &&
                damagePrefabSource == SpawnSource.PrefabPool) {
                _damagePrefabWavePool = LevelSettings.GetFirstMatchingPrefabPool(damagePrefabPoolName);
                if (_damagePrefabWavePool == null) {
                    LevelSettings.LogIfNew("Damage Prefab Pool '" + _damagePrefabWavePool + "' not found for Killable '" +
                                           name + "'.");
                }
            }

            if (damagePrefabSpawnMode != DamagePrefabSpawnMode.None && damagePrefabSource == SpawnSource.Specific &&
                damagePrefabSpecific == null) {
                LevelSettings.LogIfNew(string.Format("Damage Prefab for '{0}' is not assigned.", Trans.name));
            }

            CheckForValidVariables();

            StopAllCoroutines(); // for respawn purposes.
            StartCoroutine(CoUpdate());

            deathDespawnBehavior = DeathDespawnBehavior.ReturnToPool;

            if (invincibleOnSpawn) {
                TemporaryInvincibility(invincibleTimeSpawn.Value);
            }
        }