Exemple #1
0
    void Update()
    {
        if (!_hasReachedUpMoveApex &&
            _isGoingUp &&
            _lastPosition.y > _gameObject.transform.position.y)
        {// we assume there is a bounce out animation, so we want to find out when the up move has reached the apex before bouncing around a bit and getting settled
            _hasReachedUpMoveApex = true;
        }

        if (_isPlayerControllerAttached &&
            !_hasBounced &&
            _hasReachedUpMoveApex
            )
        {
            if (_trampolineBounceControlHandler != null)
            {
                _playerController.RemoveControlHandler(_trampolineBounceControlHandler);
                _trampolineBounceControlHandler = null;
            }

            _playerController.PushControlHandler(new TrampolineAutoBounceControlHandler(_playerController, autoBounceFixedJumpHeight));
            _hasBounced = true;
        }

        _lastPosition = _gameObject.transform.position;
    }
Exemple #2
0
    void _playerController_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
    {
        if ((e.currentPlatform == null && _playerController.transform.parent == this._gameObject.transform) || // either player is in air
            e.previousPlatform == this._gameObject // or the previous platform was the trampoline
            )
        {
            // lost ground
            _isPlayerControllerAttached        = false;
            _playerController.transform.parent = null;

            if (_trampolineBounceControlHandler != null &&
                !_trampolineBounceControlHandler.HasJumped) // we check this in case the player has slid off thr trampoline before being able to jump
            {
                _playerController.RemoveControlHandler(_trampolineBounceControlHandler);
                _trampolineBounceControlHandler = null;
            }

            var handler = this.Detached;
            if (handler != null)
            {
                handler.Invoke(this, this.gameObject);
            }

            Logger.Info("Removed parent (" + this.gameObject.transform + ") relationship from child (" + _playerController.name + ")");
        }
        else if (e.currentPlatform == this._gameObject)
        {
            if (_playerController.transform.parent != this._gameObject.transform)
            {
                _isGoingUp            = false;
                _hasBounced           = false;
                _hasReachedUpMoveApex = false;

                _isPlayerControllerAttached = true;

                _playerController.transform.parent = this._gameObject.transform;

                _trampolineBounceControlHandler = new TrampolineBounceControlHandler(_playerController, -1f, fixedJumpHeight, onTrampolineSkidDamping, canJump);
                _playerController.PushControlHandler(_trampolineBounceControlHandler);

                iTween.MoveBy(this._gameObject
                              , iTween.Hash(
                                  "y", platformDownwardDistance
                                  , "time", platformDownwardDuration
                                  , "easetype", platformDownwardEaseType
                                  , "oncomplete", "OnDownMoveComplete"
                                  , "oncompletetarget", this.gameObject
                                  ));

                var handler = this.Attached;
                if (handler != null)
                {
                    handler.Invoke(this, this.gameObject);
                }

                Logger.Info("Added parent (" + this.gameObject.transform + ") relationship to child (" + _playerController.name + ")");
            }
        }
    }