Browse Source

Added EventWindow class

master
Zach Vinless 8 years ago
parent
commit
5f0e58194a
  1. 76
      Assets/Fungus/Scripts/Editor/EventWindow.cs
  2. 12
      Assets/Fungus/Scripts/Editor/EventWindow.cs.meta

76
Assets/Fungus/Scripts/Editor/EventWindow.cs

@ -0,0 +1,76 @@
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
// Adapted from: https://github.com/thecodejunkie/unity.resources/blob/master/scripts/editor/ExtendedEditorWindow.cs
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
namespace Fungus.EditorUtils
{
internal static class MouseButton
{
public const int Left = 0;
public const int Right = 1;
public const int Middle = 2;
}
public class EventWindow : EditorWindow
{
protected delegate void EventAction(Event e);
protected Dictionary<EventType, EventAction> eventTable;
protected Dictionary<EventType, EventAction> rawEventTable;
public EventWindow()
{
eventTable = new Dictionary<EventType, EventAction> {
{ EventType.MouseDown, e => OnMouseDown(e) },
{ EventType.MouseUp, e => OnMouseUp(e) },
{ EventType.MouseDrag, e => OnMouseDrag(e) },
{ EventType.MouseMove, e => OnMouseMove(e) },
{ EventType.ScrollWheel, e => OnScrollWheel(e) },
{ EventType.ContextClick, e => OnContextClick(e) },
{ EventType.KeyDown, e => OnKeyDown(e) },
{ EventType.KeyUp, e => OnKeyUp(e) },
{ EventType.ValidateCommand, e => OnValidateCommand(e) },
{ EventType.ExecuteCommand, e => OnExecuteCommand(e) },
};
rawEventTable = new Dictionary<EventType, EventAction> {
{ EventType.MouseDown, e => OnRawMouseDown(e) },
{ EventType.MouseUp, e => OnRawMouseUp(e) },
{ EventType.MouseDrag, e => OnRawMouseDrag(e) },
{ EventType.MouseMove, e => OnRawMouseMove(e) },
};
}
protected virtual void OnMouseDown(Event e) { }
protected virtual void OnMouseUp(Event e) { }
protected virtual void OnMouseDrag(Event e) { }
protected virtual void OnMouseMove(Event e) { }
protected virtual void OnScrollWheel(Event e) { }
protected virtual void OnContextClick(Event e) { }
protected virtual void OnKeyDown(Event e) { }
protected virtual void OnKeyUp(Event e) { }
protected virtual void OnValidateCommand(Event e) { }
protected virtual void OnExecuteCommand(Event e) { }
protected virtual void OnRawMouseDown(Event e) { }
protected virtual void OnRawMouseUp(Event e) { }
protected virtual void OnRawMouseDrag(Event e) { }
protected virtual void OnRawMouseMove(Event e) { }
protected virtual void HandleEvents(Event e)
{
EventAction handler;
if (rawEventTable.TryGetValue(e.rawType, out handler))
{
handler.Invoke(e);
}
if (eventTable.TryGetValue(e.type, out handler))
{
handler.Invoke(e);
}
}
}
}

12
Assets/Fungus/Scripts/Editor/EventWindow.cs.meta

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cf9fe33ec7c10409398e58f1ede7e850
timeCreated: 1485118482
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save