Main/Component/UI/Common/FunctionButton.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Main/Component/UI/Common/FunctionButtonGroup.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Main/System/Skill/FlipScroll.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
Main/System/Skill/FlipScroll.cs.meta | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
Main/Component/UI/Common/FunctionButton.cs
@@ -1,262 +1,262 @@ // //-------------------------------------------------------- // // [Author]: 第二世界 // // [ Date ]: Tuesday, October 31, 2017 // //-------------------------------------------------------- // using UnityEngine; // using System.Collections; // using UnityEngine.UI; // using UnityEngine.Events; // using UnityEngine.EventSystems; //-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, October 31, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.Events; using UnityEngine.EventSystems; // using System; using System; // namespace vnxbqy.UI // { namespace vnxbqy.UI { // public class FunctionButton : Button // { // [SerializeField] int m_Order = 0; // public int order { // get { return m_Order; } // set { // m_Order = value; // } // } public class FunctionButton : Button { [SerializeField] int m_Order = 0; public int order { get { return m_Order; } set { m_Order = value; } } // [SerializeField] int m_FunctionId = -1; // public int functionId { // get { return m_FunctionId; } // set { // m_FunctionId = value; // OnFunctionUnLockStateChange(); // } // } [SerializeField] int m_FunctionId = -1; public int functionId { get { return m_FunctionId; } set { m_FunctionId = value; OnFunctionUnLockStateChange(); } } // [SerializeField] TitleBtnState m_State = TitleBtnState.Normal; // public TitleBtnState state { // get { return m_State; } // set { // if (m_State != value) // { // m_State = value; // OnStateChange(); // } // } // } [SerializeField] TitleBtnState m_State = TitleBtnState.Normal; public TitleBtnState state { get { return m_State; } set { if (m_State != value) { m_State = value; OnStateChange(); } } } // [SerializeField] Button m_Button; // public Button button { // get { return m_Button; } // set { m_Button = value; } // } [SerializeField] Button m_Button; public Button button { get { return m_Button; } set { m_Button = value; } } // [SerializeField] ImageEx m_Icon; // public ImageEx icon { // get { return this.m_Icon; } // set { this.m_Icon = value; } // } [SerializeField] ImageEx m_Icon; public ImageEx icon { get { return this.m_Icon; } set { this.m_Icon = value; } } // [SerializeField] TextEx m_Title; // public TextEx title { // get { return this.m_Title; } // set { this.m_Title = value; } // } [SerializeField] TextEx m_Title; public TextEx title { get { return this.m_Title; } set { this.m_Title = value; } } // [SerializeField] RedpointBehaviour m_Redpoint; // public RedpointBehaviour redpoint { // get { return m_Redpoint; } // set { m_Redpoint = value; } // } [SerializeField] RedpointBehaviour m_Redpoint; public RedpointBehaviour redpoint { get { return m_Redpoint; } set { m_Redpoint = value; } } // [SerializeField] Shadow m_Shadow; // public Shadow shadow { // get { return this.m_Shadow; } // set { this.m_Shadow = value; } // } [SerializeField] Shadow m_Shadow; public Shadow shadow { get { return this.m_Shadow; } set { this.m_Shadow = value; } } // [SerializeField] Transform m_Locked; // public Transform locked { // get { return this.m_Locked; } // set { this.m_Locked = value; } // } [SerializeField] Transform m_Locked; public Transform locked { get { return this.m_Locked; } set { this.m_Locked = value; } } // [SerializeField] int m_Audio = 1; // public int clickAudio { // get { return this.m_Audio; } // set { this.m_Audio = value; } // } [SerializeField] int m_Audio = 1; public int clickAudio { get { return this.m_Audio; } set { this.m_Audio = value; } } // [SerializeField] bool m_UseDefaultConfig = true; // public bool useDefaultConfig { // get { return this.m_UseDefaultConfig; } // set { this.m_UseDefaultConfig = value; } // } [SerializeField] bool m_UseDefaultConfig = true; public bool useDefaultConfig { get { return this.m_UseDefaultConfig; } set { this.m_UseDefaultConfig = value; } } // [SerializeField] FunctionButtonConfig m_AlternativeConfig; // public FunctionButtonConfig alternativeConfig { get { return m_AlternativeConfig; } set { m_AlternativeConfig = value; } } [SerializeField] FunctionButtonConfig m_AlternativeConfig; public FunctionButtonConfig alternativeConfig { get { return m_AlternativeConfig; } set { m_AlternativeConfig = value; } } // [SerializeField] // FunctionButtonGroup m_Group; // public FunctionButtonGroup group { // get { return m_Group; } // set { // if (m_Group != null) // { // m_Group.UnRegister(this); // } // m_Group = value; // if (m_Group != null) // { // m_Group.Register(this); // } // } // } [SerializeField] FunctionButtonGroup m_Group; public FunctionButtonGroup group { get { return m_Group; } set { if (m_Group != null) { m_Group.UnRegister(this); } m_Group = value; if (m_Group != null) { m_Group.Register(this); } } } // public event Action<string> OnPointClickLockFunc; // public event Action repeatClickFunc; public event Action<string> OnPointClickLockFunc; public event Action repeatClickFunc; // protected override void Awake() // { // #if UNITY_EDITOR // if (!Application.isPlaying) return; // #endif // OnFunctionUnLockStateChange(); // FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionUnLockStateChange; // } protected override void Awake() { #if UNITY_EDITOR if (!Application.isPlaying) return; #endif OnFunctionUnLockStateChange(); FuncOpen.Instance.OnFuncStateChangeEvent += OnFunctionUnLockStateChange; } // protected override void OnEnable() // { // base.OnEnable(); protected override void OnEnable() { base.OnEnable(); // if (group != null) // { // group.Register(this); // } if (group != null) { group.Register(this); } // OnStateChange(); // } OnStateChange(); } // protected override void OnDisable() // { // base.OnDisable(); protected override void OnDisable() { base.OnDisable(); // if (group != null) // { // group.UnRegister(this); // } // } if (group != null) { group.UnRegister(this); } } // protected override void OnDestroy() // { // #if UNITY_EDITOR // if (!Application.isPlaying) return; // #endif // FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionUnLockStateChange; // } protected override void OnDestroy() { #if UNITY_EDITOR if (!Application.isPlaying) return; #endif FuncOpen.Instance.OnFuncStateChangeEvent -= OnFunctionUnLockStateChange; } // bool invokeForce = false; bool invokeForce = false; // public void Invoke(bool _force) // { // invokeForce = _force; // OnPointerClick(null); // invokeForce = false; // } public void Invoke(bool _force) { invokeForce = _force; OnPointerClick(null); invokeForce = false; } // public override void OnPointerClick(PointerEventData eventData) // { // if (state == TitleBtnState.Locked) // { // if (OnPointClickLockFunc != null) // { // OnPointClickLockFunc(this.gameObject.name); // } // else // { // FuncOpen.Instance.ProcessorFuncErrorTip(functionId); // } // return; // } public override void OnPointerClick(PointerEventData eventData) { if (state == TitleBtnState.Locked) { if (OnPointClickLockFunc != null) { OnPointClickLockFunc(this.gameObject.name); } else { FuncOpen.Instance.ProcessorFuncErrorTip(functionId); } return; } // if (!invokeForce && state == TitleBtnState.Click) // { // if (repeatClickFunc != null) // { // repeatClickFunc(); // } // return; // } if (!invokeForce && state == TitleBtnState.Click) { if (repeatClickFunc != null) { repeatClickFunc(); } return; } // if (base.onClick != null) // { // base.onClick.Invoke(); // if (eventData != null) // { // SoundPlayer.Instance.PlayUIAudio(clickAudio); // } // } if (base.onClick != null) { base.onClick.Invoke(); if (eventData != null) { SoundPlayer.Instance.PlayUIAudio(clickAudio); } } // state = TitleBtnState.Click; // } state = TitleBtnState.Click; } // private void OnStateChange() // { // var config = useDefaultConfig ? FunctionButtonConfig.GetDefault() : m_AlternativeConfig; // if (Application.isPlaying) // { // icon.SetSprite(config.GetIconKey(state)); // } private void OnStateChange() { var config = useDefaultConfig ? FunctionButtonConfig.GetDefault() : m_AlternativeConfig; if (Application.isPlaying) { icon.SetSprite(config.GetIconKey(state)); } // title.color = config.GetFontColor(state); // title.fontSize = config.GetFontSize(state); title.color = config.GetFontColor(state); title.fontSize = config.GetFontSize(state); // if (shadow != null) // { // shadow.enabled = state == TitleBtnState.Locked || state == TitleBtnState.Normal; // } if (shadow != null) { shadow.enabled = state == TitleBtnState.Locked || state == TitleBtnState.Normal; } // if (locked != null) // { // locked.SetActive(state == TitleBtnState.Locked); // } if (locked != null) { locked.SetActive(state == TitleBtnState.Locked); } // if (group != null && state == TitleBtnState.Click) // { // group.NotifyToggleOn(this); // } // } if (group != null && state == TitleBtnState.Click) { group.NotifyToggleOn(this); } } // private void OnFunctionUnLockStateChange(int _functionId) // { // if (m_FunctionId == _functionId) // { // OnFunctionUnLockStateChange(); // } // } private void OnFunctionUnLockStateChange(int _functionId) { if (m_FunctionId == _functionId) { OnFunctionUnLockStateChange(); } } // private void OnFunctionUnLockStateChange() // { // if (m_FunctionId == 0) // { // return; // } private void OnFunctionUnLockStateChange() { if (m_FunctionId == 0) { return; } // var isOpen = m_FunctionId == -1 || FuncOpen.Instance.IsFuncOpen(m_FunctionId); // state = isOpen ? state == TitleBtnState.Click ? TitleBtnState.Click : TitleBtnState.Normal : TitleBtnState.Locked; // } var isOpen = m_FunctionId == -1 || FuncOpen.Instance.IsFuncOpen(m_FunctionId); state = isOpen ? state == TitleBtnState.Click ? TitleBtnState.Click : TitleBtnState.Normal : TitleBtnState.Locked; } // #if UNITY_EDITOR // protected override void OnValidate() // { // base.OnValidate(); // OnStateChange(); // } // #endif #if UNITY_EDITOR protected override void OnValidate() { base.OnValidate(); OnStateChange(); } #endif // } } // } } Main/Component/UI/Common/FunctionButtonGroup.cs
@@ -1,269 +1,269 @@ // //-------------------------------------------------------- // // [Author]: 第二世界 // // [ Date ]: Tuesday, October 31, 2017 // //-------------------------------------------------------- // using UnityEngine; // using System.Collections; // using System.Collections.Generic; // using UnityEngine.UI; // using UnityEngine.Events; //-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Tuesday, October 31, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using System.Collections.Generic; using UnityEngine.UI; using UnityEngine.Events; // namespace vnxbqy.UI // { namespace vnxbqy.UI { // public class FunctionButtonGroup : MonoBehaviour // { // [SerializeField] ScrollRect m_ScrollRect; // [SerializeField] RectTransform m_Container; public class FunctionButtonGroup : MonoBehaviour { [SerializeField] ScrollRect m_ScrollRect; [SerializeField] RectTransform m_Container; // public int unLockedCount { // get { // var count = 0; // foreach (var button in functionButtons.Values) // { // if (button.state != TitleBtnState.Locked) // { // count++; // } // } public int unLockedCount { get { var count = 0; foreach (var button in functionButtons.Values) { if (button.state != TitleBtnState.Locked) { count++; } } // return count; // } // } return count; } } // int currentOrder = 0; // List<int> orders = new List<int>(); // Dictionary<int, FunctionButton> functionButtons = new Dictionary<int, FunctionButton>(); int currentOrder = 0; List<int> orders = new List<int>(); Dictionary<int, FunctionButton> functionButtons = new Dictionary<int, FunctionButton>(); // public void Register(FunctionButton button) // { // functionButtons[button.order] = button; // if (!orders.Contains(button.order)) // { // orders.Add(button.order); // orders.Sort(OrderCompare); // } public void Register(FunctionButton button) { functionButtons[button.order] = button; if (!orders.Contains(button.order)) { orders.Add(button.order); orders.Sort(OrderCompare); } // if (m_ScrollRect != null) // { // m_ScrollRect.horizontal = functionButtons.Count > 5; // } // } if (m_ScrollRect != null) { m_ScrollRect.horizontal = functionButtons.Count > 5; } } // public void ChangeHorizontal(bool move) // { // if (m_ScrollRect != null) // { // m_ScrollRect.horizontal = move; // } // } public void ChangeHorizontal(bool move) { if (m_ScrollRect != null) { m_ScrollRect.horizontal = move; } } // public void ChangeHorizontalPos(float index) // { // if (m_ScrollRect != null) // { // m_ScrollRect.horizontalNormalizedPosition = index; // } // } // public void UnRegister(FunctionButton button) // { // if (functionButtons.ContainsKey(button.order)) // { // functionButtons.Remove(button.order); // } public void ChangeHorizontalPos(float index) { if (m_ScrollRect != null) { m_ScrollRect.horizontalNormalizedPosition = index; } } public void UnRegister(FunctionButton button) { if (functionButtons.ContainsKey(button.order)) { functionButtons.Remove(button.order); } // if (orders.Contains(button.order)) // { // orders.Remove(button.order); // orders.Sort(OrderCompare); // } if (orders.Contains(button.order)) { orders.Remove(button.order); orders.Sort(OrderCompare); } // if (m_ScrollRect != null) // { // m_ScrollRect.horizontal = functionButtons.Count > 5; // } // } if (m_ScrollRect != null) { m_ScrollRect.horizontal = functionButtons.Count > 5; } } // public void NotifyToggleOn(FunctionButton button) // { public void NotifyToggleOn(FunctionButton button) { // if (button.state == TitleBtnState.Click) // { // currentOrder = button.order; // for (int i = 0; i < orders.Count; i++) // { // if (!functionButtons.ContainsKey(orders[i])) // { // Debug.LogFormat("<color=#ff0000ff>{0} {1}</color>", orders[i], button.name); // } // var functionButton = functionButtons[orders[i]]; // if (functionButton != button && functionButton.state != TitleBtnState.Locked) // { // functionButton.state = TitleBtnState.Normal; // } // } // } // } if (button.state == TitleBtnState.Click) { currentOrder = button.order; for (int i = 0; i < orders.Count; i++) { if (!functionButtons.ContainsKey(orders[i])) { Debug.LogFormat("<color=#ff0000ff>{0} {1}</color>", orders[i], button.name); } var functionButton = functionButtons[orders[i]]; if (functionButton != button && functionButton.state != TitleBtnState.Locked) { functionButton.state = TitleBtnState.Normal; } } } } // public void TriggerByOrder(int targetOrder) // { // for (int i = 0; i < orders.Count; i++) // { // var order = orders[i]; // if (order == targetOrder) // { // functionButtons[order].Invoke(true); // break; // } // } // } public void TriggerByOrder(int targetOrder) { for (int i = 0; i < orders.Count; i++) { var order = orders[i]; if (order == targetOrder) { functionButtons[order].Invoke(true); break; } } } // public void TriggerLast() // { // var index = orders.IndexOf(currentOrder); // if (index < 0) // { // return; // } public void TriggerLast() { var index = orders.IndexOf(currentOrder); if (index < 0) { return; } // var loopTimes = 0; // while (loopTimes < 2) // { // index--; // if (index < 0) // { // index = orders.Count - 1; // loopTimes++; // } var loopTimes = 0; while (loopTimes < 2) { index--; if (index < 0) { index = orders.Count - 1; loopTimes++; } // var next = orders[index]; // if (functionButtons[next].state != TitleBtnState.Locked) // { // functionButtons[next].Invoke(false); // break; // } // } var next = orders[index]; if (functionButtons[next].state != TitleBtnState.Locked) { functionButtons[next].Invoke(false); break; } } // } } // public void TriggerNext() // { // var index = orders.IndexOf(currentOrder); // if (index < 0) // { // return; // } public void TriggerNext() { var index = orders.IndexOf(currentOrder); if (index < 0) { return; } // var loopTimes = 0; // while (loopTimes < 2) // { // index++; // if (index > orders.Count - 1) // { // index = 0; // loopTimes++; // } var loopTimes = 0; while (loopTimes < 2) { index++; if (index > orders.Count - 1) { index = 0; loopTimes++; } // var next = orders[index]; // if (functionButtons[next].state != TitleBtnState.Locked) // { // functionButtons[next].Invoke(false); // break; // } // } // } var next = orders[index]; if (functionButtons[next].state != TitleBtnState.Locked) { functionButtons[next].Invoke(false); break; } } } // public bool IsFirst() // { // return orders.Count > 0 && currentOrder == orders[0]; // } public bool IsFirst() { return orders.Count > 0 && currentOrder == orders[0]; } // public bool IsLast() // { // return orders.Count > 0 && currentOrder == orders[orders.Count - 1]; // } public bool IsLast() { return orders.Count > 0 && currentOrder == orders[orders.Count - 1]; } // public void GotoOrder(int order) // { // if (m_ScrollRect != null) // { // var index = orders.IndexOf(order); // if (m_ScrollRect.horizontal) // { // m_ScrollRect.horizontalNormalizedPosition = (float)index / orders.Count; // } // else if (m_ScrollRect.vertical) // { // m_ScrollRect.verticalNormalizedPosition = (float)index / orders.Count; // } // } // } public void GotoOrder(int order) { if (m_ScrollRect != null) { var index = orders.IndexOf(order); if (m_ScrollRect.horizontal) { m_ScrollRect.horizontalNormalizedPosition = (float)index / orders.Count; } else if (m_ScrollRect.vertical) { m_ScrollRect.verticalNormalizedPosition = (float)index / orders.Count; } } } // private int OrderCompare(int a, int b) // { // return a < b ? -1 : 1; // } private int OrderCompare(int a, int b) { return a < b ? -1 : 1; } // public FunctionButton AddFunction(string pattern, int order, int functionId, string title, int redpointId) // { // if (m_Container == null) // { // return null; // } public FunctionButton AddFunction(string pattern, int order, int functionId, string title, int redpointId) { if (m_Container == null) { return null; } // var instance = UIUtility.CreateWidget(pattern, string.Concat("Function_", order)); // instance.transform.SetParentEx(this.m_Container, Vector3.zero, Quaternion.identity, Vector3.one); var instance = UIUtility.CreateWidget(pattern, string.Concat("Function_", order)); instance.transform.SetParentEx(this.m_Container, Vector3.zero, Quaternion.identity, Vector3.one); // var functionButton = instance.GetComponent<FunctionButton>(); // functionButton.functionId = functionId; // functionButton.order = order; // functionButton.title.text = title; var functionButton = instance.GetComponent<FunctionButton>(); functionButton.functionId = functionId; functionButton.order = order; functionButton.title.text = title; // functionButton.group = this; // functionButton.redpoint.redpointId = redpointId; // functionButtons[order] = functionButton; functionButton.group = this; functionButton.redpoint.redpointId = redpointId; functionButtons[order] = functionButton; // functionButton.SetActive(functionButton.functionId != -1); // return functionButton; // } functionButton.SetActive(functionButton.functionId != -1); return functionButton; } // public void SetFunctionListener(int order, UnityAction callBack) // { // if (functionButtons.ContainsKey(order)) // { // functionButtons[order].SetListener(callBack); // } // } public void SetFunctionListener(int order, UnityAction callBack) { if (functionButtons.ContainsKey(order)) { functionButtons[order].SetListener(callBack); } } // public void SetFunctionButtonActive(int order, bool isShow) // { // if (functionButtons.ContainsKey(order)) // { // functionButtons[order].SetActive(isShow); // } // } public void SetFunctionButtonActive(int order, bool isShow) { if (functionButtons.ContainsKey(order)) { functionButtons[order].SetActive(isShow); } } // public RedPointState GetFunctionButtonRedPointState(int order) // { // if (functionButtons.ContainsKey(order)) // { // return RedpointCenter.Instance.GetRedpointState(functionButtons[order].redpoint.redpointId); // } public RedPointState GetFunctionButtonRedPointState(int order) { if (functionButtons.ContainsKey(order)) { return RedpointCenter.Instance.GetRedpointState(functionButtons[order].redpoint.redpointId); } // return RedPointState.None; // } return RedPointState.None; } // public FunctionButton GetFunctionBtn(int order) // { // if (functionButtons.ContainsKey(order)) // { // return functionButtons[order]; // } // return null; // } // } public FunctionButton GetFunctionBtn(int order) { if (functionButtons.ContainsKey(order)) { return functionButtons[order]; } return null; } } // } } Main/System/Skill/FlipScroll.cs
New file @@ -0,0 +1,320 @@ //-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Monday, September 11, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using UnityEngine.EventSystems; using System; namespace vnxbqy.UI { public class FlipScroll : MaskableGraphic, IBeginDragHandler, IEndDragHandler, IDragHandler { public enum FlipDirEnum { Horizon, Vertical, } private int page = 0; /// <summary> /// 当前页 /// </summary> public int Page { get { return page; } } [SerializeField] private FlipDirEnum flipType = FlipDirEnum.Horizon; public FlipDirEnum FlipType { get { return flipType; } set { flipType = value; } } [SerializeField] private bool m_Loop = false; public bool loop { get { return m_Loop; } set { m_Loop = value; } } [SerializeField] private TweenType _tweenType = TweenType.Linear; public TweenType tweenType { get { return _tweenType; } set { _tweenType = value; } } [SerializeField] private float sensitive = 5.0f; public float Sensitive { get { return sensitive; } set { sensitive = value; } } [SerializeField] public bool resetOnEnable = true; private bool tweening = false; public bool IsTweening { get { return tweening; } } [SerializeField] private float _tweenTime = 1.0f; public float TweenTime { get { return _tweenTime; } set { _tweenTime = value; } } public RectTransform presentRT; public RectTransform lastRT; private RectTransform presentFlipRT; private RectTransform lastFlipRT; public event Action<int, RectTransform> OnRefreshData; public event Action OnTweenCompt; public int pageCnt = 0; [HideInInspector] public bool locked = false; protected override void Awake() { base.Awake(); if (presentRT == null || lastRT == null) return; presentRT.SetActive(false); lastRT.SetActive(false); presentFlipRT = presentRT; lastFlipRT = lastRT; } protected override void OnEnable() { base.OnEnable(); if (presentRT == null || lastRT == null || pageCnt == 0) return; presentRT.SetActive(true); lastRT.SetActive(true); presentRT.localPosition = Vector3.zero; if (resetOnEnable) { switch (FlipType) { case FlipDirEnum.Horizon: lastRT.localPosition = rectTransform.localPosition.SetX(rectTransform.sizeDelta.x); break; case FlipDirEnum.Vertical: lastRT.localPosition = rectTransform.localPosition.SetY(-rectTransform.sizeDelta.y); break; } page = 0; } presentFlipRT = presentRT; lastFlipRT = lastRT; RefreshActive(); } private Vector2 lastPos = Vector2.zero; public void OnBeginDrag(PointerEventData eventData) { lastPos = eventData.position; } public void OnEndDrag(PointerEventData eventData) { if (IsTweening || locked) return; Vector2 nPos = lastPos - eventData.position; switch (FlipType) { case FlipDirEnum.Horizon: { if (Math.Abs(nPos.x) < sensitive) return; if (nPos.x > 0) { FlipRight(); } else { FlipLeft(); } } break; case FlipDirEnum.Vertical: { if (Math.Abs(nPos.y) < sensitive) return; Vector3 pos = Vector3.zero; if (nPos.y < 0) { FlipLeft(); } else { FlipRight(); } } break; } } protected override void OnDisable() { tweening = false; StopAllCoroutines(); base.OnDisable(); } IEnumerator TweenPosition(Vector3 lPos, Vector3 nPos, Vector3 lastRtPos) { float time = 0; Vector3 newPresentPos = Vector3.zero; Vector3 newLastPos = Vector3.zero; bool InView = false; tweening = true; while (time < _tweenTime) { float per = 0; switch (tweenType) { case TweenType.Immediate: per = 1; break; case TweenType.Linear: per = Linear(time / _tweenTime); break; case TweenType.Smooth: per = Smooth(time / _tweenTime); break; } newPresentPos = Vector3.Lerp(lPos, nPos, per); newLastPos = Vector3.Lerp(lastRtPos, Vector3.zero, per); presentFlipRT.localPosition = newPresentPos; lastFlipRT.localPosition = newLastPos; time += Time.unscaledDeltaTime; if (!InView) { InView = InViewSide(); } if (tweenType == TweenType.Immediate) { break; } yield return null; } tweening = false; presentFlipRT.localPosition = nPos; lastFlipRT.localPosition = Vector3.zero; RectTransform temp = presentFlipRT; presentFlipRT = lastFlipRT; lastFlipRT = temp; if (OnTweenCompt != null) OnTweenCompt(); } public bool InViewSide() { switch (FlipType) { case FlipDirEnum.Horizon: { if (Vector3.Distance(Vector3.zero, lastFlipRT.localPosition) < lastFlipRT.sizeDelta.x + rectTransform.sizeDelta.x) { if (OnRefreshData != null) { lastFlipRT.SetActive(true); OnRefreshData(page, lastFlipRT); } return true; } } break; case FlipDirEnum.Vertical: { if (Vector3.Distance(Vector3.zero, lastFlipRT.localPosition) < lastFlipRT.sizeDelta.y + rectTransform.sizeDelta.y) { if (OnRefreshData != null) { lastFlipRT.SetActive(true); OnRefreshData(page, lastFlipRT); } return true; } } break; } return false; } private float Linear(float val) { return Mathf.Lerp(0, 1, val); } private float Smooth(float val) { float result = Mathf.SmoothStep(0, 1, val); result = Mathf.Clamp(result, 0, 1); return result; } public void RefreshActive() { if (pageCnt == 0 || presentFlipRT == null) return; if (OnRefreshData != null) { presentFlipRT.SetActive(true); OnRefreshData(page, presentFlipRT); } } public void FlipLeft() { if (IsTweening || pageCnt == 0) return; Vector3 pos = Vector3.zero; page--; if (page < 0) { if (loop) { page = pageCnt - 1; } else { page = 0; return; } } switch (FlipType) { case FlipDirEnum.Horizon: { lastFlipRT.localPosition = rectTransform.localPosition.SetX(-rectTransform.sizeDelta.x); pos = rectTransform.localPosition.SetX(rectTransform.sizeDelta.x); } break; case FlipDirEnum.Vertical: { lastFlipRT.localPosition = rectTransform.localPosition.SetY(rectTransform.sizeDelta.y); pos = rectTransform.localPosition.SetY(-rectTransform.sizeDelta.y); } break; } StartCoroutine(TweenPosition(presentFlipRT.localPosition, pos, lastFlipRT.localPosition)); } public void FlipRight() { if (IsTweening || pageCnt == 0) return; Vector3 pos = Vector3.zero; page++; if (page >= pageCnt) { if (loop) { page = 0; } else { page = pageCnt - 1; return; } } switch (FlipType) { case FlipDirEnum.Horizon: { lastFlipRT.localPosition = rectTransform.localPosition.SetX(rectTransform.sizeDelta.x); pos = rectTransform.localPosition.SetX(-rectTransform.sizeDelta.x); } break; case FlipDirEnum.Vertical: { lastFlipRT.localPosition = rectTransform.localPosition.SetY(-rectTransform.sizeDelta.y); pos = rectTransform.localPosition.SetY(rectTransform.sizeDelta.y); } break; } StartCoroutine(TweenPosition(presentFlipRT.localPosition, pos, lastFlipRT.localPosition)); } public void OnDrag(PointerEventData eventData) { } public enum TweenType { Immediate, Linear, Smooth, } } } Main/System/Skill/FlipScroll.cs.meta
New file @@ -0,0 +1,12 @@ fileFormatVersion: 2 guid: 2398076fc4555d74e832fd67f5265819 timeCreated: 1505130007 licenseType: Free MonoImporter: serializedVersion: 2 defaultReferences: [] executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: assetBundleVariant: