SetPropertyUtility.cs 1.1 KB

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