/// <summary> /// Destroys the object. /// </summary> /// <param name="hitPosition">The position of the destruction.</param> /// <param name="hitNormal">The normal direction of the destruction.</param> public void Destruct(Vector3 hitPosition, Vector3 hitNormal) { for (int i = 0; i < m_SpawnedObjectsOnDestruction.Length; ++i) { if (m_SpawnedObjectsOnDestruction[i] == null) { continue; } var spawnedObject = m_SpawnedObjectsOnDestruction[i].Instantiate(hitPosition, hitNormal, m_NormalizedGravity); if (spawnedObject == null) { continue; } var explosion = spawnedObject.GetCachedComponent <Explosion>(); if (explosion != null) { explosion.Explode(m_DamageAmount, m_ImpactForce, m_ImpactForceFrames, m_Originator); } } // The component and collider no longer need to be enabled after the object has been destroyed. if (m_Collider != null) { m_Collider.enabled = false; } if (m_ParticleSystem != null) { m_ParticleSystem.Stop(); } m_Destroyed = true; m_DestroyEvent = null; enabled = false; // The destructible should be destroyed. #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (NetworkObjectPool.IsNetworkActive()) { // The object may have already been destroyed over the network. if (!m_GameObject.activeSelf) { return; } NetworkObjectPool.Destroy(m_GameObject); return; } #endif ObjectPoolBase.Destroy(m_GameObject); }
/// <summary> /// Returns the projectile back to the object pool. /// </summary> private void ReturnToObjectPool() { #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (NetworkObjectPool.IsNetworkActive()) { // The object may have already been destroyed over the network. if (!m_GameObject.activeSelf) { return; } NetworkObjectPool.Destroy(m_GameObject); return; } #endif ObjectPool.Destroy(m_GameObject); }
/// <summary> /// The object has been picked up. /// </summary> /// <param name="pickedUpBy">A reference to the object that picked up the object.</param> protected virtual void ObjectPickedUp(GameObject pickedUpBy) { // The object may not have been instantiated within the scene. if (m_GameObject == null) { return; } m_IsDepleted = true; // Send an event notifying of the pickup. EventHandler.ExecuteEvent(pickedUpBy, "OnObjectPickedUp", this); // Optionally play a pickup sound if the object picking up the item is attached to a camera. // A null GameObject indicates that the clip will play from the AudioManager. var camera = Utility.UnityEngineUtility.FindCamera(pickedUpBy); if (camera != null) { m_PickupAudioClipSet.PlayAudioClip(null); } if (ObjectPool.InstantiatedWithPool(m_GameObject)) { #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (NetworkObjectPool.IsNetworkActive()) { NetworkObjectPool.Destroy(m_GameObject); return; } #endif ObjectPool.Destroy(m_GameObject); } else { // Deactivate the pickup for now. It can appear again if a Respawner component is attached to the GameObject. m_GameObject.SetActive(false); } }
/// <summary> /// Returns the GameObject back to the ObjectPool. /// </summary> private void PoolGameObject() { // The particle may be looping so it shouldn't be stopped yet. if (m_ParticleSystem.IsAlive(true)) { m_PoolEvent = Scheduler.Schedule(m_ParticleSystem.main.duration, PoolGameObject); return; } #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (NetworkObjectPool.IsNetworkActive()) { // The object may have already been destroyed over the network. if (!m_GameObject.activeSelf) { return; } NetworkObjectPool.Destroy(m_GameObject); return; } #endif ObjectPool.Destroy(m_GameObject); }
/// <summary> /// Stops the cast. /// </summary> public override void Stop() { if (m_SpawnedObject != null) { #if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER if (NetworkObjectPool.IsNetworkActive()) { // The object may have already been destroyed over the network. if (!m_GameObject.activeSelf) { return; } NetworkObjectPool.Destroy(m_SpawnedObject); return; } #endif ObjectPool.Destroy(m_SpawnedObject); m_SpawnedObject = null; } base.Stop(); }