コード例 #1
0
    void OnDisable()
    {
        // Get the stat with id of RPGStatType.Health of type RPGVital
        RPGVital health;

        if (collection.TryGetStat(RPGStatType.Health, out health))
        {
            // Remove connections to the Health stat's events
            health.RemoveValueListener(OnHealthValueChange);
            health.RemoveCurrentValueListener(OnHealthCurrentValueChange);
        }
    }
コード例 #2
0
    void OnEnable()
    {
        entity     = GetComponent <Entity>();
        collection = GetComponent <RPGStatCollection>();

        // If the collection is not setup, trigger setup
        if (collection.IsCollectionSetup == false)
        {
            collection.SetupCollection();
        }

        // Get the stat with id of RPGStatType.Health of type RPGVital
        RPGVital health;

        if (collection.TryGetStat(RPGStatType.Health, out health))
        {
            // Connect to the Health stat's events
            health.AddValueListener(OnHealthValueChange);
            health.AddCurrentValueListener(OnHealthCurrentValueChange);

            // Add modifier to Health stat, then update stat's modifier value
            health.AddModifier(new RPGStatModBaseAdd(10.5f));
            health.UpdateModifiers();

            // Update the Health stat's current value to max
            health.SetCurrentValueToMax();
        }
    }
コード例 #3
0
ファイル: Entity.cs プロジェクト: jkpenner/RPGStatSystem
    public void OnEnable()
    {
        _statCollection = GetComponent <RPGStatCollection>();
        if (_statCollection != null)
        {
            if (_statCollection.IsCollectionSetup == false)
            {
                _statCollection.SetupCollection();
            }

            if (_statCollection.TryGetStat(_healthType, out _health) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain vital of type {1}",
                                       this.name, _healthType.ToString());
            }

            if (_statCollection.TryGetStat(_healthRegenType, out _healthRegen) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain vital of type {1}",
                                       this.name, _healthRegenType.ToString());
            }

            if (_statCollection.TryGetStat(_energyType, out _energy) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain vital of type {1}",
                                       this.name, _energyType.ToString());
            }

            if (_statCollection.TryGetStat(_energyRegenType, out _energyRegen) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain vital of type {1}",
                                       this.name, _energyRegenType.ToString());
            }

            if (_statCollection.TryGetStat(_manaType, out _mana) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain vital of type {1}",
                                       this.name, _manaType.ToString());
            }

            if (_statCollection.TryGetStat(_manaRegenType, out _manaRegen) == false)
            {
                Debug.LogWarningFormat("[{0}]: Collection does not contain stat of type {1}",
                                       this.name, _manaRegenType.ToString());
            }
        }
    }