少年修仙传客户端代码仓库
client_Wu Xijin
2019-04-12 9a66671e5cc3f26e19bb5cb3bb20f52eff3d33f1
UI/Common/FunctionButtonGroup.cs
@@ -12,10 +12,12 @@
    public class FunctionButtonGroup : MonoBehaviour
    {
        [SerializeField] ScrollRect m_ScrollRect;
        public int unLockedCount {
            get {
                var count = 0;
                foreach (var button in toggleButtons.Values)
                foreach (var button in functionButtons.Values)
                {
                    if (button.state != TitleBtnState.Locked)
                    {
@@ -29,57 +31,57 @@
        int currentOrder = 0;
        List<int> orders = new List<int>();
        Dictionary<int, FunctionButton> toggleButtons = new Dictionary<int, FunctionButton>();
        Dictionary<int, FunctionButton> functionButtons = new Dictionary<int, FunctionButton>();
        public void Register(FunctionButton _toggleButton)
        public void Register(FunctionButton button)
        {
            toggleButtons[_toggleButton.order] = _toggleButton;
            if (!orders.Contains(_toggleButton.order))
            functionButtons[button.order] = button;
            if (!orders.Contains(button.order))
            {
                orders.Add(_toggleButton.order);
                orders.Add(button.order);
                orders.Sort(OrderCompare);
            }
        }
        public void UnRegister(FunctionButton _toggleButton)
        public void UnRegister(FunctionButton button)
        {
            if (toggleButtons.ContainsKey(_toggleButton.order))
            if (functionButtons.ContainsKey(button.order))
            {
                toggleButtons.Remove(_toggleButton.order);
                functionButtons.Remove(button.order);
            }
            if (orders.Contains(_toggleButton.order))
            if (orders.Contains(button.order))
            {
                orders.Remove(_toggleButton.order);
                orders.Remove(button.order);
                orders.Sort(OrderCompare);
            }
        }
        public void NotifyToggleOn(FunctionButton _toggleButton)
        public void NotifyToggleOn(FunctionButton button)
        {
            if (_toggleButton.state == TitleBtnState.Click)
            if (button.state == TitleBtnState.Click)
            {
                currentOrder = _toggleButton.order;
                currentOrder = button.order;
                for (int i = 0; i < orders.Count; i++)
                {
                    var toggleButton = toggleButtons[orders[i]];
                    if (toggleButton != _toggleButton && toggleButton.state != TitleBtnState.Locked)
                    var functionButton = functionButtons[orders[i]];
                    if (functionButton != button && functionButton.state != TitleBtnState.Locked)
                    {
                        toggleButton.state = TitleBtnState.Normal;
                        functionButton.state = TitleBtnState.Normal;
                    }
                }
            }
        }
        public void TriggerByOrder(int _order)
        public void TriggerByOrder(int targetOrder)
        {
            for (int i = 0; i < orders.Count; i++)
            {
                var order = orders[i];
                if (order == _order)
                if (order == targetOrder)
                {
                    toggleButtons[order].Invoke(true);
                    functionButtons[order].Invoke(true);
                    break;
                }
            }
@@ -104,9 +106,9 @@
                }
                var next = orders[index];
                if (toggleButtons[next].state != TitleBtnState.Locked)
                if (functionButtons[next].state != TitleBtnState.Locked)
                {
                    toggleButtons[next].Invoke(false);
                    functionButtons[next].Invoke(false);
                    break;
                }
            }
@@ -132,9 +134,9 @@
                }
                var next = orders[index];
                if (toggleButtons[next].state != TitleBtnState.Locked)
                if (functionButtons[next].state != TitleBtnState.Locked)
                {
                    toggleButtons[next].Invoke(false);
                    functionButtons[next].Invoke(false);
                    break;
                }
            }
@@ -150,6 +152,22 @@
            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
                {
                    m_ScrollRect.verticalNormalizedPosition = (float)index / orders.Count;
                }
            }
        }
        private int OrderCompare(int a, int b)
        {
            return a < b ? -1 : 1;