Esempio n. 1
0
    void OnDisappearWhenLandingOnNextPlatform(GroundedPlatformChangedInfo GroundedPlatformChangedInfo)
    {
        if (_currentPlatforms.Contains(GroundedPlatformChangedInfo.CurrentPlatform))
        {
            var isLastPlatform =
                GroundedPlatformChangedInfo.CurrentPlatform.transform.position == _worldSpacePlatformCoordinates[_currentIndex];

            if (isLastPlatform)
            {
                // we are on last platform
                while (_currentPlatforms.Count < TotalVisiblePlatforms + 1)
                {
                    _currentIndex++;

                    if (_currentIndex >= _worldSpacePlatformCoordinates.Count)
                    {
                        _currentIndex = 0;
                    }

                    var platform = _objectPoolingManager.GetObject(
                        PlatformPrefab.name,
                        _worldSpacePlatformCoordinates[_currentIndex]);

                    _currentPlatforms.Enqueue(platform);
                }

                var platformToRemove = _currentPlatforms.Dequeue();

                ObjectPoolingManager.Instance.Deactivate(platformToRemove); // TODO (Roman): notify and run fade animation
            }
        }
    }
Esempio n. 2
0
 void OnPlayerGroundedPlatformChanged(GroundedPlatformChangedInfo e)
 {
     if (e.CurrentPlatform == gameObject)
     {
         _isGrounded = true;
     }
     else
     {
         _isGrounded = false;
     }
 }
Esempio n. 3
0
    void OnPlayerGroundedPlatformChanged(GroundedPlatformChangedInfo 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...");

            _isMoving = true;
        }
    }
    void OnPlayerGroundedPlatformChanged(GroundedPlatformChangedInfo e)
    {
        if (e.PreviousPlatform == gameObject &&
            _playerController.transform.parent == gameObject.transform)
        {
            _playerController.transform.parent = null;

            var handler = Detached;

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

            Logger.Info("Removed parent (" + gameObject.name + " [ " + GetHashCode() + " ]) relationship from child (" + _playerController.name + ") [1]");
        }
        else
        {
            if (e.CurrentPlatform == gameObject &&
                _playerController.transform.parent != gameObject.transform)
            {
                if (_playerController.transform.parent != null)
                {
                    _playerController.transform.parent = null;

                    Logger.Info("Removed parent (" + gameObject.name + " [ " + GetHashCode() + " ]) relationship from child (" + _playerController.name + ") [2]");
                }

                _playerController.transform.parent = gameObject.transform;

                Logger.Info("Added parent (" + gameObject.name + " [ " + GetHashCode() + " ]) relationship to child (" + _playerController.name + ")");

                var playerControllerGotGroundedHandler = PlayerControllerGotGrounded;

                if (playerControllerGotGroundedHandler != null)
                {
                    playerControllerGotGroundedHandler.Invoke();
                }

                var attachedHandler = Attached;

                if (attachedHandler != null)
                {
                    attachedHandler.Invoke(this, gameObject);
                }
            }
        }
    }
Esempio n. 5
0
    void OnPlayerGroundedPlatformChanged(GroundedPlatformChangedInfo 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 (var i = 0; i < _synchronizedStartObjects.Length; i++)
            {
                _synchronizedStartObjects[i].StartMove();
            }
        }
    }
Esempio n. 6
0
    void OnDisappearWhenLostGround(GroundedPlatformChangedInfo groundedPlatformChangedInfo)
    {
        var lostGround = groundedPlatformChangedInfo.CurrentPlatform == null;

        if (lostGround)
        {
            if (_hasLandedOnPlatform)
            {
                if (_isOnPlatform)
                {
                    if (PlatformMode == JumpControlledDisappearingPlatformMode.DisappearWhenLostGround)
                    {
                        if (_currentPlatforms.Count >= TotalVisiblePlatforms)
                        {
                            GameObject platformToRemove = _currentPlatforms.Dequeue();
                            StartCoroutine(FadeOutPlatform(platformToRemove, .2f));
                        }
                    }
                }
            }

            _isOnPlatform = false;

            _currentPlatform = null;
        }
        else
        {
            if (groundedPlatformChangedInfo.CurrentPlatform != _currentPlatform)
            {
                if (_currentPlatforms.Contains(groundedPlatformChangedInfo.CurrentPlatform))
                {
                    _currentPlatform = groundedPlatformChangedInfo.CurrentPlatform;

                    _hasLandedOnPlatform = true;

                    _isOnPlatform = true;

                    if (groundedPlatformChangedInfo.CurrentPlatform.transform.position == _worldSpacePlatformCoordinates[_currentIndex])
                    {
                        // we are on last platform. Make sure we have the correct count

                        while (_currentPlatforms.Count >= TotalVisiblePlatforms)
                        {
                            var platformToRemove = _currentPlatforms.Dequeue();

                            StartCoroutine(FadeOutPlatform(platformToRemove, .2f));
                        }

                        while (_currentPlatforms.Count < TotalVisiblePlatforms)
                        {
                            _currentIndex++;

                            if (_currentIndex >= _worldSpacePlatformCoordinates.Count)
                            {
                                _currentIndex = 0;
                            }

                            var platform = _objectPoolingManager.GetObject(
                                PlatformPrefab.name,
                                _worldSpacePlatformCoordinates[_currentIndex]);

                            _currentPlatforms.Enqueue(platform);
                        }
                    }
                }
                else
                {
                    _currentPlatform = null;
                }
            }
        }
    }
Esempio n. 7
0
    void OnPlayerGroundedPlatformChanged(GroundedPlatformChangedInfo e)
    {
        var lostGround =
            ( // either player is in air
                e.CurrentPlatform == null &&
                _playerController.transform.parent == _gameObject.transform
            ) ||
            e.PreviousPlatform == _gameObject; // or the previous platform was the trampoline

        if (lostGround)
        {
            // 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 = Detached;

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

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

                _hasBounced = false;

                _hasReachedUpMoveApex = false;

                _isPlayerControllerAttached = true;

                _playerController.transform.parent = _gameObject.transform;

                _trampolineBounceControlHandler = new TrampolineBounceControlHandler(
                    _playerController,
                    -1f,
                    FixedJumpHeight,
                    OnTrampolineSkidDamping,
                    CanJump);

                _playerController.PushControlHandler(_trampolineBounceControlHandler);

                iTween.MoveBy(
                    _gameObject,
                    iTween.Hash(
                        "y", PlatformDownwardDistance,
                        "time", PlatformDownwardDuration,
                        "easetype", PlatformDownwardEaseType,
                        "oncomplete", "OnDownMoveComplete",
                        "oncompletetarget", gameObject));

                var handler = Attached;

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

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