UnselectTool.cs 920 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using UnityEngine;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class UnselectTool<T>
  6. {
  7. private Unselector<T> m_Unselector = new Unselector<T>();
  8. public ICacheUndo cacheUndo { get; set; }
  9. public ISelection<T> selection
  10. {
  11. get { return m_Unselector.selection; }
  12. set { m_Unselector.selection = value; }
  13. }
  14. public Action onUnselect = () => {};
  15. public void OnGUI()
  16. {
  17. Debug.Assert(cacheUndo != null);
  18. Debug.Assert(selection != null);
  19. var e = Event.current;
  20. if (selection.Count > 0 && e.type == EventType.MouseDown && e.button == 1 && !e.alt)
  21. {
  22. cacheUndo.BeginUndoOperation(TextContent.clearSelection);
  23. m_Unselector.Select();
  24. e.Use();
  25. onUnselect.Invoke();
  26. }
  27. }
  28. }
  29. }