Range.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #if UNITY_EDITOR
  2. using UnityEngine;
  3. using System;
  4. namespace O3DWB
  5. {
  6. [Serializable]
  7. public class Range<DataType> where DataType : struct
  8. {
  9. #region Private Variables
  10. [SerializeField]
  11. private DataType _min;
  12. [SerializeField]
  13. private DataType _max;
  14. #endregion
  15. #region Public Properties
  16. public DataType Min { get { return _min; } set { _min = value; } }
  17. public DataType Max { get { return _max; } set { _max = value; } }
  18. #endregion
  19. #region Constructors
  20. public Range()
  21. {
  22. _min = default(DataType);
  23. _max = _min;
  24. ValidateDataType();
  25. }
  26. public Range(DataType min, DataType max)
  27. {
  28. _min = min;
  29. _max = max;
  30. ValidateDataType();
  31. }
  32. #endregion
  33. #region Private Methods
  34. private void ValidateDataType()
  35. {
  36. if (!typeof(DataType).IsNumeric())
  37. throw new UnityException("Range.ValidateDataType: Only numeric primitive types are allowed.");
  38. }
  39. #endregion
  40. }
  41. }
  42. #endif