mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 10:46:17 +00:00
提交FairyGUI
This commit is contained in:
@@ -0,0 +1,198 @@
|
||||
using System.Timers;
|
||||
#if FAIRYGUI_TOLUA
|
||||
using System;
|
||||
using LuaInterface;
|
||||
#endif
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
class EventBridge
|
||||
{
|
||||
public EventDispatcher owner;
|
||||
|
||||
EventCallback0 _callback0;
|
||||
EventCallback1 _callback1;
|
||||
EventCallback1 _captureCallback;
|
||||
internal bool _dispatching;
|
||||
private float _intervalTime = 0;
|
||||
private bool _isOnCall = true;
|
||||
public EventBridge(EventDispatcher owner)
|
||||
{
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
public void AddCapture(EventCallback1 callback)
|
||||
{
|
||||
_captureCallback -= callback;
|
||||
_captureCallback += callback;
|
||||
}
|
||||
|
||||
public void RemoveCapture(EventCallback1 callback)
|
||||
{
|
||||
_captureCallback -= callback;
|
||||
}
|
||||
|
||||
public void Add(EventCallback1 callback)
|
||||
{
|
||||
_callback1 -= callback;
|
||||
_callback1 += callback;
|
||||
}
|
||||
|
||||
public void Remove(EventCallback1 callback)
|
||||
{
|
||||
_callback1 -= callback;
|
||||
}
|
||||
|
||||
public void Add(EventCallback0 callback)
|
||||
{
|
||||
_callback0 -= callback;
|
||||
_callback0 += callback;
|
||||
}
|
||||
|
||||
public void SetInterval(float timer)
|
||||
{
|
||||
_intervalTime = timer;
|
||||
}
|
||||
|
||||
public void Remove(EventCallback0 callback)
|
||||
{
|
||||
_callback0 -= callback;
|
||||
}
|
||||
|
||||
#if FAIRYGUI_TOLUA
|
||||
public void Add(LuaFunction func, LuaTable self)
|
||||
{
|
||||
EventCallback1 callback;
|
||||
if(self != null)
|
||||
callback = (EventCallback1)DelegateTraits<EventCallback1>.Create(func, self);
|
||||
else
|
||||
callback = (EventCallback1)DelegateTraits<EventCallback1>.Create(func);
|
||||
_callback1 -= callback;
|
||||
_callback1 += callback;
|
||||
}
|
||||
|
||||
public void Add(LuaFunction func, GComponent self)
|
||||
{
|
||||
if (self._peerTable == null)
|
||||
throw new Exception("self is not connected to lua.");
|
||||
|
||||
Add(func, self._peerTable);
|
||||
}
|
||||
|
||||
public void Remove(LuaFunction func, LuaTable self)
|
||||
{
|
||||
LuaState state = func.GetLuaState();
|
||||
LuaDelegate target;
|
||||
if (self != null)
|
||||
target = state.GetLuaDelegate(func, self);
|
||||
else
|
||||
target = state.GetLuaDelegate(func);
|
||||
|
||||
Delegate[] ds = _callback1.GetInvocationList();
|
||||
|
||||
for (int i = 0; i < ds.Length; i++)
|
||||
{
|
||||
LuaDelegate ld = ds[i].Target as LuaDelegate;
|
||||
if (ld != null && ld.Equals(target))
|
||||
{
|
||||
_callback1 = (EventCallback1)Delegate.Remove(_callback1, ds[i]);
|
||||
//DelayDispose will cause problem
|
||||
//state.DelayDispose(ld.func);
|
||||
//if (ld.self != null)
|
||||
// state.DelayDispose(ld.self);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Remove(LuaFunction func, GComponent self)
|
||||
{
|
||||
if (self._peerTable == null)
|
||||
throw new Exception("self is not connected to lua.");
|
||||
|
||||
Remove(func, self._peerTable);
|
||||
}
|
||||
#endif
|
||||
|
||||
public bool isEmpty
|
||||
{
|
||||
get { return _callback1 == null && _callback0 == null && _captureCallback == null; }
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
#if FAIRYGUI_TOLUA
|
||||
//if (_callback1 != null)
|
||||
//{
|
||||
// Delegate[] ds = _callback1.GetInvocationList();
|
||||
// for (int i = 0; i < ds.Length; i++)
|
||||
// {
|
||||
// LuaDelegate ld = ds[i].Target as LuaDelegate;
|
||||
// if (ld != null)
|
||||
// {
|
||||
// LuaState state = ld.func.GetLuaState();
|
||||
// state.DelayDispose(ld.func);
|
||||
// if (ld.self != null)
|
||||
// state.DelayDispose(ld.self);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
#endif
|
||||
_callback1 = null;
|
||||
_callback0 = null;
|
||||
_captureCallback = null;
|
||||
}
|
||||
|
||||
public void CallInternal(EventContext context)
|
||||
{
|
||||
if (_isOnCall)
|
||||
{
|
||||
if (_intervalTime > 0)
|
||||
{
|
||||
_isOnCall = false;
|
||||
Timers.inst.Add(_intervalTime, 0, (object context)=>
|
||||
{
|
||||
_isOnCall = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
_dispatching = true;
|
||||
context.sender = owner;
|
||||
try
|
||||
{
|
||||
if (_callback1 != null)
|
||||
_callback1(context);
|
||||
if (_callback0 != null)
|
||||
_callback0();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dispatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void CallCaptureInternal(EventContext context)
|
||||
{
|
||||
if (_captureCallback == null)
|
||||
return;
|
||||
|
||||
_dispatching = true;
|
||||
context.sender = owner;
|
||||
try
|
||||
{
|
||||
_captureCallback(context);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_dispatching = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9712bee5e6977647989e012a6a332a6
|
||||
timeCreated: 1460480288
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,94 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class EventContext
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public EventDispatcher sender { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// /
|
||||
/// </summary>
|
||||
public object initiator { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// /
|
||||
/// </summary>
|
||||
public InputEvent inputEvent { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string type;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public object data;
|
||||
|
||||
internal bool _defaultPrevented;
|
||||
internal bool _stopsPropagation;
|
||||
internal bool _touchCapture;
|
||||
|
||||
internal List<EventBridge> callChain = new List<EventBridge>();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void StopPropagation()
|
||||
{
|
||||
_stopsPropagation = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void PreventDefault()
|
||||
{
|
||||
_defaultPrevented = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void CaptureTouch()
|
||||
{
|
||||
_touchCapture = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool isDefaultPrevented
|
||||
{
|
||||
get { return _defaultPrevented; }
|
||||
}
|
||||
|
||||
static Stack<EventContext> pool = new Stack<EventContext>();
|
||||
internal static EventContext Get()
|
||||
{
|
||||
if (pool.Count > 0)
|
||||
{
|
||||
EventContext context = pool.Pop();
|
||||
context._stopsPropagation = false;
|
||||
context._defaultPrevented = false;
|
||||
context._touchCapture = false;
|
||||
return context;
|
||||
}
|
||||
else
|
||||
return new EventContext();
|
||||
}
|
||||
|
||||
internal static void Return(EventContext value)
|
||||
{
|
||||
pool.Push(value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3391a1fa2fc33b7448dfdf3e7c48880d
|
||||
timeCreated: 1535374214
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,515 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
public delegate void EventCallback0();
|
||||
public delegate void EventCallback1(EventContext context);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class EventDispatcher : IEventDispatcher
|
||||
{
|
||||
Dictionary<string, EventBridge> _dic;
|
||||
|
||||
public EventDispatcher()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void AddEventListener(string strType, EventCallback1 callback)
|
||||
{
|
||||
GetBridge(strType).Add(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void AddEventListener(string strType, EventCallback0 callback)
|
||||
{
|
||||
GetBridge(strType).Add(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void RemoveEventListener(string strType, EventCallback1 callback)
|
||||
{
|
||||
if (_dic == null)
|
||||
return;
|
||||
|
||||
EventBridge bridge = null;
|
||||
if (_dic.TryGetValue(strType, out bridge))
|
||||
bridge.Remove(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void RemoveEventListener(string strType, EventCallback0 callback)
|
||||
{
|
||||
if (_dic == null)
|
||||
return;
|
||||
|
||||
EventBridge bridge = null;
|
||||
if (_dic.TryGetValue(strType, out bridge))
|
||||
bridge.Remove(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void AddCapture(string strType, EventCallback1 callback)
|
||||
{
|
||||
GetBridge(strType).AddCapture(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="callback"></param>
|
||||
public void RemoveCapture(string strType, EventCallback1 callback)
|
||||
{
|
||||
if (_dic == null)
|
||||
return;
|
||||
|
||||
EventBridge bridge = null;
|
||||
if (_dic.TryGetValue(strType, out bridge))
|
||||
bridge.RemoveCapture(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void RemoveEventListeners()
|
||||
{
|
||||
RemoveEventListeners(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
public void RemoveEventListeners(string strType)
|
||||
{
|
||||
if (_dic == null)
|
||||
return;
|
||||
|
||||
if (strType != null)
|
||||
{
|
||||
EventBridge bridge;
|
||||
if (_dic.TryGetValue(strType, out bridge))
|
||||
bridge.Clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (KeyValuePair<string, EventBridge> kv in _dic)
|
||||
kv.Value.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <returns></returns>
|
||||
public bool hasEventListeners(string strType)
|
||||
{
|
||||
EventBridge bridge = TryGetEventBridge(strType);
|
||||
if (bridge == null)
|
||||
return false;
|
||||
|
||||
return !bridge.isEmpty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <returns></returns>
|
||||
public bool isDispatching(string strType)
|
||||
{
|
||||
EventBridge bridge = TryGetEventBridge(strType);
|
||||
if (bridge == null)
|
||||
return false;
|
||||
|
||||
return bridge._dispatching;
|
||||
}
|
||||
|
||||
internal EventBridge TryGetEventBridge(string strType)
|
||||
{
|
||||
if (_dic == null)
|
||||
return null;
|
||||
|
||||
EventBridge bridge = null;
|
||||
_dic.TryGetValue(strType, out bridge);
|
||||
return bridge;
|
||||
}
|
||||
|
||||
internal EventBridge GetEventBridge(string strType)
|
||||
{
|
||||
if (_dic == null)
|
||||
_dic = new Dictionary<string, EventBridge>();
|
||||
|
||||
EventBridge bridge = null;
|
||||
if (!_dic.TryGetValue(strType, out bridge))
|
||||
{
|
||||
bridge = new EventBridge(this);
|
||||
_dic[strType] = bridge;
|
||||
}
|
||||
return bridge;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <returns></returns>
|
||||
public bool DispatchEvent(string strType)
|
||||
{
|
||||
return DispatchEvent(strType, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool DispatchEvent(string strType, object data)
|
||||
{
|
||||
return InternalDispatchEvent(strType, null, data, null);
|
||||
}
|
||||
|
||||
public bool DispatchEvent(string strType, object data, object initiator)
|
||||
{
|
||||
return InternalDispatchEvent(strType, null, data, initiator);
|
||||
}
|
||||
|
||||
static InputEvent sCurrentInputEvent = new InputEvent();
|
||||
|
||||
internal bool InternalDispatchEvent(string strType, EventBridge bridge, object data, object initiator)
|
||||
{
|
||||
if (bridge == null)
|
||||
bridge = TryGetEventBridge(strType);
|
||||
|
||||
EventBridge gBridge = null;
|
||||
if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null)
|
||||
gBridge = ((DisplayObject)this).gOwner.TryGetEventBridge(strType);
|
||||
|
||||
bool b1 = bridge != null && !bridge.isEmpty;
|
||||
bool b2 = gBridge != null && !gBridge.isEmpty;
|
||||
if (b1 || b2)
|
||||
{
|
||||
EventContext context = EventContext.Get();
|
||||
context.initiator = initiator != null ? initiator : this;
|
||||
context.type = strType;
|
||||
context.data = data;
|
||||
if (data is InputEvent)
|
||||
sCurrentInputEvent = (InputEvent)data;
|
||||
context.inputEvent = sCurrentInputEvent;
|
||||
|
||||
if (b1)
|
||||
{
|
||||
bridge.CallCaptureInternal(context);
|
||||
bridge.CallInternal(context);
|
||||
}
|
||||
|
||||
if (b2)
|
||||
{
|
||||
gBridge.CallCaptureInternal(context);
|
||||
gBridge.CallInternal(context);
|
||||
}
|
||||
|
||||
EventContext.Return(context);
|
||||
context.initiator = null;
|
||||
context.sender = null;
|
||||
context.data = null;
|
||||
|
||||
return context._defaultPrevented;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="context"></param>
|
||||
/// <returns></returns>
|
||||
public bool DispatchEvent(EventContext context)
|
||||
{
|
||||
EventBridge bridge = TryGetEventBridge(context.type);
|
||||
EventBridge gBridge = null;
|
||||
if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null)
|
||||
gBridge = ((DisplayObject)this).gOwner.TryGetEventBridge(context.type);
|
||||
|
||||
EventDispatcher savedSender = context.sender;
|
||||
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
{
|
||||
bridge.CallCaptureInternal(context);
|
||||
bridge.CallInternal(context);
|
||||
}
|
||||
|
||||
if (gBridge != null && !gBridge.isEmpty)
|
||||
{
|
||||
gBridge.CallCaptureInternal(context);
|
||||
gBridge.CallInternal(context);
|
||||
}
|
||||
|
||||
context.sender = savedSender;
|
||||
return context._defaultPrevented;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="addChain"></param>
|
||||
/// <returns></returns>
|
||||
internal bool BubbleEvent(string strType, object data, List<EventBridge> addChain)
|
||||
{
|
||||
EventContext context = EventContext.Get();
|
||||
context.initiator = this;
|
||||
|
||||
context.type = strType;
|
||||
context.data = data;
|
||||
if (data is InputEvent)
|
||||
sCurrentInputEvent = (InputEvent)data;
|
||||
context.inputEvent = sCurrentInputEvent;
|
||||
List<EventBridge> bubbleChain = context.callChain;
|
||||
bubbleChain.Clear();
|
||||
|
||||
GetChainBridges(strType, bubbleChain, true);
|
||||
|
||||
int length = bubbleChain.Count;
|
||||
for (int i = length - 1; i >= 0; i--)
|
||||
{
|
||||
bubbleChain[i].CallCaptureInternal(context);
|
||||
if (context._touchCapture)
|
||||
{
|
||||
context._touchCapture = false;
|
||||
if (strType == "onTouchBegin")
|
||||
Stage.inst.AddTouchMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
|
||||
}
|
||||
}
|
||||
|
||||
if (!context._stopsPropagation)
|
||||
{
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
bubbleChain[i].CallInternal(context);
|
||||
|
||||
if (context._touchCapture)
|
||||
{
|
||||
context._touchCapture = false;
|
||||
if (strType == "onTouchBegin")
|
||||
Stage.inst.AddTouchMonitor(context.inputEvent.touchId, bubbleChain[i].owner);
|
||||
}
|
||||
|
||||
if (context._stopsPropagation)
|
||||
break;
|
||||
}
|
||||
|
||||
if (addChain != null)
|
||||
{
|
||||
length = addChain.Count;
|
||||
for (int i = 0; i < length; ++i)
|
||||
{
|
||||
EventBridge bridge = addChain[i];
|
||||
if (bubbleChain.IndexOf(bridge) == -1)
|
||||
{
|
||||
bridge.CallCaptureInternal(context);
|
||||
bridge.CallInternal(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EventContext.Return(context);
|
||||
context.initiator = null;
|
||||
context.sender = null;
|
||||
context.data = null;
|
||||
return context._defaultPrevented;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool BubbleEvent(string strType, object data)
|
||||
{
|
||||
return BubbleEvent(strType, data, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="strType"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool BroadcastEvent(string strType, object data)
|
||||
{
|
||||
EventContext context = EventContext.Get();
|
||||
context.initiator = this;
|
||||
context.type = strType;
|
||||
context.data = data;
|
||||
if (data is InputEvent)
|
||||
sCurrentInputEvent = (InputEvent)data;
|
||||
context.inputEvent = sCurrentInputEvent;
|
||||
List<EventBridge> bubbleChain = context.callChain;
|
||||
bubbleChain.Clear();
|
||||
|
||||
if (this is Container)
|
||||
GetChildEventBridges(strType, (Container)this, bubbleChain);
|
||||
else if (this is GComponent)
|
||||
GetChildEventBridges(strType, (GComponent)this, bubbleChain);
|
||||
|
||||
int length = bubbleChain.Count;
|
||||
for (int i = 0; i < length; ++i)
|
||||
bubbleChain[i].CallInternal(context);
|
||||
|
||||
EventContext.Return(context);
|
||||
context.initiator = null;
|
||||
context.sender = null;
|
||||
context.data = null;
|
||||
return context._defaultPrevented;
|
||||
}
|
||||
|
||||
EventBridge GetBridge(string strType)
|
||||
{
|
||||
if (strType == null)
|
||||
throw new Exception("event type cant be null");
|
||||
|
||||
if (_dic == null)
|
||||
_dic = new Dictionary<string, EventBridge>();
|
||||
|
||||
EventBridge bridge = null;
|
||||
if (!_dic.TryGetValue(strType, out bridge))
|
||||
{
|
||||
bridge = new EventBridge(this);
|
||||
_dic[strType] = bridge;
|
||||
}
|
||||
|
||||
return bridge;
|
||||
}
|
||||
|
||||
static void GetChildEventBridges(string strType, Container container, List<EventBridge> bridges)
|
||||
{
|
||||
EventBridge bridge = container.TryGetEventBridge(strType);
|
||||
if (bridge != null)
|
||||
bridges.Add(bridge);
|
||||
if (container.gOwner != null)
|
||||
{
|
||||
bridge = container.gOwner.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
bridges.Add(bridge);
|
||||
}
|
||||
|
||||
int count = container.numChildren;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
DisplayObject obj = container.GetChildAt(i);
|
||||
if (obj is Container)
|
||||
GetChildEventBridges(strType, (Container)obj, bridges);
|
||||
else
|
||||
{
|
||||
bridge = obj.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
bridges.Add(bridge);
|
||||
|
||||
if (obj.gOwner != null)
|
||||
{
|
||||
bridge = obj.gOwner.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
bridges.Add(bridge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void GetChildEventBridges(string strType, GComponent container, List<EventBridge> bridges)
|
||||
{
|
||||
EventBridge bridge = container.TryGetEventBridge(strType);
|
||||
if (bridge != null)
|
||||
bridges.Add(bridge);
|
||||
|
||||
int count = container.numChildren;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
GObject obj = container.GetChildAt(i);
|
||||
if (obj is GComponent)
|
||||
GetChildEventBridges(strType, (GComponent)obj, bridges);
|
||||
else
|
||||
{
|
||||
bridge = obj.TryGetEventBridge(strType);
|
||||
if (bridge != null)
|
||||
bridges.Add(bridge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal void GetChainBridges(string strType, List<EventBridge> chain, bool bubble)
|
||||
{
|
||||
EventBridge bridge = TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
chain.Add(bridge);
|
||||
|
||||
if ((this is DisplayObject) && ((DisplayObject)this).gOwner != null)
|
||||
{
|
||||
bridge = ((DisplayObject)this).gOwner.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
chain.Add(bridge);
|
||||
}
|
||||
|
||||
if (!bubble)
|
||||
return;
|
||||
|
||||
if (this is DisplayObject)
|
||||
{
|
||||
DisplayObject element = (DisplayObject)this;
|
||||
while ((element = element.parent) != null)
|
||||
{
|
||||
bridge = element.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
chain.Add(bridge);
|
||||
|
||||
if (element.gOwner != null)
|
||||
{
|
||||
bridge = element.gOwner.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
chain.Add(bridge);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (this is GObject)
|
||||
{
|
||||
GObject element = (GObject)this;
|
||||
while ((element = element.parent) != null)
|
||||
{
|
||||
bridge = element.TryGetEventBridge(strType);
|
||||
if (bridge != null && !bridge.isEmpty)
|
||||
chain.Add(bridge);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f31d18fa6488bb469504c7128522d21
|
||||
timeCreated: 1460480288
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,284 @@
|
||||
#if FAIRYGUI_TOLUA
|
||||
using LuaInterface;
|
||||
#endif
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class EventListener
|
||||
{
|
||||
EventBridge _bridge;
|
||||
string _type;
|
||||
private const float DefualtIntervalTime = 0.5f;
|
||||
private EventDispatcher Owner;
|
||||
|
||||
public EventListener(EventDispatcher owner, string type)
|
||||
{
|
||||
Owner = owner;
|
||||
_bridge = owner.GetEventBridge(type);
|
||||
_type = type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string type
|
||||
{
|
||||
get { return _type; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
public void AddCapture(EventCallback1 callback)
|
||||
{
|
||||
_bridge.AddCapture(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
public void RemoveCapture(EventCallback1 callback)
|
||||
{
|
||||
_bridge.RemoveCapture(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
public void Add(EventCallback1 callback, bool isInterval = true)
|
||||
{
|
||||
_bridge.Add(callback);
|
||||
if (isInterval && Owner is GButton)
|
||||
{
|
||||
SetInterval(DefualtIntervalTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
public void Remove(EventCallback1 callback)
|
||||
{
|
||||
_bridge.Remove(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
/// <param name="isInterval">是否开启点击延迟 默认开启</param>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public void Add(EventCallback0 callback, bool isInterval = true)
|
||||
{
|
||||
_bridge.Add(callback);
|
||||
if (isInterval && Owner is GButton)
|
||||
{
|
||||
SetInterval(DefualtIntervalTime);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public void Remove(EventCallback0 callback)
|
||||
{
|
||||
_bridge.Remove(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
public void Set(EventCallback1 callback)
|
||||
{
|
||||
_bridge.Clear();
|
||||
if (callback != null)
|
||||
_bridge.Add(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="callback"></param>
|
||||
#if FAIRYGUI_TOLUA
|
||||
[NoToLua]
|
||||
#endif
|
||||
public void Set(EventCallback0 callback)
|
||||
{
|
||||
_bridge.Clear();
|
||||
if (callback != null)
|
||||
_bridge.Add(callback);
|
||||
}
|
||||
|
||||
#if FAIRYGUI_TOLUA
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Add(LuaFunction func, LuaTable self)
|
||||
{
|
||||
_bridge.Add(func, self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Add(LuaFunction func, GComponent self)
|
||||
{
|
||||
_bridge.Add(func, self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Remove(LuaFunction func, LuaTable self)
|
||||
{
|
||||
_bridge.Remove(func, self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Remove(LuaFunction func, GComponent self)
|
||||
{
|
||||
_bridge.Remove(func, self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Set(LuaFunction func, LuaTable self)
|
||||
{
|
||||
_bridge.Clear();
|
||||
if (func != null)
|
||||
Add(func, self);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
/// <param name="self"></param>
|
||||
public void Set(LuaFunction func, GComponent self)
|
||||
{
|
||||
_bridge.Clear();
|
||||
if (func != null)
|
||||
Add(func, self);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool isEmpty
|
||||
{
|
||||
get
|
||||
{
|
||||
return !_bridge.owner.hasEventListeners(_type);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool isDispatching
|
||||
{
|
||||
get
|
||||
{
|
||||
return _bridge.owner.isDispatching(_type);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_bridge.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool Call()
|
||||
{
|
||||
return _bridge.owner.InternalDispatchEvent(_type, _bridge, null, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool Call(object data)
|
||||
{
|
||||
return _bridge.owner.InternalDispatchEvent(_type, _bridge, data, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool BubbleCall(object data)
|
||||
{
|
||||
return _bridge.owner.BubbleEvent(_type, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool BubbleCall()
|
||||
{
|
||||
return _bridge.owner.BubbleEvent(_type, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public bool BroadcastCall(object data)
|
||||
{
|
||||
return _bridge.owner.BroadcastEvent(_type, data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public bool BroadcastCall()
|
||||
{
|
||||
return _bridge.owner.BroadcastEvent(_type, null);
|
||||
}
|
||||
|
||||
public void SetInterval(float timer)
|
||||
{
|
||||
_bridge.SetInterval(timer);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8747c4706bc8c864786f691555eaa2fb
|
||||
timeCreated: 1460480288
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public interface IEventDispatcher
|
||||
{
|
||||
void AddEventListener(string strType, EventCallback0 callback);
|
||||
void AddEventListener(string strType, EventCallback1 callback);
|
||||
void RemoveEventListener(string strType, EventCallback0 callback);
|
||||
void RemoveEventListener(string strType, EventCallback1 callback);
|
||||
bool DispatchEvent(EventContext context);
|
||||
bool DispatchEvent(string strType);
|
||||
bool DispatchEvent(string strType, object data);
|
||||
bool DispatchEvent(string strType, object data, object initiator);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8dfc3c6bb6a91445b52cee1e916c398
|
||||
timeCreated: 1460480288
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,149 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace FairyGUI
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class InputEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// x position in stage coordinates.
|
||||
/// </summary>
|
||||
public float x { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// y position in stage coordinates.
|
||||
/// </summary>
|
||||
public float y { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public KeyCode keyCode { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public char character { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public EventModifiers modifiers { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public float mouseWheelDelta { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int touchId { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// -1-none,0-left,1-right,2-middle
|
||||
/// </summary>
|
||||
public int button { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public int clickCount { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Duraion of holding the button. You can read this in touchEnd or click event.
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
public float holdTime { get; internal set; }
|
||||
|
||||
public InputEvent()
|
||||
{
|
||||
touchId = -1;
|
||||
x = 0;
|
||||
y = 0;
|
||||
clickCount = 0;
|
||||
keyCode = KeyCode.None;
|
||||
character = '\0';
|
||||
modifiers = 0;
|
||||
mouseWheelDelta = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Vector2 position
|
||||
{
|
||||
get { return new Vector2(x, y); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool isDoubleClick
|
||||
{
|
||||
get { return clickCount > 1 && button == 0; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool ctrlOrCmd
|
||||
{
|
||||
get
|
||||
{
|
||||
return ctrl || command;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool ctrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool shift
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool alt
|
||||
{
|
||||
get
|
||||
{
|
||||
return Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool command
|
||||
{
|
||||
get
|
||||
{
|
||||
//In win, as long as the win key and other keys are pressed at the same time, the getKey will continue to return true. So it can only be shielded.
|
||||
if (Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor)
|
||||
return Input.GetKey(KeyCode.LeftCommand) || Input.GetKey(KeyCode.RightCommand);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc16eca0c17d9344882b6e63f26ecc9e
|
||||
timeCreated: 1460480288
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user