From b0a5d4688f1af73b5ad03ccc2df11c9aac1523a9 Mon Sep 17 00:00:00 2001 From: yyl <yyl> Date: 星期二, 29 七月 2025 16:56:23 +0800 Subject: [PATCH] Merge branch 'master' of http://192.168.1.20:10010/r/Project_SG_scripts --- Main/Component/UI/Common/FunctionButtonGroup.cs | 491 +++++++++++++++++++++++++++--------------------------- 1 files changed, 247 insertions(+), 244 deletions(-) diff --git a/Main/Component/UI/Common/FunctionButtonGroup.cs b/Main/Component/UI/Common/FunctionButtonGroup.cs index 66b475f..3e8aee6 100644 --- a/Main/Component/UI/Common/FunctionButtonGroup.cs +++ b/Main/Component/UI/Common/FunctionButtonGroup.cs @@ -9,258 +9,261 @@ using UnityEngine.Events; using System; - public class FunctionButtonGroup : MonoBehaviour +//鍏宠仈娓告垙鐜╂硶鍔熻兘鎸夐挳锛屽鍗囨槦鍔熻兘 +public class FunctionButtonGroup : MonoBehaviour +{ + [SerializeField] ScrollRect m_ScrollRect; + [SerializeField] RectTransform m_Container; + + public int unLockedCount { - [SerializeField] ScrollRect m_ScrollRect; - [SerializeField] RectTransform m_Container; - - public int unLockedCount { - get { - var count = 0; - foreach (var button in functionButtons.Values) + get + { + var count = 0; + foreach (var button in functionButtons.Values) + { + if (button.state != TitleBtnState.Locked) { - if (button.state != TitleBtnState.Locked) - { - count++; - } - } - - return count; - } - } - - 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); - } - - 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 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 (m_ScrollRect != null) - { - m_ScrollRect.horizontal = functionButtons.Count > 5; - } - } - - 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; - } - } - } - } - - 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; - } - - 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; + count++; } } - } - - 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 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 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; - } - } - } - - 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; - } - - 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; - - functionButton.group = this; - functionButton.redpoint.redpointId = redpointId; - functionButtons[order] = functionButton; - - functionButton.SetActive(functionButton.functionId != -1); - return functionButton; - } - - public void SetFunctionListener(int order, Action callBack) - { - if (functionButtons.ContainsKey(order)) - { - functionButtons[order].SetListener(() => callBack?.Invoke()); - } - } - - 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); - } - - return RedPointState.None; - } - - public FunctionButton GetFunctionBtn(int order) - { - if (functionButtons.ContainsKey(order)) - { - return functionButtons[order]; - } - return null; + return count; } } + 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); + } + + 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 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 (m_ScrollRect != null) + { + m_ScrollRect.horizontal = functionButtons.Count > 5; + } + } + + 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; + } + } + } + } + + 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; + } + + 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; + } + } + + } + + 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 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 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; + } + } + } + + 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; + } + + 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; + + functionButton.group = this; + functionButton.redpoint.redpointId = redpointId; + functionButtons[order] = functionButton; + + functionButton.SetActive(functionButton.functionId != -1); + return functionButton; + } + + public void SetFunctionListener(int order, Action callBack) + { + if (functionButtons.ContainsKey(order)) + { + functionButtons[order].SetListener(() => callBack?.Invoke()); + } + } + + 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); + } + + return RedPointState.None; + } + + public FunctionButton GetFunctionBtn(int order) + { + if (functionButtons.ContainsKey(order)) + { + return functionButtons[order]; + } + return null; + } +} + -- Gitblit v1.8.0