SCSetPropertyUtility.cs 1.0 KB

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