PropertyUtils.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. namespace XGame.Framework.Utils
  4. {
  5. /// <summary>
  6. /// 属性设置工具类
  7. /// </summary>
  8. public static class PropertyUtils
  9. {
  10. public static bool SetColor(ref Color currentValue, Color newValue)
  11. {
  12. if (currentValue.r == newValue.r && currentValue.g == newValue.g && currentValue.b == newValue.b && currentValue.a == newValue.a)
  13. return false;
  14. currentValue = newValue;
  15. return true;
  16. }
  17. public static bool SetStruct<T>(ref T currentValue, T newValue) where T : struct
  18. {
  19. if (EqualityComparer<T>.Default.Equals(currentValue, newValue))
  20. return false;
  21. currentValue = newValue;
  22. return true;
  23. }
  24. public static bool SetClass<T>(ref T currentValue, T newValue) where T : class
  25. {
  26. if ((currentValue == null && newValue == null) || (currentValue != null && currentValue.Equals(newValue)))
  27. return false;
  28. currentValue = newValue;
  29. return true;
  30. }
  31. }
  32. }