MaterialDirtyScope.cs 811 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Linq;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Coffee.UIEffects.Editors
  5. {
  6. /// <summary>
  7. /// Changes in this scope cause the graphic's material to be dirty.
  8. /// When you change a property, it marks the material as dirty.
  9. /// </summary>
  10. internal class MaterialDirtyScope : EditorGUI.ChangeCheckScope
  11. {
  12. readonly Object[] targets;
  13. public MaterialDirtyScope(Object[] targets)
  14. {
  15. this.targets = targets;
  16. }
  17. protected override void CloseScope()
  18. {
  19. if (changed)
  20. {
  21. foreach (var effect in targets.OfType<BaseMaterialEffect>())
  22. {
  23. effect.SetMaterialDirty();
  24. }
  25. }
  26. base.CloseScope();
  27. }
  28. }
  29. }