Exemplo n.º 1
0
    //=====================================================

    public void OnPlayerGemsEvent(int currentGems)
    {
        var location = GameManager.Instance.CurrentLocation;

        // Only update running gems total outwith puzzle room areas - otherwise, updates are via SceneManager (local data)
        // Puzzle Room enums range from 0+ (eLocation.PUZZLE_ROOM_01 == 0)
        if (location != eLocation.NULL && (int)location < (int)eLocation.NUM_PUZZLE_LOCATIONS)
        {
            // Do nothing
        }
        else
        {
            switch (location)
            {
            case eLocation.MAIN_HALL:
                // Work around to force SceneManager to update gui-gem count with GameDataManager + SceneManager gems
                SceneManager.AddPlayerGems(0);
                break;

            default:
                TxtGems = currentGems.ToString();
                break;
            }
        }
    }
Exemplo n.º 2
0
    //=====================================================

    private void ChangeState(eState state)
    {
        CheckReferences();

        _state = state;

        switch (_type)
        {
        case eCollectable.GEM:
            switch (_state)
            {
            case eState.ACTIVE:
                _collectable.gameObject.SetActive(true);
                StartCoroutine(DelayedSpinCollectable());
                break;

            case eState.COLLECTED:
                _collectable.gameObject.SetActive(false);
                _shadow.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();
                _audioSource.Play();

                // Update SceneManager's temp data with collected gems
                SceneManager.AddPlayerGems(1);

                // Update GameDataManager's player data with health
                GameDataManager.Instance.AddPlayerHealth(Convert.ToInt32(SettingsManager.GetSettingsItem("HEALTH_PACK_SMALL", -1)));

                // Destroy
                StartCoroutine(DestroyCollectable());
                break;

            case eState.LOCKED:
                _collectable.gameObject.SetActive(true);
                break;

            case eState.EATEN:
                // Used by GemManager in Boss Room
                if (ConsumedEvent != null)
                {
                    ConsumedEvent(_gridIndex);
                }

                _collectable.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();

                // Destroy
                StartCoroutine(DestroyCollectable());
                break;
            }
            break;

        case eCollectable.RED_GEM:
            switch (_state)
            {
            case eState.ACTIVE:
                _collectable.gameObject.SetActive(true);
                StartCoroutine(DelayedSpinCollectable());
                break;

            case eState.COLLECTED:
                _collectable.gameObject.SetActive(false);
                _shadow.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();
                _audioSource.Play();

                // Update SceneManager's temp data with collected gems
                SceneManager.AddPlayerRedGems(1);

                // Update GameDataManager's player data with health
                GameDataManager.Instance.AddPlayerHealth(Convert.ToInt32(SettingsManager.GetSettingsItem("HEALTH_PACK_SMALL", -1)));

                // Destroy
                StartCoroutine(DestroyCollectable());
                break;

            case eState.LOCKED:
                _collectable.gameObject.SetActive(true);
                break;

            case eState.EATEN:
                _collectable.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();

                // Destroy
                StartCoroutine(DestroyCollectable());
                break;
            }
            break;

        case eCollectable.KEY:
            switch (_state)
            {
            case eState.ACTIVE:
                _collectable.gameObject.SetActive(true);
                _shadow.gameObject.SetActive(true);

                // Switch material if key has already been collected
                if (GameDataManager.Instance.PlayerKeyIsOwned(GameManager.Instance.CurrentLocation, _keyId))
                {
                    var materials = _collectable.GetComponentInChildren <MeshRenderer>().materials;
                    materials[0] = _matKeyIsCollected;
                    _collectable.GetComponentInChildren <MeshRenderer>().materials = materials;
                }

                StartCoroutine(DelayedSpinCollectable());
                break;

            case eState.COLLECTED:
                _collectable.gameObject.SetActive(false);
                _shadow.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();
                _audioSource.Play();

                // Keys are stored directly in GameDataManager
                // If new key, trigger GameManager to play cutscene then boot player from puzzle-room
                if (GameDataManager.Instance.AddPlayerKey(GameManager.Instance.CurrentLocation, _keyId) == true)
                {
                    GameManager.Instance.OnKeyCollected(this, _keyId);
                    // Note: Don't destroy key's because we need to show a popup and then show a cutscene
                }
                else
                {
                    // Player already has key so no cutscene and ok to destroy
                    StartCoroutine(DestroyCollectable());
                }
                break;

            case eState.LOCKED:
                _collectable.gameObject.SetActive(false);
                _shadow.gameObject.SetActive(false);
                break;
            }
            break;

        case eCollectable.HEALTH_GEM:
            switch (_state)
            {
            case eState.ACTIVE:
            case eState.LOCKED:
                _collectable.gameObject.SetActive(true);
                StartCoroutine(DelayedSpinCollectable());
                break;

            case eState.COLLECTED:
                _collectable.gameObject.SetActive(false);
                _shadow.gameObject.SetActive(false);
                _particleSystem.enableEmission = true;
                _particleSystem.Play();
                _audioSource.Play();

                // Update GameDataManager's player data with health
                GameDataManager.Instance.AddPlayerHealth(Convert.ToInt32(SettingsManager.GetSettingsItem("HEALTH_PACK_MEDIUM", -1)));

                // Destroy
                StartCoroutine(DestroyCollectable());
                break;

                //case eState.EATEN:
                //	_collectable.gameObject.SetActive( false );

                //	// Destroy
                //	StartCoroutine( DestroyCollectable() );
                //	break;
            }
            break;
        }
    }