ConfigValue.cs 776 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using UnityEngine;
  2. using System.Collections;
  3. public class ConfigValue
  4. {
  5. public enum ValueType
  6. {
  7. Constant = 0,
  8. Percentage = 1,
  9. }
  10. private static System.Array valueTypeArr = System.Enum.GetValues(typeof(ValueType));
  11. public static ValueType GetValueTypeByCode(int code)
  12. {
  13. return (ValueType)valueTypeArr.GetValue(code);
  14. }
  15. private float value;
  16. private ValueType valueType;
  17. public ConfigValue(float value, int valueType)
  18. {
  19. this.value = value;
  20. this.valueType = GetValueTypeByCode(valueType);
  21. }
  22. public float GetValue(float origin)
  23. {
  24. if(valueType == ValueType.Constant)
  25. {
  26. return value;
  27. }
  28. else if(valueType == ValueType.Percentage)
  29. {
  30. return value/100f*origin;
  31. }
  32. return 0;
  33. }
  34. public ValueType GetValueType()
  35. {
  36. return valueType;
  37. }
  38. }