├── BasicUI_Levels ├── Atomospheres.cs ├── ButtonListener.cs ├── ButtonTextUpdater.cs ├── FourLevelButton.cs ├── FourthListner.cs ├── LevelManager.cs ├── OneLevelButton.cs ├── SecondButtonTextUpdater.cs ├── SecondLevelButton.cs ├── SecondListner.cs ├── ThirdButtonTextUpdater.cs ├── ThirdLevelButton.cs └── ThirdListner.cs ├── LICENSE └── README.md /BasicUI_Levels/Atomospheres.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | 4 | 5 | public class Atomospheres : MonoBehaviour 6 | { 7 | //这里认为用一张透明程度很高的image就代表氛围灯,只是举一个按钮触发事件的例子 8 | void Start() 9 | { 10 | HideAllImages(); 11 | } 12 | public Image image1; 13 | public Image image2; 14 | public Image image3; 15 | 16 | public void ShowImage1() 17 | { 18 | image1.gameObject.SetActive(true); 19 | image2.gameObject.SetActive(false); 20 | image3.gameObject.SetActive(false); 21 | } 22 | 23 | public void ShowImage2() 24 | { 25 | image1.gameObject.SetActive(false); 26 | image2.gameObject.SetActive(true); 27 | image3.gameObject.SetActive(false); 28 | } 29 | 30 | public void ShowImage3() 31 | { 32 | image1.gameObject.SetActive(false); 33 | image2.gameObject.SetActive(false); 34 | image3.gameObject.SetActive(true); 35 | } 36 | 37 | public void HideAllImages() 38 | { 39 | image1.gameObject.SetActive(false); 40 | image2.gameObject.SetActive(false); 41 | image3.gameObject.SetActive(false); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /BasicUI_Levels/ButtonListener.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | //这是第一层的界面按钮点击事件集 4 | public class ButtonToggle : MonoBehaviour 5 | { 6 | // 存储按钮的选中状态 7 | public LevelManager levelManager; 8 | public ButtonTextUpdater buttonTextUpdater; 9 | public Atomospheres atomosphere; 10 | private bool button1Selected = false; 11 | private bool button2Selected = false; 12 | private bool button3Selected = false; 13 | 14 | public GameObject secondlevelgroup; 15 | public GameObject thirdlevelgroup; 16 | public GameObject fifthlevelgroup; 17 | public GameObject fourthlevelgroup; 18 | public SecondListener secondlister; 19 | 20 | 21 | 22 | // 存储上一个选中的按钮 23 | private int lastSelectedButton = -1; // -1表示没有按钮被选中 24 | 25 | // 按钮引用 26 | public Button button1; //建设 27 | public Button button2; //运营 28 | public Button button3; 29 | 30 | void Start() 31 | { 32 | // 为按钮添加点击事件监听器 33 | button1.onClick.AddListener(() => ToggleButton(1)); 34 | button2.onClick.AddListener(() => ToggleButton(2)); 35 | button3.onClick.AddListener(() => ToggleButton(3)); 36 | HideSecondLevelGroup(); 37 | lastSelectedButton=-1; 38 | levelManager.SetFirstLevel(0); 39 | levelManager.SetSecondLevel(0); 40 | levelManager.SetThirdLevel(0); 41 | levelManager.SetFourthLevel(0); 42 | 43 | } 44 | 45 | private void ShowSecondLevelGroup() 46 | { 47 | if (secondlevelgroup != null) 48 | { 49 | secondlevelgroup.SetActive(true); 50 | } 51 | 52 | } 53 | 54 | private void HideSecondLevelGroup() 55 | { 56 | secondlister.SecondClearButtons(); 57 | if (secondlevelgroup != null) 58 | { 59 | secondlevelgroup.SetActive(false); 60 | } 61 | if (thirdlevelgroup != null) 62 | { 63 | thirdlevelgroup.SetActive(false); 64 | } 65 | if (fourthlevelgroup != null) 66 | { 67 | fourthlevelgroup.SetActive(false); 68 | } 69 | if (fifthlevelgroup != null) 70 | { 71 | fifthlevelgroup.SetActive(false); 72 | } 73 | } 74 | 75 | // 切换按钮状态并调用相应的函数 76 | private void ToggleButton(int buttonNumber) 77 | { 78 | // 如果当前点击的按钮与上一个点击的按钮不相同,先取消上一个按钮的选中状态 79 | if (lastSelectedButton != -1 && lastSelectedButton != buttonNumber) 80 | { 81 | CancelLastSelectedButton(lastSelectedButton); 82 | } 83 | 84 | // 切换当前按钮的状态 85 | switch (buttonNumber) 86 | { 87 | case 1: 88 | button1Selected = !button1Selected; 89 | if (button1Selected) 90 | Button1Selected(); 91 | else 92 | Button1Unselected(); 93 | break; 94 | case 2: 95 | button2Selected = !button2Selected; 96 | if (button2Selected) 97 | Button2Selected(); 98 | else 99 | Button2Unselected(); 100 | break; 101 | // case 3: 102 | // button3Selected = !button3Selected; 103 | // if (button3Selected) 104 | // Button3Selected(); 105 | // else 106 | // Button3Unselected(); 107 | // break; 108 | } 109 | 110 | // 更新上一个选中的按钮 111 | lastSelectedButton = buttonNumber; 112 | } 113 | 114 | // 取消上一个选中的按钮的选中状态 115 | private void CancelLastSelectedButton(int buttonNumber) 116 | { 117 | switch (buttonNumber) 118 | { 119 | case 1: 120 | button1Selected = false; 121 | Button1Unselected(); 122 | break; 123 | case 2: 124 | button2Selected = false; 125 | Button2Unselected(); 126 | break; 127 | 128 | } 129 | } 130 | 131 | // 按钮1被选中时调用的函数 132 | private void Button1Selected() 133 | { 134 | levelManager.SetFirstLevel(1); 135 | ShowSecondLevelGroup(); 136 | atomosphere.ShowImage1();//氛围灯插入,当然这里也可以加别的触发的函数 137 | buttonTextUpdater.UpdateButtonTexts("AAA", "BBB", "CCC", "DDD", ""); 138 | } 139 | 140 | // 按钮1取消选中时调用的函数 141 | private void Button1Unselected() 142 | { 143 | levelManager.SetFirstLevel(0); 144 | HideSecondLevelGroup(); 145 | atomosphere.HideAllImages(); 146 | } 147 | 148 | // 按钮2被选中时调用的函数 149 | private void Button2Selected() 150 | { 151 | levelManager.SetFirstLevel(2); 152 | ShowSecondLevelGroup(); 153 | buttonTextUpdater.UpdateButtonTexts("AAA", "BBB", "CCC", "DDD", ""); 154 | //这里有个空代表会有一个按钮不显示 155 | atomosphere.ShowImage2(); 156 | //Debug.Log("FirstLevel is set to: " + levelManager.GetFirstLevel()); 157 | } 158 | 159 | // 按钮2取消选中时调用的函数 160 | private void Button2Unselected() 161 | { 162 | levelManager.SetFirstLevel(0); 163 | HideSecondLevelGroup(); 164 | atomosphere.HideAllImages(); 165 | } 166 | //其它按钮点击中和取消也相应如上 167 | 168 | } -------------------------------------------------------------------------------- /BasicUI_Levels/ButtonTextUpdater.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using TMPro; // 引入TextMeshPro命名空间 3 | using UnityEngine.UI; 4 | //这个是用来控制点击一级界面后二级界面的改变 5 | public class ButtonTextUpdater : MonoBehaviour 6 | { 7 | public Button button1; 8 | public Button button2; 9 | public Button button3; 10 | public Button button4; 11 | public Button button5; 12 | 13 | // 五个按钮对应的TextMeshPro文本 14 | public TextMeshProUGUI buttonText1; 15 | public TextMeshProUGUI buttonText2; 16 | public TextMeshProUGUI buttonText3; 17 | public TextMeshProUGUI buttonText4; 18 | public TextMeshProUGUI buttonText5; 19 | 20 | // 更新按钮文本并控制其显示或隐藏 21 | public void UpdateButtonTexts(string text1, string text2, string text3, string text4, string text5) 22 | { 23 | // 处理第一个按钮 24 | if (!string.IsNullOrEmpty(text1)) 25 | { 26 | buttonText1.text = text1; 27 | button1.gameObject.SetActive(true); // 显示按钮 28 | } 29 | else 30 | { 31 | button1.gameObject.SetActive(false); // 隐藏按钮 32 | } 33 | 34 | // 处理第二个按钮 35 | if (!string.IsNullOrEmpty(text2)) 36 | { 37 | buttonText2.text = text2; 38 | button2.gameObject.SetActive(true); // 显示按钮 39 | } 40 | else 41 | { 42 | button2.gameObject.SetActive(false); // 隐藏按钮 43 | } 44 | 45 | // 处理第三个按钮 46 | if (!string.IsNullOrEmpty(text3)) 47 | { 48 | buttonText3.text = text3; 49 | button3.gameObject.SetActive(true); // 显示按钮 50 | } 51 | else 52 | { 53 | button3.gameObject.SetActive(false); // 隐藏按钮 54 | } 55 | 56 | // 处理第四个按钮 57 | if (!string.IsNullOrEmpty(text4)) 58 | { 59 | buttonText4.text = text4; 60 | button4.gameObject.SetActive(true); // 显示按钮 61 | } 62 | else 63 | { 64 | button4.gameObject.SetActive(false); // 隐藏按钮 65 | } 66 | 67 | // 处理第五个按钮 68 | if (!string.IsNullOrEmpty(text5)) 69 | { 70 | buttonText5.text = text5; 71 | button5.gameObject.SetActive(true); // 显示按钮 72 | } 73 | else 74 | { 75 | button5.gameObject.SetActive(false); // 隐藏按钮 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /BasicUI_Levels/FourLevelButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; // 引入UI命名空间 3 | using TMPro; 4 | using UnityEngine.EventSystems; // 引入事件系统命名空间 5 | //有关于第四层元素的颜色与选中控制 6 | //颜色可以调 7 | //注意,任何函数请前往ThirdButtonListner(第三层的按钮控制) 8 | public class FourLevelButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler 9 | { 10 | public Color normalColor = Color.gray; // 正常状态的颜色(灰色) 11 | public Color hoverColor = Color.yellow; // 鼠标悬停时的颜色(黄色) 12 | public Color selectedColor = Color.red; // 选中状态的颜色(红色) 13 | 14 | private Image buttonImage; // 按钮的Image组件 15 | private TMP_Text buttonText; // 按钮的文本组件(TextMesh Pro) 16 | private bool isSelected = false; // 选中状态 17 | private FourLevelButton[] allButtons; // 所有按钮的引用 18 | 19 | // 新增字段,用于存储按钮的点击事件 20 | public System.Action OnButtonClick; 21 | 22 | void Awake() 23 | { 24 | // 获取按钮的Image组件 25 | buttonImage = GetComponent(); 26 | // 获取子物体中的 TMP_Text 组件 27 | buttonText = GetComponentInChildren(); 28 | 29 | // 错误检查:确保按钮的文本组件存在 30 | if (buttonText == null) 31 | { 32 | Debug.LogError("TMP_Text component not found in button prefab."); 33 | } 34 | 35 | // 获取场景中所有 FourLevelButton 组件 36 | allButtons = FindObjectsOfType(); 37 | 38 | // 初始时设置按钮颜色为正常颜色 39 | buttonImage.color = normalColor; 40 | } 41 | 42 | // 鼠标进入按钮区域时调用 43 | public void OnPointerEnter(PointerEventData eventData) 44 | { 45 | // 如果按钮未选中,鼠标悬停时改变颜色为黄色 46 | if (!isSelected) 47 | { 48 | buttonImage.color = hoverColor; 49 | } 50 | } 51 | 52 | // 鼠标离开按钮区域时调用 53 | public void OnPointerExit(PointerEventData eventData) 54 | { 55 | // 如果按钮未选中,恢复为正常颜色 56 | if (!isSelected) 57 | { 58 | buttonImage.color = normalColor; 59 | } 60 | } 61 | 62 | // 按钮点击时调用 63 | public void OnPointerClick(PointerEventData eventData) 64 | { 65 | // 点击新按钮时,首先取消所有按钮的选中状态并恢复为正常颜色 66 | foreach (FourLevelButton button in allButtons) 67 | { 68 | if (button != this) // 不影响当前点击的按钮 69 | { 70 | button.isSelected = false; // 取消选中状态 71 | button.buttonImage.color = normalColor; // 恢复为正常颜色 72 | } 73 | } 74 | 75 | // 只有点击的按钮会变为选中状态,变红色 76 | if (!isSelected) 77 | { 78 | isSelected = true; 79 | buttonImage.color = selectedColor; // 改为红色 80 | } 81 | else 82 | { 83 | // 如果按钮已经是选中的状态,则取消选中 84 | isSelected = false; 85 | buttonImage.color = normalColor; // 恢复为灰色 86 | } 87 | 88 | // 执行按钮的点击事件(如果有的话) 89 | OnButtonClick?.Invoke(); 90 | } 91 | 92 | // 设置按钮文本 93 | public void SetButtonText(string text) 94 | { 95 | if (buttonText != null) 96 | { 97 | buttonText.text = text; 98 | } 99 | else 100 | { 101 | Debug.LogError("TMP_Text component is not assigned."); 102 | } 103 | } 104 | void OnDisable() 105 | { 106 | // 如果按钮处于选中状态,取消选中并恢复为正常颜色 107 | if (isSelected) 108 | { 109 | isSelected = false; 110 | buttonImage.color = normalColor; // 恢复为正常颜色 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /BasicUI_Levels/FourthListner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | //第四层按钮点击事件集,注意这里触发的第五层界面不是真的界面,而是非交互界面显示 4 | public class FourthListner : MonoBehaviour 5 | { 6 | public LevelManager levelManager; 7 | private bool button1Selected = false; 8 | private bool button2Selected = false; 9 | public GameObject fifthlevelgroup; 10 | private int lastSelectedButton = -1; // -1表示没有按钮被选中 11 | public Button FourthButton1; 12 | public Button FourthButton2; 13 | private int PageOneCondition; //第一层的序号是多少 14 | private int PageTwoCondition; 15 | private int PageThreeCondition; 16 | void Start() 17 | { 18 | // 为按钮添加点击事件监听器 19 | FourthButton1.onClick.AddListener(() => ToggleButton(1)); 20 | FourthButton2.onClick.AddListener(() => ToggleButton(2)); 21 | HideFifthLevelGroup(); 22 | 23 | } 24 | //这里是没有fifth的,fifth是不定式的 25 | private void HideFifthLevelGroup() 26 | { 27 | if (fifthlevelgroup != null) 28 | { 29 | fifthlevelgroup.SetActive(false); 30 | } 31 | } 32 | private void ToggleButton(int buttonNumber) 33 | { 34 | // 如果当前点击的按钮与上一个点击的按钮不相同,先取消上一个按钮的选中状态 35 | if (lastSelectedButton != -1 && lastSelectedButton != buttonNumber) 36 | { 37 | CancelLastSelectedButton(lastSelectedButton); 38 | } 39 | 40 | // 切换当前按钮的状态 41 | switch (buttonNumber) 42 | { 43 | case 1: 44 | button1Selected = !button1Selected; 45 | if (button1Selected) 46 | Button1Selected(); 47 | else 48 | Button1Unselected(); 49 | break; 50 | case 2: 51 | button2Selected = !button2Selected; 52 | if (button2Selected) 53 | Button2Selected(); 54 | else 55 | Button2Unselected(); 56 | break; 57 | 58 | } 59 | lastSelectedButton = buttonNumber; 60 | } 61 | private void CancelLastSelectedButton(int buttonNumber) 62 | { 63 | switch (buttonNumber) 64 | { 65 | case 1: 66 | button1Selected = false; 67 | Button1Unselected(); 68 | break; 69 | case 2: 70 | button2Selected = false; 71 | Button2Unselected(); 72 | break; 73 | 74 | } 75 | } 76 | private void Button1Selected() 77 | { 78 | levelManager.SetFourthLevel(1); 79 | //没有特定的show了 80 | PageOneCondition=levelManager.GetFirstLevel(); 81 | PageTwoCondition=levelManager.GetSecondLevel(); 82 | PageThreeCondition=levelManager.GetThirdLevel(); 83 | //根据三个去决定 84 | } 85 | private void Button1Unselected() 86 | { 87 | levelManager.SetFourthLevel(0); 88 | HideFifthLevelGroup(); 89 | } 90 | private void Button2Selected() 91 | { 92 | levelManager.SetFourthLevel(2); 93 | //没有特定的show了 94 | PageOneCondition=levelManager.GetFirstLevel(); 95 | PageTwoCondition=levelManager.GetSecondLevel(); 96 | PageThreeCondition=levelManager.GetThirdLevel(); 97 | //根据三个去决定 98 | } 99 | private void Button2Unselected() 100 | { 101 | levelManager.SetFourthLevel(0); 102 | HideFifthLevelGroup(); 103 | } 104 | 105 | public void FourthClearButtons() 106 | { 107 | button1Selected=false; 108 | button2Selected=false; 109 | lastSelectedButton=-1; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /BasicUI_Levels/LevelManager.cs: -------------------------------------------------------------------------------- 1 | //这是一个很重要的文件 2 | //任何涉及到4级界面按钮的操作 3 | //都需要set和get这里面的变量来决定 4 | //到底是在用什么 5 | using UnityEngine; 6 | 7 | public class LevelManager : MonoBehaviour 8 | { 9 | private int firstLevel; 10 | private int secondLevel; 11 | private int thirdLevel; 12 | private int fourthLevel; 13 | 14 | // 获取 firstLevel 的方法 15 | public int GetFirstLevel() 16 | { 17 | return firstLevel; 18 | } 19 | 20 | // 设置 firstLevel 的方法 21 | public void SetFirstLevel(int value) 22 | { 23 | firstLevel = value; 24 | } 25 | 26 | // 获取 secondLevel 的方法 27 | public int GetSecondLevel() 28 | { 29 | return secondLevel; 30 | } 31 | 32 | // 设置 secondLevel 的方法 33 | public void SetSecondLevel(int value) 34 | { 35 | secondLevel = value; 36 | } 37 | 38 | // 获取 thirdLevel 的方法 39 | public int GetThirdLevel() 40 | { 41 | return thirdLevel; 42 | } 43 | 44 | // 设置 thirdLevel 的方法 45 | public void SetThirdLevel(int value) 46 | { 47 | thirdLevel = value; 48 | } 49 | 50 | // 获取 fourthLevel 的方法 51 | public int GetFourthLevel() 52 | { 53 | return fourthLevel; 54 | } 55 | 56 | // 设置 fourthLevel 的方法 57 | public void SetFourthLevel(int value) 58 | { 59 | fourthLevel = value; 60 | } 61 | } -------------------------------------------------------------------------------- /BasicUI_Levels/OneLevelButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; // 引入UI命名空间 3 | using TMPro; 4 | using UnityEngine.EventSystems; // 引入事件系统命名空间 5 | //有关于第一层元素的颜色与选中控制 6 | //注意,任何函数请前往ButtonListner 7 | public class OneLevelButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler 8 | { 9 | public Color normalColor = Color.gray; // 正常状态的颜色(灰色) 10 | public Color hoverColor = Color.yellow; // 鼠标悬停时的颜色(黄色) 11 | public Color selectedColor = Color.red; // 选中状态的颜色(红色) 12 | 13 | private Image buttonImage; // 按钮的Image组件 14 | private TMP_Text buttonText; // 按钮的文本组件(TextMesh Pro) 15 | private bool isSelected = false; // 选中状态 16 | private OneLevelButton[] allButtons; // 所有按钮的引用 17 | 18 | // 新增字段,用于存储按钮的点击事件 19 | public System.Action OnButtonClick; 20 | 21 | void Awake() 22 | { 23 | // 获取按钮的Image组件 24 | buttonImage = GetComponent(); 25 | // 获取子物体中的 TMP_Text 组件 26 | buttonText = GetComponentInChildren(); 27 | 28 | // 错误检查:确保按钮的文本组件存在 29 | if (buttonText == null) 30 | { 31 | Debug.LogError("TMP_Text component not found in button prefab."); 32 | } 33 | 34 | // 获取场景中所有 OneLevelButton 组件 35 | allButtons = FindObjectsOfType(); 36 | 37 | // 初始时设置按钮颜色为正常颜色 38 | buttonImage.color = normalColor; 39 | } 40 | 41 | // 鼠标进入按钮区域时调用 42 | public void OnPointerEnter(PointerEventData eventData) 43 | { 44 | // 如果按钮未选中,鼠标悬停时改变颜色为黄色 45 | if (!isSelected) 46 | { 47 | buttonImage.color = hoverColor; 48 | } 49 | } 50 | 51 | // 鼠标离开按钮区域时调用 52 | public void OnPointerExit(PointerEventData eventData) 53 | { 54 | // 如果按钮未选中,恢复为正常颜色 55 | if (!isSelected) 56 | { 57 | buttonImage.color = normalColor; 58 | } 59 | } 60 | 61 | // 按钮点击时调用 62 | public void OnPointerClick(PointerEventData eventData) 63 | { 64 | // 点击新按钮时,首先取消所有按钮的选中状态并恢复为正常颜色 65 | foreach (OneLevelButton button in allButtons) 66 | { 67 | if (button != this) // 不影响当前点击的按钮 68 | { 69 | button.isSelected = false; // 取消选中状态 70 | button.buttonImage.color = normalColor; // 恢复为正常颜色 71 | } 72 | } 73 | 74 | // 只有点击的按钮会变为选中状态,变红色 75 | if (!isSelected) 76 | { 77 | isSelected = true; 78 | buttonImage.color = selectedColor; // 改为红色 79 | } 80 | else 81 | { 82 | // 如果按钮已经是选中的状态,则取消选中 83 | isSelected = false; 84 | buttonImage.color = normalColor; // 恢复为灰色 85 | } 86 | 87 | // 执行按钮的点击事件(如果有的话) 88 | OnButtonClick?.Invoke(); 89 | } 90 | 91 | // 设置按钮文本 92 | public void SetButtonText(string text) 93 | { 94 | if (buttonText != null) 95 | { 96 | buttonText.text = text; 97 | } 98 | else 99 | { 100 | Debug.LogError("TMP_Text component is not assigned."); 101 | } 102 | } 103 | } -------------------------------------------------------------------------------- /BasicUI_Levels/SecondButtonTextUpdater.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using TMPro; // 引入TextMeshPro命名空间 3 | using UnityEngine.UI; 4 | //这个是用来控制点击二级界面后三级界面的改变 5 | public class SecondButtonTextUpdater : MonoBehaviour 6 | { 7 | public Button button1_third; 8 | public Button button2_third; 9 | public Button button3_third; 10 | public Button button4_third; 11 | public Button button5_third; 12 | 13 | // 五个按钮对应的TextMeshPro文本 14 | public TextMeshProUGUI buttonText1_third; 15 | public TextMeshProUGUI buttonText2_third; 16 | public TextMeshProUGUI buttonText3_third; 17 | public TextMeshProUGUI buttonText4_third; 18 | public TextMeshProUGUI buttonText5_third; 19 | 20 | // 更新按钮文本并控制其显示或隐藏 21 | public void UpdateButtonTexts(string text1, string text2, string text3, string text4, string text5) 22 | { 23 | // 处理第一个按钮 24 | if (!string.IsNullOrEmpty(text1)) 25 | { 26 | buttonText1_third.text = text1; 27 | button1_third.gameObject.SetActive(true); // 显示按钮 28 | } 29 | else 30 | { 31 | button1_third.gameObject.SetActive(false); // 隐藏按钮 32 | } 33 | 34 | // 处理第二个按钮 35 | if (!string.IsNullOrEmpty(text2)) 36 | { 37 | buttonText2_third.text = text2; 38 | button2_third.gameObject.SetActive(true); // 显示按钮 39 | } 40 | else 41 | { 42 | button2_third.gameObject.SetActive(false); // 隐藏按钮 43 | } 44 | 45 | // 处理第三个按钮 46 | if (!string.IsNullOrEmpty(text3)) 47 | { 48 | buttonText3_third.text = text3; 49 | button3_third.gameObject.SetActive(true); // 显示按钮 50 | } 51 | else 52 | { 53 | button3_third.gameObject.SetActive(false); // 隐藏按钮 54 | } 55 | 56 | // 处理第四个按钮 57 | if (!string.IsNullOrEmpty(text4)) 58 | { 59 | buttonText4_third.text = text4; 60 | button4_third.gameObject.SetActive(true); // 显示按钮 61 | } 62 | else 63 | { 64 | button4_third.gameObject.SetActive(false); // 隐藏按钮 65 | } 66 | 67 | // 处理第五个按钮 68 | if (!string.IsNullOrEmpty(text5)) 69 | { 70 | buttonText5_third.text = text5; 71 | button5_third.gameObject.SetActive(true); // 显示按钮 72 | } 73 | else 74 | { 75 | button5_third.gameObject.SetActive(false); // 隐藏按钮 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /BasicUI_Levels/SecondLevelButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; // 引入UI命名空间 3 | using TMPro; 4 | using UnityEngine.EventSystems; // 引入事件系统命名空间 5 | //有关于第二层元素的颜色与选中控制 6 | //注意,任何函数请前往ButtonListner 7 | public class SecondLevelButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler 8 | { 9 | public Color normalColor = Color.gray; // 正常状态的颜色(灰色) 10 | public Color hoverColor = Color.yellow; // 鼠标悬停时的颜色(黄色) 11 | public Color selectedColor = Color.red; // 选中状态的颜色(红色) 12 | 13 | private Image buttonImage; // 按钮的Image组件 14 | private TMP_Text buttonText; // 按钮的文本组件(TextMesh Pro) 15 | private bool isSelected = false; // 选中状态 16 | private SecondLevelButton[] allButtons; // 所有按钮的引用 17 | 18 | // 新增字段,用于存储按钮的点击事件 19 | public System.Action OnButtonClick; 20 | 21 | void Awake() 22 | { 23 | // 获取按钮的Image组件 24 | buttonImage = GetComponent(); 25 | // 获取子物体中的 TMP_Text 组件 26 | buttonText = GetComponentInChildren(); 27 | 28 | // 错误检查:确保按钮的文本组件存在 29 | if (buttonText == null) 30 | { 31 | Debug.LogError("TMP_Text component not found in button prefab."); 32 | } 33 | 34 | // 获取场景中所有 OneLevelButton 组件 35 | allButtons = FindObjectsOfType(); 36 | 37 | // 初始时设置按钮颜色为正常颜色 38 | buttonImage.color = normalColor; 39 | } 40 | 41 | // 鼠标进入按钮区域时调用 42 | public void OnPointerEnter(PointerEventData eventData) 43 | { 44 | // 如果按钮未选中,鼠标悬停时改变颜色为黄色 45 | if (!isSelected) 46 | { 47 | buttonImage.color = hoverColor; 48 | } 49 | } 50 | 51 | // 鼠标离开按钮区域时调用 52 | public void OnPointerExit(PointerEventData eventData) 53 | { 54 | // 如果按钮未选中,恢复为正常颜色 55 | if (!isSelected) 56 | { 57 | buttonImage.color = normalColor; 58 | } 59 | } 60 | 61 | // 按钮点击时调用 62 | public void OnPointerClick(PointerEventData eventData) 63 | { 64 | // 点击新按钮时,首先取消所有按钮的选中状态并恢复为正常颜色 65 | foreach (SecondLevelButton button in allButtons) 66 | { 67 | if (button != this) // 不影响当前点击的按钮 68 | { 69 | button.isSelected = false; // 取消选中状态 70 | button.buttonImage.color = normalColor; // 恢复为正常颜色 71 | } 72 | } 73 | 74 | // 只有点击的按钮会变为选中状态,变粉色 75 | if (!isSelected) 76 | { 77 | isSelected = true; 78 | buttonImage.color = selectedColor; 79 | } 80 | else 81 | { 82 | // 如果按钮已经是选中的状态,则取消选中 83 | isSelected = false; 84 | buttonImage.color = normalColor; // 恢复为灰色 85 | } 86 | 87 | // 执行按钮的点击事件(如果有的话) 88 | OnButtonClick?.Invoke(); 89 | } 90 | 91 | // 设置按钮文本 92 | public void SetButtonText(string text) 93 | { 94 | if (buttonText != null) 95 | { 96 | buttonText.text = text; 97 | } 98 | else 99 | { 100 | Debug.LogError("TMP_Text component is not assigned."); 101 | } 102 | } 103 | void OnDisable() 104 | { 105 | // 如果按钮处于选中状态,取消选中并恢复为正常颜色 106 | if (isSelected) 107 | { 108 | isSelected = false; 109 | buttonImage.color = normalColor; // 恢复为正常颜色 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /BasicUI_Levels/SecondListner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | //这是第二层的界面按钮点击事件集 4 | public class SecondListener : MonoBehaviour 5 | { 6 | public LevelManager levelManager; 7 | public SecondButtonTextUpdater secondbuttonTextUpdater; 8 | 9 | private bool button1Selected = false; 10 | private bool button2Selected = false; 11 | public GameObject thirdlevelgroup; 12 | public GameObject fourthlevelgroup; 13 | public GameObject fifthlevelgroup; 14 | private int lastSelectedButton = -1; // -1表示没有按钮被选中 15 | 16 | public Button SecondButton1; 17 | public Button SecondButton2; 18 | 19 | private int PageOneCondition; //第一层的序号是多少 20 | public ThirdListener thirdlistner; 21 | 22 | //这些按钮实际意思是要看第一层给的定义 23 | //这里留地方作为目录注释 24 | void Start() 25 | { 26 | // 为按钮添加点击事件监听器 27 | SecondButton1.onClick.AddListener(() => ToggleButton(1)); 28 | SecondButton2.onClick.AddListener(() => ToggleButton(2)); 29 | HideThirdLevelGroup(); 30 | 31 | } 32 | private void ShowThirdLevelGroup() 33 | { 34 | if (thirdlevelgroup != null) 35 | { 36 | thirdlevelgroup.SetActive(true); 37 | } 38 | } 39 | 40 | private void HideThirdLevelGroup() 41 | { 42 | lastSelectedButton=-1; 43 | thirdlistner.ThirdClearButtons(); 44 | if (fifthlevelgroup != null) 45 | { 46 | thirdlevelgroup.SetActive(false); 47 | } 48 | if (fourthlevelgroup != null) 49 | { 50 | fourthlevelgroup.SetActive(false); 51 | } 52 | 53 | if (thirdlevelgroup != null) 54 | { 55 | thirdlevelgroup.SetActive(false); 56 | } 57 | 58 | } 59 | 60 | private void ToggleButton(int buttonNumber) 61 | { 62 | // 如果当前点击的按钮与上一个点击的按钮不相同,先取消上一个按钮的选中状态 63 | if (lastSelectedButton != -1 && lastSelectedButton != buttonNumber) 64 | { 65 | CancelLastSelectedButton(lastSelectedButton); 66 | } 67 | 68 | // 切换当前按钮的状态 69 | switch (buttonNumber) 70 | { 71 | case 1: 72 | button1Selected = !button1Selected; 73 | if (button1Selected) 74 | Button1Selected(); 75 | else 76 | Button1Unselected(); 77 | break; 78 | case 2: 79 | button2Selected = !button2Selected; 80 | if (button2Selected) 81 | Button2Selected(); 82 | else 83 | Button2Unselected(); 84 | break; 85 | 86 | } 87 | lastSelectedButton = buttonNumber; 88 | } 89 | 90 | private void CancelLastSelectedButton(int buttonNumber) 91 | { 92 | switch (buttonNumber) 93 | { 94 | case 1: 95 | button1Selected = false; 96 | Button1Unselected(); 97 | break; 98 | case 2: 99 | button2Selected = false; 100 | Button2Unselected(); 101 | break; 102 | 103 | } 104 | } 105 | private void Button1Selected() 106 | { 107 | levelManager.SetSecondLevel(1); 108 | ShowThirdLevelGroup(); 109 | PageOneCondition=levelManager.GetFirstLevel(); 110 | if(PageOneCondition==1){ 111 | secondbuttonTextUpdater.UpdateButtonTexts("某某某", "耶耶耶", "hhh", "", ""); 112 | } 113 | if(PageOneCondition==2){ 114 | secondbuttonTextUpdater.UpdateButtonTexts("待定", "待定", "", "", ""); 115 | } 116 | } 117 | private void Button1Unselected() 118 | { 119 | 120 | levelManager.SetSecondLevel(0); 121 | HideThirdLevelGroup(); 122 | } 123 | 124 | private void Button2Selected() 125 | { 126 | levelManager.SetSecondLevel(2); 127 | ShowThirdLevelGroup(); 128 | PageOneCondition=levelManager.GetFirstLevel(); 129 | if(PageOneCondition==1){ 130 | secondbuttonTextUpdater.UpdateButtonTexts("lucky", "lucky", "lucky!", "", ""); 131 | //Debug.Log("SecondLevel is set to: " + levelManager.GetSecondLevel()); 132 | } 133 | } 134 | private void Button2Unselected() 135 | { 136 | button1Selected=false; 137 | levelManager.SetSecondLevel(0); 138 | HideThirdLevelGroup(); 139 | } 140 | 141 | public void SecondClearButtons() 142 | { 143 | button1Selected=false; 144 | button2Selected=false; 145 | lastSelectedButton=-1; 146 | thirdlistner.ThirdClearButtons(); 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /BasicUI_Levels/ThirdButtonTextUpdater.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using TMPro; // 引入TextMeshPro命名空间 3 | using UnityEngine.UI; 4 | //这个是用来控制点击三级界面后四级界面的改变 5 | public class ThirdButtonTextUpdater : MonoBehaviour 6 | { 7 | public Button button1_fourth; 8 | public Button button2_fourth; 9 | public Button button3_fourth; 10 | public Button button4_fourth; 11 | public Button button5_fourth; 12 | 13 | // 五个按钮对应的TextMeshPro文本 14 | public TextMeshProUGUI buttonText1_fourth; 15 | public TextMeshProUGUI buttonText2_fourth; 16 | public TextMeshProUGUI buttonText3_fourth; 17 | public TextMeshProUGUI buttonText4_fourth; 18 | public TextMeshProUGUI buttonText5_fourth; 19 | 20 | // 更新按钮文本并控制其显示或隐藏 21 | public void UpdateButtonTexts(string text1, string text2, string text3, string text4, string text5) 22 | { 23 | // 处理第一个按钮 24 | if (!string.IsNullOrEmpty(text1)) 25 | { 26 | buttonText1_fourth.text = text1; 27 | button1_fourth.gameObject.SetActive(true); // 显示按钮 28 | } 29 | else 30 | { 31 | button1_fourth.gameObject.SetActive(false); // 隐藏按钮 32 | } 33 | 34 | // 处理第二个按钮 35 | if (!string.IsNullOrEmpty(text2)) 36 | { 37 | buttonText2_fourth.text = text2; 38 | button2_fourth.gameObject.SetActive(true); // 显示按钮 39 | } 40 | else 41 | { 42 | button2_fourth.gameObject.SetActive(false); // 隐藏按钮 43 | } 44 | 45 | // 处理第三个按钮 46 | if (!string.IsNullOrEmpty(text3)) 47 | { 48 | buttonText3_fourth.text = text3; 49 | button3_fourth.gameObject.SetActive(true); // 显示按钮 50 | } 51 | else 52 | { 53 | button3_fourth.gameObject.SetActive(false); // 隐藏按钮 54 | } 55 | 56 | // 处理第四个按钮 57 | if (!string.IsNullOrEmpty(text4)) 58 | { 59 | buttonText4_fourth.text = text4; 60 | button4_fourth.gameObject.SetActive(true); // 显示按钮 61 | } 62 | else 63 | { 64 | button4_fourth.gameObject.SetActive(false); // 隐藏按钮 65 | } 66 | 67 | // 处理第五个按钮 68 | if (!string.IsNullOrEmpty(text5)) 69 | { 70 | buttonText5_fourth.text = text5; 71 | button5_fourth.gameObject.SetActive(true); // 显示按钮 72 | } 73 | else 74 | { 75 | button5_fourth.gameObject.SetActive(false); // 隐藏按钮 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /BasicUI_Levels/ThirdLevelButton.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; // 引入UI命名空间 3 | using TMPro; 4 | using UnityEngine.EventSystems; // 引入事件系统命名空间 5 | //有关于第三层元素的颜色与选中控制 6 | //注意,任何函数请前往SecondListner 7 | public class ThirdLevelButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IPointerClickHandler 8 | { 9 | public Color normalColor = Color.gray; // 正常状态的颜色(灰色) 10 | public Color hoverColor = Color.yellow; // 鼠标悬停时的颜色(黄色) 11 | public Color selectedColor = Color.red; // 选中状态的颜色(红色) 12 | 13 | private Image buttonImage; // 按钮的Image组件 14 | private TMP_Text buttonText; // 按钮的文本组件(TextMesh Pro) 15 | private bool isSelected = false; // 选中状态 16 | private ThirdLevelButton[] allButtons; // 所有按钮的引用 17 | 18 | // 新增字段,用于存储按钮的点击事件 19 | public System.Action OnButtonClick; 20 | 21 | void Awake() 22 | { 23 | // 获取按钮的Image组件 24 | buttonImage = GetComponent(); 25 | // 获取子物体中的 TMP_Text 组件 26 | buttonText = GetComponentInChildren(); 27 | 28 | // 错误检查:确保按钮的文本组件存在 29 | if (buttonText == null) 30 | { 31 | Debug.LogError("TMP_Text component not found in button prefab."); 32 | } 33 | 34 | // 获取场景中所有 OneLevelButton 组件 35 | allButtons = FindObjectsOfType(); 36 | 37 | // 初始时设置按钮颜色为正常颜色 38 | buttonImage.color = normalColor; 39 | } 40 | 41 | // 鼠标进入按钮区域时调用 42 | public void OnPointerEnter(PointerEventData eventData) 43 | { 44 | // 如果按钮未选中,鼠标悬停时改变颜色为黄色 45 | if (!isSelected) 46 | { 47 | buttonImage.color = hoverColor; 48 | } 49 | } 50 | 51 | // 鼠标离开按钮区域时调用 52 | public void OnPointerExit(PointerEventData eventData) 53 | { 54 | // 如果按钮未选中,恢复为正常颜色 55 | if (!isSelected) 56 | { 57 | buttonImage.color = normalColor; 58 | } 59 | } 60 | 61 | // 按钮点击时调用 62 | public void OnPointerClick(PointerEventData eventData) 63 | { 64 | // 点击新按钮时,首先取消所有按钮的选中状态并恢复为正常颜色 65 | foreach (ThirdLevelButton button in allButtons) 66 | { 67 | if (button != this) // 不影响当前点击的按钮 68 | { 69 | button.isSelected = false; // 取消选中状态 70 | button.buttonImage.color = normalColor; // 恢复为正常颜色 71 | } 72 | } 73 | 74 | // 只有点击的按钮会变为选中状态,变粉色 75 | if (!isSelected) 76 | { 77 | isSelected = true; 78 | buttonImage.color = selectedColor; 79 | } 80 | else 81 | { 82 | // 如果按钮已经是选中的状态,则取消选中 83 | isSelected = false; 84 | buttonImage.color = normalColor; // 恢复为灰色 85 | } 86 | 87 | // 执行按钮的点击事件(如果有的话) 88 | OnButtonClick?.Invoke(); 89 | } 90 | 91 | // 设置按钮文本 92 | public void SetButtonText(string text) 93 | { 94 | if (buttonText != null) 95 | { 96 | buttonText.text = text; 97 | } 98 | else 99 | { 100 | Debug.LogError("TMP_Text component is not assigned."); 101 | } 102 | } 103 | void OnDisable() 104 | { 105 | // 如果按钮处于选中状态,取消选中并恢复为正常颜色 106 | if (isSelected) 107 | { 108 | isSelected = false; 109 | buttonImage.color = normalColor; // 恢复为正常颜色 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /BasicUI_Levels/ThirdListner.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | //这是第三层的界面按钮点击事件集 4 | public class ThirdListener : MonoBehaviour 5 | { 6 | public LevelManager levelManager; 7 | public ThirdButtonTextUpdater thirdbuttonTextUpdater; 8 | 9 | private bool button1Selected = false; 10 | private bool button2Selected = false; 11 | public GameObject fourthlevelgroup; 12 | 13 | public GameObject fifthlevelgroup; 14 | private int lastSelectedButton = -1; // -1表示没有按钮被选中 15 | 16 | public Button ThirdButton1; 17 | public Button ThirdButton2; 18 | 19 | private int PageOneCondition; //第一层的序号是多少 20 | private int PageTwoCondition; 21 | public FourthListner fourthlistner; 22 | 23 | //这些按钮实际意思是要看第一层给的定义 24 | //这里留地方作为目录注释 25 | void Start() 26 | { 27 | // 为按钮添加点击事件监听器 28 | ThirdButton1.onClick.AddListener(() => ToggleButton(1)); 29 | ThirdButton2.onClick.AddListener(() => ToggleButton(2)); 30 | HideFourthLevelGroup(); 31 | 32 | } 33 | private void ShowFourthLevelGroup() 34 | { 35 | if (fourthlevelgroup != null) 36 | { 37 | fourthlevelgroup.SetActive(true); 38 | } 39 | 40 | } 41 | 42 | private void HideFourthLevelGroup() 43 | { 44 | fourthlistner.FourthClearButtons(); 45 | 46 | if (fourthlevelgroup != null) 47 | { 48 | fourthlevelgroup.SetActive(false); 49 | } 50 | if (fifthlevelgroup != null) 51 | { 52 | fifthlevelgroup.SetActive(false); 53 | } 54 | } 55 | 56 | private void ToggleButton(int buttonNumber) 57 | { 58 | // 如果当前点击的按钮与上一个点击的按钮不相同,先取消上一个按钮的选中状态 59 | if (lastSelectedButton != -1 && lastSelectedButton != buttonNumber) 60 | { 61 | CancelLastSelectedButton(lastSelectedButton); 62 | } 63 | 64 | // 切换当前按钮的状态 65 | switch (buttonNumber) 66 | { 67 | case 1: 68 | button1Selected = !button1Selected; 69 | if (button1Selected) 70 | Button1Selected(); 71 | else 72 | Button1Unselected(); 73 | break; 74 | case 2: 75 | button2Selected = !button2Selected; 76 | if (button2Selected) 77 | Button2Selected(); 78 | else 79 | Button2Unselected(); 80 | break; 81 | 82 | } 83 | lastSelectedButton = buttonNumber; 84 | } 85 | 86 | private void CancelLastSelectedButton(int buttonNumber) 87 | { 88 | switch (buttonNumber) 89 | { 90 | case 1: 91 | button1Selected = false; 92 | Button1Unselected(); 93 | break; 94 | case 2: 95 | button2Selected = false; 96 | Button2Unselected(); 97 | break; 98 | 99 | } 100 | } 101 | private void Button1Selected() 102 | { 103 | levelManager.SetThirdLevel(1); 104 | ShowFourthLevelGroup(); 105 | PageOneCondition=levelManager.GetFirstLevel(); 106 | PageTwoCondition=levelManager.GetSecondLevel(); 107 | if(PageOneCondition==1&&PageTwoCondition==1){ 108 | thirdbuttonTextUpdater.UpdateButtonTexts("其", "qita", "其它", "", ""); 109 | } 110 | if(PageOneCondition==1&&PageTwoCondition==2){ 111 | thirdbuttonTextUpdater.UpdateButtonTexts("待定", "待定", "", "", ""); 112 | } 113 | } 114 | private void Button1Unselected() 115 | { 116 | levelManager.SetThirdLevel(0); 117 | HideFourthLevelGroup(); 118 | } 119 | 120 | private void Button2Selected() 121 | { 122 | levelManager.SetThirdLevel(2); 123 | ShowFourthLevelGroup(); 124 | PageOneCondition=levelManager.GetFirstLevel(); 125 | PageTwoCondition=levelManager.GetSecondLevel(); 126 | if(PageOneCondition==1&&PageTwoCondition==1){ 127 | thirdbuttonTextUpdater.UpdateButtonTexts("112", "112", "112", "112", "112"); 128 | } 129 | if(PageOneCondition==1&&PageTwoCondition==2){ 130 | thirdbuttonTextUpdater.UpdateButtonTexts("122", "122", "122", "", ""); 131 | } 132 | } 133 | private void Button2Unselected() 134 | { 135 | levelManager.SetThirdLevel(0); 136 | HideFourthLevelGroup(); 137 | } 138 | 139 | public void ThirdClearButtons() 140 | { 141 | button1Selected=false; 142 | button2Selected=false; 143 | lastSelectedButton=-1; 144 | fourthlistner.FourthClearButtons(); 145 | } 146 | 147 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 hamsteryuan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityButtonLevels 2 | 这是一个开源的unity的多层按钮交互界面的可使用模版。一层按钮可以触发不同的二层按钮,后续相应。一共提供了四层按钮的模版。相应事件接口例子提供。This is an available template for the open source unity multi-layer button interface. Layer 1 buttons can trigger different layer 2 buttons. A total of four layers of button templates are provided. Corresponding event interface examples are provided. 3 | 每个文件里都有注释。 4 | 是自己兴趣开发,希望能帮到一些人! 5 | ## 具体功能 6 | 每个按钮能够识别:
7 | 1.是否出现。如果自己所在相应层级根本没有通过点击更高层级激活,或者自己层级激活但只激活了3个按钮而这个按钮是第4个,那么不出现。
8 | 2.是否处于鼠标浮在上方的状态,如果是,改变颜色(可以调整)
9 | 3.是否处于被选中状态,如果是,改变颜色(可以调整);被选中下,再次点击会取消选中,点击同层和更高层也会取消选中(激活)
10 | 4.点击后触发事件。分为两部分:一部分是非界面交互事件,一部分是触发下一面界面。 11 | ## 代码介绍 12 | 1.xxxLevelButton 是绑定在每一层按钮的prefab上
13 | 2.xxxListener 和 xxx TextUpdator 可以分别建一个空gameobject绑定。然后把对应层object与按钮相应拖入。二者分别表示控制按钮点击事件和控制按钮文本显示
14 | 3.把交互界面(这里以4层为例)分别建4个gameobject,每个gameobject里面建多个按钮(为这一层所要的最大按钮数量)。在建立一个gameobject,里面放非交互的界面东西,比如一个不可修改,只会因为某个按钮点击而显示的文本框,这个gameobject就相当于是一个虚拟的第五层。
15 | 4.Atomosphere是表示氛围灯,可有可无,这里可以当作一个举例按钮操作效果的东西
16 | 5.LevelManager很重要。因为逻辑上点击按钮后,先去判定当前属于什么子界面下,再去触发功能。
17 | 6.接口和注释可以看文件里。有一些函数已经填入了范例。 18 | --------------------------------------------------------------------------------