Ejemplo n.º 1
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 + ")");
            }
        }
    }
Ejemplo n.º 2
0
 void _playerController_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
 {
     if (e.currentPlatform == this.gameObject)
     {
         _isGrounded = true;
     }
     else
     {
         _isGrounded = false;
     }
 }
Ejemplo n.º 3
0
 void player_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
 {
     if (e.currentPlatform != _gameObject)
     {
         return; // we need to check that the player landed on this platform
     }
     if (!_isMoving && movingPlatformType == MovingPlatformType.StartsWhenPlayerLands)
     {
         Logger.Info("Player landed on platform, start move...");
         StartMove();
     }
 }
Ejemplo n.º 4
0
    void player_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
    {
        if (!_gameObjectTrackingInformation.Exists(c => c.gameObject == e.currentPlatform))
        {
            return;
        }

        if (!_isMoving && movingPlatformType == MovingPlatformType.StartsWhenPlayerLands)
        {
            Logger.Info("Player landed on platform, start move...");
            _isMoving      = true;
            _moveStartTime = Time.time + startDelayOnEnabled;

            for (int i = 0; i < _synchronizedStartObjects.Length; i++)
            {
                _synchronizedStartObjects[i].StartMove();
            }
        }
    }
    void _playerController_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
    {
        if (e.previousPlatform == this.gameObject && _playerController.transform.parent == this.gameObject.transform)
        {
            _playerController.transform.parent = null;
            var handler = this.Detached;
            if (handler != null)
            {
                handler.Invoke(this, this.gameObject);
            }
            Logger.Info("Removed parent (" + this.gameObject.name + " [ " + this.GetHashCode() + " ]) relationship from child (" + _playerController.name + ") [1]");
        }
        else
        {
            if (e.currentPlatform == this.gameObject && _playerController.transform.parent != this.gameObject.transform)
            {
                if (_playerController.transform.parent != null)
                {
                    _playerController.transform.parent = null;
                    Logger.Info("Removed parent (" + this.gameObject.name + " [ " + this.GetHashCode() + " ]) relationship from child (" + _playerController.name + ") [2]");
                }
                _playerController.transform.parent = this.gameObject.transform;
                Logger.Info("Added parent (" + this.gameObject.name + " [ " + this.GetHashCode() + " ]) relationship to child (" + _playerController.name + ")");

                var handler = OnPlayerControllerGotGrounded;
                if (handler != null)
                {
                    handler.Invoke();
                }

                var handler2 = this.Attached;
                if (handler2 != null)
                {
                    handler2.Invoke(this, this.gameObject);
                }
            }
        }
    }
Ejemplo n.º 6
0
    void _playerController_DisappearWhenLostGround_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
    {
        if (e.currentPlatform == null)
        {// lost ground
            if (_hasLandedOnPlatform)
            {
                if (_isOnPlatform)
                {
                    switch (jumpControlledDisappearingPlatformMode)
                    {
                    case JumpControlledDisappearingPlatformMode.DisappearWhenLostGround:
                        if (_currentPlatforms.Count >= totalVisiblePlatforms)
                        {
                            GameObject platformToRemove = _currentPlatforms.Dequeue();
                            StartCoroutine(FadeOutPlatform(platformToRemove, .2f));
                        }
                        break;
                    }
                }
            }

            _isOnPlatform    = false;
            _currentPlatform = null;
        }
        else
        {
            if (e.currentPlatform != _currentPlatform)
            {
                if (_currentPlatforms.Contains(e.currentPlatform))
                {
                    _currentPlatform = e.currentPlatform;

                    _hasLandedOnPlatform = true;
                    _isOnPlatform        = true;

                    if (e.currentPlatform.transform.position == _worldSpacePlatformCoordinates[_currentIndex])
                    {
                        // we are on last platform. Make sure we have the correct count
                        while (_currentPlatforms.Count >= totalVisiblePlatforms)
                        {
                            GameObject platformToRemove = _currentPlatforms.Dequeue();
                            StartCoroutine(FadeOutPlatform(platformToRemove, .2f));
                        }

                        while (_currentPlatforms.Count < totalVisiblePlatforms)
                        {
                            _currentIndex++;
                            if (_currentIndex >= _worldSpacePlatformCoordinates.Count)
                            {
                                _currentIndex = 0;
                            }

                            GameObject platform = _objectPoolingManager.GetObject(platformPrefab.name, _worldSpacePlatformCoordinates[_currentIndex]);
                            _currentPlatforms.Enqueue(platform);
                        }
                    }
                }
                else
                {
                    _currentPlatform = null;
                }
            }
        }
    }
Ejemplo n.º 7
0
    void _playerController_DisappearWhenLandingOnNextPlatform_OnGroundedPlatformChanged(object sender, PlayerController.GroundedPlatformChangedEventArgs e)
    {
        if (_currentPlatforms.Contains(e.currentPlatform))
        {
            if (e.currentPlatform.transform.position == _worldSpacePlatformCoordinates[_currentIndex])
            {
                // we are on last platform
                while (_currentPlatforms.Count < totalVisiblePlatforms + 1)
                {
                    _currentIndex++;
                    if (_currentIndex >= _worldSpacePlatformCoordinates.Count)
                    {
                        _currentIndex = 0;
                    }

                    GameObject platform = _objectPoolingManager.GetObject(platformPrefab.name, _worldSpacePlatformCoordinates[_currentIndex]);
                    _currentPlatforms.Enqueue(platform);
                }

                GameObject platformToRemove = _currentPlatforms.Dequeue();
                ObjectPoolingManager.Instance.Deactivate(platformToRemove); // TODO (Roman): notify and run fade animation
            }
        }
    }