コード例 #1
0
ファイル: Explodable.cs プロジェクト: Andy260/Sheeplosion
        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");
            }
        }
コード例 #2
0
ファイル: Explodable.cs プロジェクト: Andy260/Sheeplosion
        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");
            }
        }