Exemplo n.º 1
0
 public Stat(T value, IComparable min, IComparable max, BoundMode boundMode)
 {
     this.boundMode = boundMode;
     this.min       = min;
     this.max       = max;
     Set(value);
 }
Exemplo n.º 2
0
 public StatNumber(T value, T min, T max, BoundMode boundMode) : base(value, true)
 {
     this.boundMode = boundMode;
     //set min
     this.min = min;
     minSet   = true;
     //set max
     this.max = max;
     maxSet   = true;
     Set(value);
 }
Exemplo n.º 3
0
 public Stat(T value)
 {
     boundMode = BoundMode.Cap;
     Set(value);
 }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GUIStyle bold = new GUIStyle();

            bold.fontStyle = FontStyle.Bold;
            GUIStyle gray = new GUIStyle();

            gray.fontStyle = FontStyle.Italic;

            EditorGUI.BeginChangeCheck();

            StatFloat element = (StatFloat)fieldInfo.GetValue(property.serializedObject.targetObject);
            float     x       = position.x;
            float     y       = position.y;
            float     width   = position.width;

            float     _value     = property.FindPropertyRelative("value").floatValue;
            float     _max       = property.FindPropertyRelative("max").floatValue;
            float     _min       = property.FindPropertyRelative("min").floatValue;
            BoundMode _boundMode = (BoundMode)property.FindPropertyRelative("boundMode").enumValueIndex;


            //Header
            property.isExpanded = EditorGUI.Foldout(new Rect(x, y, width * 0.1f, heightByElement), property.isExpanded, "");
            GUI.color           = new Color(1 * IsPlayingVar(), 1 * IsPlayingVar(), 0.9f * IsPlayingVar());
            float newValue = EditorGUI.DelayedFloatField(new Rect(x, y, width, heightByElement), property.displayName, _value);

            shownElements = 1;

            if (newValue != _value)
            {
                element.Set(newValue, false);
            }

            if (property.isExpanded)
            {
                EditorGUI.indentLevel = 1;
                GUI.color             = new Color(0.9f * IsPlayingVar(), 1 * IsPlayingVar(), 0.9f * IsPlayingVar());

                //Boundaries
                EditorGUI.LabelField(new Rect(x - 10, GetY(y, shownElements), width, heightByElement), "Boundaries", bold);
                shownElements++;

                //Min, Max
                float newMin = EditorGUI.DelayedFloatField(new Rect(x, GetY(y, shownElements), width, heightByElement), "Min", _min);
                shownElements++;
                float newMax = EditorGUI.DelayedFloatField(new Rect(x, GetY(y, shownElements), width, heightByElement), "Max", _max);
                shownElements++;

                if (newMin != _min)
                {
                    element.MIN = newMin;
                }
                if (newMax != _max)
                {
                    element.MAX = newMax;
                }

                GUI.color = StdColor();

                //Enum
                element.boundMode = (BoundMode)EditorGUI.EnumPopup(new Rect(x, GetY(y, shownElements), width, heightByElement), "Bound Mode", _boundMode);
                shownElements++;


                //Buffs
                EditorGUI.LabelField(new Rect(x - 10, GetY(y, shownElements), width, heightByElement), "Buffs", bold);
                shownElements++;

                List <StatFloat.Buff> buffList  = element.Buffs;
                List <string>         buffNames = element.BuffNames;

                int i = 0;
                foreach (StatFloat.Buff buff in buffList)
                {
                    float  locY = GetY(y, shownElements);
                    string text = buffNames[i] + ": " + (buff.value >= 0 ? "+" : "") + buff.value + (buff.type == BuffType.Percent ? "%" : "");
                    EditorGUI.LabelField(new Rect(x + 25, locY, width, heightByElement), text);

                    if (GUI.Button(new Rect(x + 15, locY, 16, heightByElement), "X"))
                    {
                        element.RemoveBuff(buffNames[i]);
                    }

                    shownElements++;
                    i++;
                }
                if (i == 0)
                {
                    EditorGUI.LabelField(new Rect(x + 25, GetY(y, shownElements), width, heightByElement), "- no buffs -", gray);
                    shownElements++;
                }

                EditorGUI.LabelField(new Rect(x, GetY(y, shownElements), width, heightByElement), "New Buff");
                float localX     = x + 105;
                float localWidth = width - 127;
                float eleWidth   = localWidth / 3;
                float padding    = 0;
                float localY     = GetY(y, shownElements);
                newBuffId    = EditorGUI.TextField(new Rect(localX, localY, eleWidth, heightByElement), newBuffId);
                newBuffValue = EditorGUI.FloatField(new Rect(localX + eleWidth + padding, localY, eleWidth, heightByElement), newBuffValue);
                newBuffType  = (BuffType)EditorGUI.EnumPopup(new Rect(localX + eleWidth + eleWidth + padding, localY, eleWidth, heightByElement), newBuffType);

                //GUI.enabled = Application.isPlaying;
                if (GUI.Button(new Rect(x + width - 18, localY - 1, 18, heightByElement + 2), "+", EditorStyles.miniButton))
                {
                    element.AddBuff(newBuffId, newBuffValue, newBuffType);
                    newBuffId    = "id";
                    newBuffValue = 0;
                    newBuffType  = BuffType.Percent;
                }
                shownElements++;
                shownElements++;

                GUI.enabled = true;
            }
            GUI.color = StdColor();

            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.SetIsDifferentCacheDirty();
            }
        }
Exemplo n.º 5
0
 public StatFloat(float value, float min, float max, BoundMode boundMode) : base(value, min, max, boundMode)
 {
 }
Exemplo n.º 6
0
 public StatNumber(T value) : base(value, true)
 {
     boundMode = BoundMode.Cap;
     Set(value);
 }
Exemplo n.º 7
0
 public StatInt(int value, int min, int max, BoundMode boundMode) : base(value, min, max, boundMode)
 {
 }