using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// 数值实例
///
public class ValueInstance {
/// 数值类型
public readonly ValueType type;
/// 数值名称
public readonly string name;
/// 最小值
public float minValue;
/// 最大值
public float maxValue;
/// 基础值
public float baseValue;
/// 附加值%
public float addedValue;
/// 当前值
public float currentValue;
/// 最终数值
public float value;
/// 修改器列表
public List modifiers = new List();
/// 是布尔值
public bool isBoolean => type == ValueType.Boolean && value == maxValue;
public ValueInstance(ValueType type, string name) {
this.type = type;
this.name = name;
if (type == ValueType.Float) { minValue = 0; maxValue = float.MaxValue; }
if (type == ValueType.Integer) { minValue = 0; maxValue = float.MaxValue; }
if (type == ValueType.Boolean) { minValue = 0; maxValue = 1; }
if (type == ValueType.Percentage) { minValue = 0; maxValue = 100; }
}
/// 添加修改器
public void AddModifier(ValueModifier modifier, bool isUpdate) {
modifiers.Add(modifier);
if (isUpdate) { RecalculateValue(); }
}
/// 添加修改器
public void AddModifier(List modifier, bool isUpdate) {
modifiers.AddRange(modifier);
if (isUpdate) { RecalculateValue(); }
}
/// 重新计算值
public void RecalculateValue() {
addedValue = 1;
currentValue = baseValue;
modifiers.ForEach(Modify);
}
/// 修改
public void Modify(ValueModifier modifier) {
addedValue += modifier.AddedValue;
currentValue += modifier.FixedValue;
value = currentValue * addedValue;
value = Mathf.Clamp(currentValue, minValue, maxValue);
}
}