File size: 3,499 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | using UnityEngine;
namespace UnityEditor.Timeline
{
abstract class Manipulator
{
int m_Id;
protected virtual bool MouseDown(Event evt, WindowState state) { return false; }
protected virtual bool MouseDrag(Event evt, WindowState state) { return false; }
protected virtual bool MouseWheel(Event evt, WindowState state) { return false; }
protected virtual bool MouseUp(Event evt, WindowState state) { return false; }
protected virtual bool DoubleClick(Event evt, WindowState state) { return false; }
protected virtual bool KeyDown(Event evt, WindowState state) { return false; }
protected virtual bool KeyUp(Event evt, WindowState state) { return false; }
protected virtual bool ContextClick(Event evt, WindowState state) { return false; }
protected virtual bool ValidateCommand(Event evt, WindowState state) { return false; }
protected virtual bool ExecuteCommand(Event evt, WindowState state) { return false; }
public virtual void Overlay(Event evt, WindowState state) { }
public bool HandleEvent(WindowState state)
{
Event currentEvent = Event.current;
var type = currentEvent.GetTypeForControl(m_Id);
return HandleEvent(type, currentEvent, state);
}
public bool HandleEvent(EventType type, WindowState state)
{
Event currentEvent = Event.current;
return HandleEvent(type, currentEvent, state);
}
bool HandleEvent(EventType type, Event evt, WindowState state)
{
if (m_Id == 0)
m_Id = GUIUtility.GetPermanentControlID();
bool isHandled = false;
switch (type)
{
case EventType.ScrollWheel:
isHandled = MouseWheel(evt, state);
break;
case EventType.MouseUp:
{
if (GUIUtility.hotControl == m_Id)
{
isHandled = MouseUp(evt, state);
GUIUtility.hotControl = 0;
evt.Use();
}
}
break;
case EventType.MouseDown:
{
isHandled = evt.clickCount < 2 ? MouseDown(evt, state) : DoubleClick(evt, state);
if (isHandled)
GUIUtility.hotControl = m_Id;
}
break;
case EventType.MouseDrag:
{
if (GUIUtility.hotControl == m_Id)
isHandled = MouseDrag(evt, state);
}
break;
case EventType.KeyDown:
isHandled = KeyDown(evt, state);
break;
case EventType.KeyUp:
isHandled = KeyUp(evt, state);
break;
case EventType.ContextClick:
isHandled = ContextClick(evt, state);
break;
case EventType.ValidateCommand:
isHandled = ValidateCommand(evt, state);
break;
case EventType.ExecuteCommand:
isHandled = ExecuteCommand(evt, state);
break;
}
if (isHandled)
evt.Use();
return isHandled;
}
}
}
|