summaryrefslogtreecommitdiff
path: root/Client/Assets/Scripts/UICommon/XUIObject.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2021-01-25 14:28:30 +0800
committerchai <chaifix@163.com>2021-01-25 14:28:30 +0800
commit6eb915c129fc90c6f4c82ae097dd6ffad5239efc (patch)
tree7dd2be50edf41f36b60fac84696e731c13afe617 /Client/Assets/Scripts/UICommon/XUIObject.cs
+scripts
Diffstat (limited to 'Client/Assets/Scripts/UICommon/XUIObject.cs')
-rw-r--r--Client/Assets/Scripts/UICommon/XUIObject.cs89
1 files changed, 89 insertions, 0 deletions
diff --git a/Client/Assets/Scripts/UICommon/XUIObject.cs b/Client/Assets/Scripts/UICommon/XUIObject.cs
new file mode 100644
index 00000000..667482eb
--- /dev/null
+++ b/Client/Assets/Scripts/UICommon/XUIObject.cs
@@ -0,0 +1,89 @@
+using System;
+
+public class XUIObject : XUIObjectBase
+{
+ protected override void OnAwake()
+ {
+ base.OnAwake();
+ if (null == transform.parent)
+ {
+ parent = null;
+ return;
+ }
+ //XUIObjectBase uiObject = NGUITools.FindInParents<XUIObjectBase>(transform.parent.gameObject);
+ //if (null != uiObject)
+ //{
+ // parent = uiObject;
+ //}
+ }
+ public override UILib.IXUIObject parent
+ {
+ get
+ {
+ if(!mParentCached)
+ {
+ XUIObjectBase uiObject = NGUITools.FindInParents<XUIObjectBase>(transform.parent.gameObject);
+ if (null != uiObject)
+ {
+ base.parent = uiObject;
+ }
+ mParentCached = true;
+ }
+ return base.parent;
+ }
+ set
+ {
+ base.parent = value;
+ mParentCached = true;
+ }
+ }
+
+ private bool mParentCached = false;
+}
+
+public class XUICD
+{
+ public static readonly float DEFAULT_CLICK_CD = 0.0f;
+ public static readonly float[] CLICK_CD_GROUPS = new float[] { 0.0f, 0.5f, 1.0f };
+
+ protected float m_ClickCD;
+ protected float m_ClickTime = 0f;
+
+ public void SetClickCD(int customCDGroup, float customCD)
+ {
+ if (customCD >= 0)
+ {
+ m_ClickCD = customCD;
+ }
+ else if (customCDGroup < 0 || customCDGroup >= CLICK_CD_GROUPS.Length)
+ {
+ m_ClickCD = DEFAULT_CLICK_CD;
+ }
+ else
+ {
+ m_ClickCD = CLICK_CD_GROUPS[customCDGroup];
+ }
+ }
+
+ public bool IsInCD()
+ {
+ float time = UnityEngine.Time.realtimeSinceStartup;
+ if (time - m_ClickTime < m_ClickCD)
+ return true;
+ m_ClickTime = time;
+ return false;
+ }
+
+ public void Reset()
+ {
+ m_ClickTime = 0;
+ }
+
+ public void SetUnavailableCD(int cd)
+ {
+ float time = UnityEngine.Time.realtimeSinceStartup;
+ m_ClickTime = time;
+
+ SetClickCD(0, cd);
+ }
+} \ No newline at end of file