Exemple #1
0
        private void OnInteractableUsed(object sender, InteractableUsedEventArgs args)
        {
            if (this.currentObjective == null)
            {
                return;
            }

            if (args.Consumed)
            {
                return;
            }

            if (this.LevelSettings.Obstacles.Any(o => o.Obstacle == args.GameObject))
            {
                return;
            }

            if (this.remainingObstacles > 0)
            {
                this.EventManager.OnError(this, new ErrorEventArgs { ErrorMessage = "You need to remove all obstacles first!" });
                Debug.Log(string.Format("Objective blocked by {0} obstacles.", this.remainingObstacles));
                return;
            }

            if (this.currentObjective.GameObject == args.GameObject)
            {
                // Finish objective.
                this.SetObjectiveState(this.currentObjective, ObjectiveState.Complete);

                // Play effects.
                this.PlayInteractionEffects(this.currentObjective.GameObject);

                // Prevent further interaction.
                var interactableComponent = this.currentObjective.GameObject.GetComponent<InteractableComponent>();
                interactableComponent.Enabled = false;

                // Select next objective.
                var nextObjective = this.objectives.FirstOrDefault(obj => obj.State != ObjectiveState.Complete);

                if (nextObjective != null)
                {
                    this.SetObjectiveState(nextObjective, ObjectiveState.Active);
                }
                else
                {
                    this.SetCurrentObjective(null);
                }
            }
            else
            {
                this.EventManager.OnError(this, new ErrorEventArgs { ErrorMessage = "You need to complete objectives in order!" });
            }
        }
Exemple #2
0
        private void OnInteractableUsed(object sender, InteractableUsedEventArgs args)
        {
            var destructibleComponent = args.GameObject.GetComponent<DestructibleComponent>();

            if (destructibleComponent == null)
            {
                return;
            }

            for (var i = 0; i < destructibleComponent.transform.childCount; ++i)
            {
                var child = destructibleComponent.transform.GetChild(i);
                var rigidBody = child.GetComponent<Rigidbody>();

                if (rigidBody == null)
                {
                    rigidBody = child.gameObject.AddComponent<Rigidbody>();
                    rigidBody.AddExplosionForce(
                        this.LevelSettings.DestructionForce,
                        this.transform.position,
                        this.LevelSettings.DestructionRadius);
                }
            }
        }
Exemple #3
0
        private void OnInteractableUsed(object sender, InteractableUsedEventArgs args)
        {
            var obstacle = this.obstacles.FirstOrDefault(o => o.Data.Obstacle == args.GameObject);

            if (obstacle == null)
            {
                return;
            }

            // Remove obstacle.
            obstacle.Removed = true;

            var i = obstacle.Data.Obstacle.GetComponent<InteractableComponent>();
            if (i != null)
            {
                i.Enabled = false;
            }

            Object.Destroy(obstacle.Data.Obstacle);

            Debug.Log(string.Format("Obstacle removed: {0}", obstacle.Data.Obstacle.name));

            // Notify listeners.
            this.EventManager.OnObstaclesChanged(
                this,
                new ObstaclesChangedEventArgs
                {
                    Objective = this.currentObjective,
                    Obstacles = this.CountCurrentObstacles()
                });
        }
Exemple #4
0
 public void OnInteractableUsed(object sender, InteractableUsedEventArgs args)
 {
     var handler = this.InteractableUsed;
     if (handler != null)
     {
         handler(sender, args);
     }
 }