From 6eb915c129fc90c6f4c82ae097dd6ffad5239efc Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 25 Jan 2021 14:28:30 +0800 Subject: +scripts --- Client/Assets/Scripts/XMainClient/XComponent.cs | 208 ++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 Client/Assets/Scripts/XMainClient/XComponent.cs (limited to 'Client/Assets/Scripts/XMainClient/XComponent.cs') diff --git a/Client/Assets/Scripts/XMainClient/XComponent.cs b/Client/Assets/Scripts/XMainClient/XComponent.cs new file mode 100644 index 00000000..529f9cc0 --- /dev/null +++ b/Client/Assets/Scripts/XMainClient/XComponent.cs @@ -0,0 +1,208 @@ +using System; +using KKSG; +using XUtliPoolLib; + +namespace XMainClient +{ + internal abstract class XComponent + { + public abstract uint ID { get; } + + public bool Enabled + { + get + { + return this._enabled && !this._detached; + } + set + { + this._enabled = value; + } + } + + public bool Detached + { + get + { + return this._detached; + } + set + { + this._detached = value; + } + } + + public bool ManualUnitBuff + { + get + { + return this._manualUnitBuff; + } + set + { + this._manualUnitBuff = value; + } + } + + public XObject Host + { + get + { + return this._host; + } + } + + public XEntity Entity + { + get + { + return this._entity; + } + } + + public static readonly uint uuID = 0u; + + protected XObject _host = null; + + protected XEntity _entity = null; + + private bool _enabled = true; + + private bool _detached = false; + + protected bool _manualUnitBuff = false; + + protected SmallBuffer _eventMap; + + public delegate bool XEventHandler(XEventArgs e); + + public struct ComponentEventHandler + { + public int eventIndex; + + public XComponent.XEventHandler handler; + } + + public virtual void InitilizeBuffer() + { + XSingleton.singleton.GetBuffer(ref this._eventMap, 8); + } + + public virtual void UninitilizeBuffer() + { + XSingleton.singleton.ReturnBuffer(ref this._eventMap); + } + + private XComponent.XEventHandler FindEventHandler(int eventIndex) + { + int count = this._eventMap.Count; + for (int i = 0; i < count; i++) + { + XComponent.ComponentEventHandler componentEventHandler = this._eventMap[i]; + bool flag = componentEventHandler.eventIndex == eventIndex; + if (flag) + { + return componentEventHandler.handler; + } + } + return null; + } + + public virtual void OnReconnect(UnitAppearance data) + { + } + + public virtual void Attached() + { + } + + public virtual void OnEnterScene() + { + } + + public virtual void OnLeaveScene() + { + } + + public virtual void Update(float fDeltaT) + { + } + + public virtual void FixedUpdate() + { + } + + public virtual void PostUpdate(float fDeltaT) + { + } + + public bool OnEvent(XEventArgs e) + { + int eventIndex = XFastEnumIntEqualityComparer.ToInt(e.ArgsDefine); + XComponent.XEventHandler xeventHandler = this.FindEventHandler(eventIndex); + bool flag = xeventHandler != null; + return flag && xeventHandler(e); + } + + public virtual void OnAttachToHost(XObject host) + { + this._host = host; + this._entity = (this._host as XEntity); + this.BeginRegisterEvent(); + this.EventSubscribe(); + this.EndRegisterEvent(); + } + + public virtual void OnDetachFromHost() + { + this.EventUnsubscribe(); + this._host = null; + this._entity = null; + } + + public virtual void OnComponentAttachToHost(XComponent c) + { + } + + public virtual void OnComponentDetachFromHost(XComponent c) + { + } + + private void BeginRegisterEvent() + { + } + + private void EndRegisterEvent() + { + } + + protected virtual void EventSubscribe() + { + } + + protected void EventUnsubscribe() + { + this._eventMap.Clear(); + } + + protected void RegisterEvent(XEventDefine eventID, XComponent.XEventHandler handler) + { + int num = XFastEnumIntEqualityComparer.ToInt(eventID); + int count = this._eventMap.Count; + for (int i = 0; i < count; i++) + { + XComponent.ComponentEventHandler componentEventHandler = this._eventMap[i]; + bool flag = componentEventHandler.eventIndex == num; + if (flag) + { + return; + } + } + this._eventMap.Add(new XComponent.ComponentEventHandler + { + eventIndex = num, + handler = handler + }); + } + } +} -- cgit v1.1-26-g67d0