RectSlider.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. namespace UnityEditor.U2D.Animation
  3. {
  4. internal class RectSlider
  5. {
  6. private static readonly int kRectSliderHashCode = "RectSlider".GetHashCode();
  7. private Vector2 m_StartPosition = Vector2.zero;
  8. private Vector2 m_Position = Vector2.zero;
  9. internal Rect Do()
  10. {
  11. return Do(GUIUtility.GetControlID(kRectSliderHashCode, FocusType.Passive));
  12. }
  13. internal Rect Do(int controlID)
  14. {
  15. var eventType = Event.current.GetTypeForControl(controlID);
  16. if (eventType == EventType.MouseDown)
  17. {
  18. m_StartPosition = ModuleUtility.GUIToWorld(Event.current.mousePosition);
  19. m_Position = m_StartPosition;
  20. }
  21. if (eventType == EventType.Layout)
  22. HandleUtility.AddDefaultControl(controlID);
  23. m_Position = Slider2D.Do(controlID, m_Position);
  24. var rect = new Rect();
  25. rect.min = m_StartPosition;
  26. rect.max = m_Position;
  27. return rect;
  28. }
  29. }
  30. }