| | |
| | | using UnityEngine.UI; |
| | | |
| | | /// <summary> |
| | | /// 游戏主界面 |
| | | /// 游戏主界面底部功能按钮 |
| | | /// </summary> |
| | | public class MainWin : UIBase |
| | | { |
| | | public GameObject windowBackground; |
| | | |
| | | // 底部按钮组 |
| | | public Button[] bottomTabButtons; |
| | | |
| | | private GameObject[] bottomTabEffects; |
| | | |
| | | // 当前选中的底部标签索引 |
| | | private int currentTabIndex = 0; |
| | |
| | | |
| | | } |
| | | |
| | | protected override void OnOpen() |
| | | public override void Refresh() |
| | | { |
| | | base.OnOpen(); |
| | | |
| | | UpdateCurrency(); |
| | | } |
| | | |
| | | protected override void OnPreOpen() |
| | | { |
| | | // 默认选中第一个标签 |
| | | SelectBottomTab(0); |
| | | |
| | | // 刷新UI |
| | | Refresh(); |
| | | } |
| | | |
| | | public override void Refresh() |
| | | { |
| | | UpdatePlayerInfo(); |
| | | UpdateCurrency(); |
| | | } |
| | | |
| | | protected override void OnPreOpen() |
| | | { |
| | | base.OnPreOpen(); |
| | | bottomTabEffects = new GameObject[bottomTabButtons.Length]; |
| | | for (int i = 0; i < bottomTabButtons.Length; i++) |
| | | { |
| | | bottomTabEffects[i] = PlayUIEffect(1004, bottomTabButtons[i].transform, false); |
| | | } |
| | | } |
| | | |
| | | protected override void OnPreClose() |
| | | { |
| | | base.OnPreClose(); |
| | | foreach (var effectGO in bottomTabEffects) |
| | | { |
| | | DestroyImmediate(effectGO); |
| | | } |
| | | bottomTabEffects = null; |
| | | } |
| | | // protected override void OnPreClose() |
| | | // { |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// 更新玩家信息 |
| | | /// </summary> |
| | | private void UpdatePlayerInfo() |
| | | { |
| | | // 从玩家数据中获取信息并更新UI |
| | | // 例如: |
| | | // playerNameText.text = PlayerData.Instance.Name; |
| | | // playerLevelText.text = "Lv." + PlayerData.Instance.Level; |
| | | // powerText.text = PlayerData.Instance.Power.ToString(); |
| | | // expSlider.value = PlayerData.Instance.ExpRatio; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 更新货币信息 |
| | |
| | | /// </summary> |
| | | private void OnBottomTabButtonClicked(int index) |
| | | { |
| | | if (index == 0) |
| | | { |
| | | if (currentSubUI != null && currentSubUI.name == "HomeWin") |
| | | { |
| | | //打开主界面的情况下再点击按钮,执行攻击逻辑 |
| | | } |
| | | } |
| | | SelectBottomTab(index); |
| | | } |
| | | |
| | |
| | | // 遍历所有按钮,设置选中状态 |
| | | for (int i = 0; i < bottomTabButtons.Length; i++) |
| | | { |
| | | // 这里可以根据是否选中设置按钮的视觉效果 |
| | | // 例如:改变图片、颜色等 |
| | | // bottomTabButtons[i].GetComponent<Image>().color = (i == currentTabIndex) ? Color.blue : Color.white; |
| | | |
| | | // 或者激活/禁用选中图标 |
| | | bottomTabButtons[i].image.color = (i == currentTabIndex) ? Color.white : Color.gray; |
| | | // bottomTabButtons[i].image.color = (i == currentTabIndex) ? Color.white : Color.gray; |
| | | } |
| | | } |
| | | |
| | |
| | | { |
| | | |
| | | Debug.Log("打开子界面 : " + index); |
| | | // 主城 阵容 同盟 福利 冒险 |
| | | windowBackground.SetActive(index != 4); |
| | | // 主城 内政 武将 挑战 公会 |
| | | //根据索引打开不同的界面 |
| | | switch (index) |
| | | { |
| | | case 0: |
| | | // 例如:打开主页界面 |
| | | // currentSubUI = UIManager.Instance.OpenUI<HomeUI>(); |
| | | // 打开主页界面 |
| | | currentSubUI = UIManager.Instance.OpenWindow<HomeWin>(); |
| | | Debug.Log("打开主城界面"); |
| | | break; |
| | | case 1: |
| | | // 例如:打开角色界面 |
| | | // currentSubUI = UIManager.Instance.OpenUI<CharacterUI>(); |
| | | Debug.Log("打开阵容界面"); |
| | | break; |
| | | case 2: |
| | | // 例如:打开背包界面 |
| | | // currentSubUI = UIManager.Instance.OpenUI<BagUI>(); |
| | | Debug.Log("打开同盟界面"); |
| | | break; |
| | | case 3: |
| | | // 例如:打开任务界面 |
| | | // currentSubUI = UIManager.Instance.OpenUI<QuestUI>(); |
| | | Debug.Log("打开福利界面"); |
| | | break; |
| | | case 4: |
| | | // 例如:打开设置界面 |
| | | currentSubUI = UIManager.Instance.OpenWindow<PlaceWin>(); |
| | | //currentSubUI = UIManager.Instance.OpenWindow<PlaceWin>(); |
| | | Debug.Log("打开冒险界面"); |
| | | break; |
| | | default: |