// ----------------------------------------------------------------------------------------------------
        #endregion

        #region Initialization
        // ----------------------------------------------------------------------------------------------------
        /// <summary>
        /// Called upon awaking this behavior.
        /// </summary>
        private void Awake()
        {
            this.movementController  = this.GetComponent <MovementController>();
            this.collisionController = this.GetComponent <ActorCollisionController>();

            this.hasGravitationalObject = false;

            this.collisionController.OnTriggerCollision += (collision) => {
                var collisionGravity = collision.GetComponent <CollisionGravity>();
                if (collisionGravity != null)
                {
                    this.gravitationalObject    = collisionGravity;
                    this.gravicationalTransform = collisionGravity.transform;
                    this.hasGravitationalObject = collisionGravity.IsActive;
                }
            };

            this.collisionController.OnTriggerCollisionExit += (collision) => {
                if (this.hasGravitationalObject)
                {
                    var collisionGravity = collision.GetComponent <CollisionGravity>();
                    if (this.gravitationalObject == collisionGravity)
                    {
                        this.gravitationalObject    = null;
                        this.gravicationalTransform = null;
                        this.hasGravitationalObject = false;
                    }
                }
            };
        }
Example #2
0
        // ----------------------------------------------------------------------------------------------------
        #endregion

        #region Initialization
        // ----------------------------------------------------------------------------------------------------
        /// <summary>
        /// Called upon awaking this behavior.
        /// </summary>
        private void Awake()
        {
            this.triggerEventGroup = new TriggerEventGroup(triggerEvents);

            this.interactionTarget = this.GetComponent <InteractionTarget>();
            this.cameraShakeEffect = this.GetComponent <CameraShakeEffect>();
            this.highlightMaterial = this.GetComponent <HighlightMaterialController>();
            this.collisionGravity  = this.GetComponent <CollisionGravity>();

            this.interactionTarget.OnInteraction += (playerController) => {
                var playerStateController = playerController.StateController;
                if (CollisionUtils.IsObjectInsideTile(transform.position, playerStateController.transform.position))
                {
                    this.Toggle();
                }
            };

            this.OnStatusChanged += (toggleSwitch) => {
                if (toggleSwitch.isActivated)
                {
                    this.triggerEventGroup.Invoke();
                }
                else
                {
                    this.triggerEventGroup.Reset();
                }
            };

            this.SetActive(this.activatedByDefault, true);
        }
 /// <summary>
 /// Resets the state.
 /// </summary>
 public void ResetState()
 {
     this.gravitationalObject    = null;
     this.hasGravitationalObject = false;
 }