SettingsPresetReceiver.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using UnityEditor;
  2. using UnityEditor.Presets;
  3. using UnityEngine;
  4. namespace HybridCLR.Editor.Settings
  5. {
  6. public class SettingsPresetReceiver : PresetSelectorReceiver
  7. {
  8. private Object m_Target;
  9. private Preset m_InitialValue;
  10. private SettingsProvider m_Provider;
  11. internal void Init(Object target, SettingsProvider provider)
  12. {
  13. m_Target = target;
  14. m_InitialValue = new Preset(target);
  15. m_Provider = provider;
  16. }
  17. public override void OnSelectionChanged(Preset selection)
  18. {
  19. if (selection != null)
  20. {
  21. Undo.RecordObject(m_Target, "Apply Preset " + selection.name);
  22. selection.ApplyTo(m_Target);
  23. }
  24. else
  25. {
  26. Undo.RecordObject(m_Target, "Cancel Preset");
  27. m_InitialValue.ApplyTo(m_Target);
  28. }
  29. m_Provider.Repaint();
  30. }
  31. public override void OnSelectionClosed(Preset selection)
  32. {
  33. OnSelectionChanged(selection);
  34. Object.DestroyImmediate(this);
  35. }
  36. }
  37. }