diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/Mgr/UISys.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/Mgr/UISys.cs index 04577cfd..d3e883b1 100644 --- a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/Mgr/UISys.cs +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/Mgr/UISys.cs @@ -1,20 +1,20 @@ namespace TEngine.Runtime.UIModule { - public partial class UISys:BehaviourSingleton + public partial class UISys : BehaviourSingleton { public static int DesginWidth => 750; public static int DesginHeight => 1624; - + public static UIManager Mgr { get { return UIManager.Instance; } } - + public override void Active() { base.Active(); - + RegisterAllController(); } diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs new file mode 100644 index 00000000..452a64e5 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs @@ -0,0 +1,115 @@ +using UnityEngine; +using UnityEngine.EventSystems; + +namespace TEngine.Runtime.UIModule +{ + public enum UIDragType + { + Draging, + Drop + } + + public class DragItem : UIEventItem + { + private UIDragType m_DragState = UIDragType.Drop; + private Vector3 m_ItemOldPos; + private Vector3 m_ItemCachePos; + private bool m_CanDrag = false; + + /// + /// 是否可以拖拽 + /// + public bool CanDrag + { + get { return m_CanDrag; } + set + { + m_CanDrag = value; + if (m_CanDrag) + { + BindDrag(); + } + } + } + + protected override void OnCreate() + { + base.OnCreate(); + BindDrag(); + } + + private void BindDrag() + { + if (m_CanDrag) + { + BindBeginDragEvent(delegate(DragItem item, PointerEventData data) + { + if (!m_CanDrag) + { + return; + } + + StartDragItem(UIDragType.Draging); + }); + + BindEndDragEvent(delegate(DragItem item, PointerEventData data) + { + if (!m_CanDrag) + { + return; + } + + EndDrag(); + }); + } + } + + protected override void OnUpdate() + { + if (!m_CanDrag) + { + return; + } + + UpdateDragPos(); + } + + private void StartDragItem(UIDragType type) + { + if (type != UIDragType.Drop) + { + m_ItemOldPos = transform.position; + Vector3 pos; + UISys.Mgr.GetMouseDownUiPos(out pos); + m_ItemCachePos = pos; + UpdateDragPos(); + m_DragState = type; + } + } + + private void EndDrag() + { + m_DragState = UIDragType.Drop; + transform.position = m_ItemOldPos; +#if UNITY_EDITOR + //Debug.LogError("m_ItemCachePos.y - m_ItemOldPos.y " + (m_ItemCachePos.y - m_ItemOldPos.y)); +#endif + if (m_ItemCachePos.y - m_ItemOldPos.y > 3) + { + } + } + + private void UpdateDragPos() + { + if (m_DragState == UIDragType.Drop) + { + return; + } + + Vector3 pos; + UISys.Mgr.GetMouseDownUiPos(out pos); + transform.position += (pos - m_ItemCachePos); + m_ItemCachePos = pos; + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs.meta b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs.meta new file mode 100644 index 00000000..d37269db --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/DragItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f4c91d7a5462771488cb7641f5055d16 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs new file mode 100644 index 00000000..32ff9e2f --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs @@ -0,0 +1,18 @@ +using UnityEngine.UI; + +public class EmptyGraph : Graphic +{ + public bool m_debug = false; + + protected override void OnPopulateMesh(VertexHelper vbo) + { + vbo.Clear(); + +#if UNITY_EDITOR + if (m_debug) + { + base.OnPopulateMesh(vbo); + } +#endif + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs.meta b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs.meta new file mode 100644 index 00000000..547e1b3b --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/EmptyGraph.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b993b1c70e007c7498a52d1449a77b22 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs new file mode 100644 index 00000000..7d29fe0a --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs @@ -0,0 +1,111 @@ +using UnityEngine; + +namespace TEngine.Runtime.UIModule +{ + public enum TweenType + { + Position, + Rotation, + Scale, + Alpha, + } + + public class TweenUtil : MonoBehaviour + { + public bool isLocal; + public TweenType type; + public Vector3 from; + public Vector3 to; + public AnimationCurve curve = AnimationCurve.Linear(0, 0, 1, 1); + public float duration = 1f; + public bool isLoop; + public bool isPingPong; + private float timer = 0f; + private CanvasGroup canvasGroup; + + void Awake() + { + canvasGroup = gameObject.GetComponent(); + } + + void Update() + { + if (duration > 0) + { + timer += Time.deltaTime; + float curveValue; + if (isLoop) + { + float remainTime = timer % duration; + int loopCount = (int)(timer / duration); + float evaluateTime = remainTime / duration; + if (isPingPong) + { + evaluateTime = loopCount % 2 == 0 ? evaluateTime : 1 - evaluateTime; + } + curveValue = curve.Evaluate(evaluateTime); + } + else + { + curveValue = curve.Evaluate(timer); + } + var lerpValue = Vector3.Lerp(from, to, curveValue); + //if (lerpValue == lastValue) + //{ + // return; + //} + //lastValue = lerpValue; + switch (type) + { + case TweenType.Position: + if (isLocal) + { + transform.localPosition = lerpValue; + } + else + { + transform.position = lerpValue; + } + break; + case TweenType.Rotation: + if (isLocal) + { + transform.localEulerAngles = lerpValue; + } + else + { + transform.eulerAngles = lerpValue; + } + break; + case TweenType.Scale: + if (isLocal) + { + transform.localScale = lerpValue; + } + else + { + var value1 = VectorWiseDivision(transform.lossyScale, transform.localScale); + var value2 = VectorWiseDivision(lerpValue, value1); + transform.localScale = value2; + } + break; + case TweenType.Alpha: + if (canvasGroup != null) + { + canvasGroup.alpha = lerpValue.x; + } + else + { + TLogger.LogError("Change Alpha need Component: [CanvasGroup]"); + } + break; + } + } + } + + Vector3 VectorWiseDivision(Vector3 a, Vector3 b) + { + return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z); + } + } +} \ No newline at end of file diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs.meta b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs.meta new file mode 100644 index 00000000..bce50ee7 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/TweenUtil.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 08d5112535e10c34e998833a7b47d9ec +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIEventItem.cs b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIEventItem.cs new file mode 100644 index 00000000..ef5e3737 --- /dev/null +++ b/Assets/TEngine/Scripts/Runtime/UIModule/Scripts/UI/UIEventItem.cs @@ -0,0 +1,196 @@ +using System; +using UnityEngine.EventSystems; +using UnityEngine.UI; + +namespace TEngine.Runtime.UIModule +{ + public class UIEventItem : UIWindowWidget where T : UIEventItem + { + protected Button m_buttonClick; + private object[] m_eventParam; + + public object EventParam1 + { + get { return m_eventParam != null && m_eventParam.Length > 0 ? m_eventParam[0] : null; } + } + + public object EventParam2 + { + get { return m_eventParam != null && m_eventParam.Length > 1 ? m_eventParam[1] : null; } + } + + public object EventParam3 + { + get { return m_eventParam != null && m_eventParam.Length > 2 ? m_eventParam[2] : null; } + } + + public object this[int index] + { + get { return m_eventParam != null && index < m_eventParam.Length ? m_eventParam[index] : null; } + } + + private Action m_clickAction; + private Action m_pressAction; + private Action m_beginDragAction; + private Action m_dragAction; + private Action m_endDragAction; + + public void BindClickEvent(Action clickAction, params object[] arg) + { + if (m_clickAction != null) + { + m_clickAction = clickAction; + } + else + { + m_clickAction = clickAction; + m_buttonClick = UnityUtil.AddMonoBehaviour