예제 #1
0
    IEnumerator IncreaseStat(Stat stat)
    {
        PropertyInfo oldProperty     = oldStat.GetType().GetProperty(stat.statType.name);
        PropertyInfo currentProperty = CharacterManager.Get_instance().characterStat.GetType().GetProperty(stat.statType.name);

        int amountOfChange = (int)currentProperty.GetValue(CharacterManager.Get_instance().characterStat) - (int)oldProperty.GetValue(oldStat);
        int normalized     = Mathf.Clamp(amountOfChange, -1, 1);

        string sign  = normalized > 0 ? "+" : "-";
        int    scale = stat.statType.name.StartsWith("raw") ? CharacterStat.MAX_STAT / CharacterStat.MAX_HEALTH : 1;

        for (int i = 0; i <= Mathf.Abs(amountOfChange) && normalized != 0; i++)
        {
            oldProperty.SetValue(oldStat, (int)oldProperty.GetValue(oldStat) + Mathf.Clamp(amountOfChange, -1, 1));
            UpdateGaugeBar(stat, oldStat);
            stat.change.text = sign + (i / scale);

            yield return(new WaitForSeconds(1 / 150f));
        }
    }
예제 #2
0
    public static CharacterStat operator +(CharacterStat param1, CharacterStat param2)
    {
        CharacterStat result = new CharacterStat();

        PropertyInfo[] properties = result.GetType().GetProperties();

        foreach (PropertyInfo property in properties)
        {
            if (property.SetMethod == null || property.Name.StartsWith("raw"))
            {
                continue;
            }

            int sum = (int)property.GetValue(param1) + (int)property.GetValue(param2);

            property.SetValue(result, sum);
        }

        return(result);
    }