hch
8 天以前 1597500ffb8817259fa1c508fc2aeff79bb80770
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
/// <summary>
/// 多页签界面,管理子界面
/// </summary>
public abstract class FunctionsBaseWin : UIBase
{
    // 标签按钮组
    public Button[] tabButtons;
 
    // 当前打开的子界面
    protected UIBase currentSubUI;
 
    /// <summary>
    /// 初始化组件
    /// </summary>
    protected override void InitComponent()
    {
        base.InitComponent();
 
        // 初始化UI组件事件
        InitButtonEvents();
    }
    protected override void OnPreOpen()
    {
        // 默认选中第一个标签
        SelectBottomTab(functionOrder);
 
    }
 
    protected override void OnPreClose()
    {
        CloseCurrentSubUI();
    }
 
 
 
    /// <summary>
    /// 初始化UI组件事件
    /// </summary>
    private void InitButtonEvents()
    {
        // 初始化底部按钮
        for (int i = 0; i < tabButtons.Length; i++)
        {
            int index = i;
            tabButtons[i].AddListener(() =>
            {
                OnTabButtonClicked(index);
            });
        }
 
    }
 
 
 
    /// <summary>
    /// 选择标签
    /// </summary>
    protected void SelectBottomTab(int index)
    {
        // 如果点击当前已选中的标签,不做处理
        if (functionOrder == index && currentSubUI != null)
        {
            return;
        }
 
        // 更新当前选中的标签索引
        functionOrder = index;
 
        // 更新按钮状态
        UpdateButtonsState();
 
        // 关闭当前打开的子界面
        CloseCurrentSubUI();
 
        // 根据选中的标签打开对应的界面
        OpenSubUIByTabIndex();
    }
 
 
    /// <summary>
    /// 关闭当前打开的子界面
    /// </summary>
    protected void CloseCurrentSubUI()
    {
        if (currentSubUI != null)
        {
            // 关闭当前界面
            currentSubUI.CloseWindow();
            currentSubUI = null;
        }
    }
 
 
    /// <summary>
    /// 更新按钮状态
    /// </summary>
    protected abstract void UpdateButtonsState();
 
    /// <summary>
    /// 根据标签索引打开对应的子界面
    /// </summary>
    protected abstract void OpenSubUIByTabIndex();
 
 
    /// <summary>
    /// 标签按钮点击
    /// </summary>
    protected virtual void OnTabButtonClicked(int index)
    {
        SelectBottomTab(index);
    }
}