示例#1
0
        public void OnDrawGizmos()
        {
            // Only render if set to globally display on all
            // explodables
            if (!_alwaysShowRangeGizmo)
            {
                return;
            }

            Gizmos.matrix = transform.localToWorldMatrix;

            // Render range gizmo
            if (_type == ExplodableType.Sheep)
            {
                DrawRangeGizmo(this);
            }
            else if (_type == ExplodableType.Crate)
            {
                // Render chain reaction range gizmo for hidden sheep
                if (_hiddenSheepPrefab != null)
                {
                    Explodable explodable = _hiddenSheepPrefab.GetComponent <Explodable>();

                    DrawRangeGizmo(explodable);
                }
            }
        }
示例#2
0
        public void OnDrawGizmosSelected()
        {
            if (_alwaysShowRangeGizmo)
            {
                // Don't render range gizmos on select
                // if globally showing range
                return;
            }

            Gizmos.matrix = transform.localToWorldMatrix;

            // Render range gizmo
            if (_type == ExplodableType.Sheep)
            {
                DrawRangeGizmo(this);
            }
            else if (_type == ExplodableType.Crate)
            {
                // Render chain reaction range gizmo for hidden sheep
                if (_hiddenSheepPrefab != null)
                {
                    Explodable explodable = _hiddenSheepPrefab.GetComponent <Explodable>();

                    DrawRangeGizmo(explodable);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Will first raycast for any objects which the player is able to explode
        /// then attempt to trigger them to explode
        /// </summary>
        public void TriggerExplosion(Vector3 a_inputPosition)
        {
            // Only execute this function if this
            // component is enabled
            if (!this.enabled)
            {
                return;
            }

            // Ensure player has enough explosions left
            // to trigger another
            if (explosionCount <= 0)
            {
                Debug.Log("Player is out of explosions");
                return;
            }

            // Log event and draw ray
            Debug.Log("Player is attemtping to explode an object");

            Ray ray = _playerCamera.ScreenPointToRay(a_inputPosition);

            Debug.DrawRay(ray.origin, ray.direction, Color.red, 5.0f);

            // Raycast to object which player may be attempting to explode
            RaycastHit raycastHit;

            if (Physics.Raycast(ray, out raycastHit, _explodableLayers))
            {
                Explodable explodableObject = raycastHit.transform.GetComponent <Explodable>();

                // Ensure object has an explodable script attached
                if (explodableObject == null)
                {
                    Debug.LogWarning(string.Format("Attempted to explode object ({0}) but found no Explodable script attached",
                                                   raycastHit.collider.name));

                    return;
                }

                // Attmept to explode object, and increment
                // explosives count, if exploded
                bool explodedObject = explodableObject.Explode(this.tag);
                if (explodedObject)
                {
                    _currentExplosionsCount++;
                }
            }
        }
示例#4
0
        public void RemoveExplodableReference(ExplodableType a_type, Explodable a_explodable)
        {
            List <Explodable> referenceList = GetList(a_type);

#if UNITY_EDITOR
            // Ensure object is referenced
            if (!_explodables.Contains(a_explodable) ||
                !referenceList.Contains(a_explodable))
            {
                Debug.LogWarning(string.Format("(Scene Manager) Attempted remove to reference '{0}' when not already referenced", a_explodable.name));
                return;
            }
#endif

            referenceList.Remove(a_explodable);
            _explodables.Remove(a_explodable);

            // Raise player win/loss event if objectives are met
            switch (a_type)
            {
            case ExplodableType.Sheep:
                if (_player.explosionCount <= 0 && sheepCount > 0 &&
                    _generators.Count > 0)
                {
                    // HACK: Fixes bug where having no explodables with
                    // an explosions left fails player
                    Invoke("NoExplosionsLeftFailure", 1.0f);
                }
                else if (sheepCount <= 0)
                {
                    RaisePlayerWinEvent(PlayerWinState.AllSheepDestroyed);
                }
                break;

            case ExplodableType.NuclearSheep:
                RaisePlayerLossEvent(PlayerLoseState.DetonatedNukeSheep);
                break;

            case ExplodableType.Crate:
                break;

            case ExplodableType.Generator:
                if (generatorsCount <= 0)
                {
                    RaisePlayerWinEvent(PlayerWinState.AllGeneratersDestroyed);
                }
                break;
            }
        }
示例#5
0
        public void DrawRangeGizmo(Explodable a_explodable)
        {
            Gizmos.color = Color.red;

            // Max range
            float range = a_explodable._chainReactionMaxRange;

            Gizmos.DrawWireSphere(Vector3.zero, range);

            Gizmos.color = Color.green;

            // Min Range
            range = a_explodable._chainReactionMinRange;
            Gizmos.DrawWireSphere(Vector3.zero, range);
        }
示例#6
0
        public void AddExplodableReference(ExplodableType a_type, Explodable a_explodable)
        {
            List <Explodable> referenceList = GetList(a_type);

#if UNITY_EDITOR
            // Ensure object isn't already referenced
            if (_explodables.Contains(a_explodable) ||
                referenceList.Contains(a_explodable))
            {
                Debug.LogWarning(string.Format("(Scene Manager) Attempted to reference '{0}' when already referenced", a_explodable.name));
                return;
            }
#endif

            referenceList.Add(a_explodable);
            _explodables.Add(a_explodable);
        }
示例#7
0
        public void DrawRangeGizmo(Explodable a_explodable)
        {
            Gizmos.color = Color.red;

            // Max range
            float range = a_explodable._chainReactionMaxRange;
            Gizmos.DrawWireSphere(Vector3.zero, range);

            Gizmos.color = Color.green;

            // Min Range
            range = a_explodable._chainReactionMinRange;
            Gizmos.DrawWireSphere(Vector3.zero, range);
        }
示例#8
0
        public void RemoveExplodableReference(ExplodableType a_type, Explodable a_explodable)
        {
            List<Explodable> referenceList = GetList(a_type);

            #if UNITY_EDITOR
            // Ensure object is referenced
            if (!_explodables.Contains(a_explodable) ||
                !referenceList.Contains(a_explodable))
            {
                Debug.LogWarning(string.Format("(Scene Manager) Attempted remove to reference '{0}' when not already referenced", a_explodable.name));
                return;
            }
            #endif

            referenceList.Remove(a_explodable);
            _explodables.Remove(a_explodable);

            // Raise player win/loss event if objectives are met
            switch (a_type)
            {
                case ExplodableType.Sheep:
                    if (_player.explosionCount <= 0 && sheepCount > 0 &&
                        _generators.Count > 0)
                    {
                        // HACK: Fixes bug where having no explodables with
                        // an explosions left fails player
                        Invoke("NoExplosionsLeftFailure", 1.0f);
                    }
                    else if (sheepCount <= 0)
                    {
                        RaisePlayerWinEvent(PlayerWinState.AllSheepDestroyed);
                    }
                    break;

                case ExplodableType.NuclearSheep:
                    RaisePlayerLossEvent(PlayerLoseState.DetonatedNukeSheep);
                    break;

                case ExplodableType.Crate:
                    break;

                case ExplodableType.Generator:
                    if (generatorsCount <= 0)
                    {
                        RaisePlayerWinEvent(PlayerWinState.AllGeneratersDestroyed);
                    }
                    break;
            }
        }
示例#9
0
        public void AddExplodableReference(ExplodableType a_type, Explodable a_explodable)
        {
            List<Explodable> referenceList = GetList(a_type);

            #if UNITY_EDITOR
            // Ensure object isn't already referenced
            if (_explodables.Contains(a_explodable) ||
                referenceList.Contains(a_explodable))
            {
                Debug.LogWarning(string.Format("(Scene Manager) Attempted to reference '{0}' when already referenced", a_explodable.name));
                return;
            }
            #endif

            referenceList.Add(a_explodable);
            _explodables.Add(a_explodable);
        }
示例#10
0
        public void Awake()
        {
            // Cache game object attributes
            _transform  = transform;
            _gameObject = gameObject;

            // Ensure configuration settings are reasonable
            if (_chainReactionMinRange > _chainReactionMaxRange ||
                _chainReactionMaxRange <= 0.0f)
            {
                if (_type == ExplodableType.Sheep)
                {
                    Debug.LogWarning(string.Format("Explodable may not be able to trigger chain reactions ({0})",
                                                   this.name));
                }
            }

            // Ensure explosion particle effect is not null
            if (_explosionPrefab == null)
            {
                Debug.LogError("Explosion prefab not set for: " + this.name);
            }
            else
            {
                _explosionObject = InstantiatePrefab(_explosionPrefab);
            }

            // Ensure crater prefab is not null
            if (_craterPrefab == null &&
                _type != ExplodableType.Crate)
            {
                Debug.LogWarning("Crater reference not set for: " + this.name);
            }
            else if (_craterPrefab != null)
            {
                _craterObject = InstantiatePrefab(_craterPrefab);
            }

            // Ensure model reference is not null
            if (_modelReference == null)
            {
                Debug.LogWarning("Model reference not set for: " + this.name);
            }

            // Ensure hidden sheep prefab is not null
            // if this explodable object is a crate
            if (_hiddenSheepPrefab == null &&
                _type == ExplodableType.Crate)
            {
                Debug.LogWarning("Hidden Sheep reference not set for: " + this.name);
            }
            else if (_type == ExplodableType.Crate)
            {
                // Create hidden sheep object
                _hiddenSheepObject = InstantiatePrefab(_hiddenSheepPrefab);

                // Disable explodable component, to prevent unwanted messages being sent
                Explodable sheepExplodable = _hiddenSheepObject.GetComponent <Explodable>();
                sheepExplodable.enabled = false;

                // Re-enable explodable component
                sheepExplodable.enabled = true;
            }

            // Calculate particle system lifetime
            _particleSystemLifeTime = CalculateParticleSystemLifeTime();

            // Save reference to scene manager
            _sceneManager = FindObjectOfType <SceneManager>();
            if (_sceneManager == null)
            {
                Debug.LogWarning("Unable to find scene manager within scene");
            }

            // Ensure obstruction layer mask is resonable
            if (_type == ExplodableType.Sheep &&
                _obstacleLayerMask == new LayerMask())
            {
                Debug.LogWarning("Obstacle layermask not set for: " + this.name);
            }

            // Get reference to Nuke Failure Effect
            _nukeFailureEffect = FindObjectOfType <NukeFailureEffect>();
            if (_nukeFailureEffect == null)
            {
                Debug.LogWarning("Unable to find Nuke Failure Effect script within the scene, effect will not be triggered");
            }
        }