using Spine.Unity; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; /// /// 下菜单脚本组件 /// public class DownMenu_Mon : MonoBehaviour, IPointerClickHandler { /// /// 商店页面 /// private GameObject Shop; /// /// 主页锻造页面 /// private GameObject Main; /// /// 图纸页面 /// private GameObject Blueprint; /// /// 升级页面 /// private GameObject Upgrade; private void LoadGame() { this.AllDiscoloration(); Color color_ = this.transform.Find("店铺").GetComponent().color; color_.a = 255; this.transform.Find("店铺").GetComponent().color=color_; this.Main = GameObject.Find("店铺UI"); // 查找所有对象,包括未激活的 GameObject[] allObjects = GameObject.FindObjectsOfType(true); // 遍历所有对象,查找名称匹配的对象 foreach (var obj in allObjects) { if (obj.name == "商店UI") { this.Shop = obj; } if (obj.name == "图纸UI") { this.Blueprint = obj; } if (obj.name == "升级UI") { this.Upgrade = obj; } } } public void OnPointerClick(PointerEventData eventData) { Debug.Log("点击对象" + eventData.pointerCurrentRaycast.gameObject.tag); string name_ = eventData.pointerCurrentRaycast.gameObject.tag; if (name_ == "商店") { this.ClickChild(name_); this.Shop.SetActive(true); this.Blueprint.SetActive(false); this.Upgrade.SetActive(false); } if (name_ == "图纸") { this.ClickChild(name_); this.Blueprint.SetActive(true); this.Shop.SetActive(false); this.Upgrade.SetActive(false); } if (name_ == "店铺") { this.ClickChild(name_); this.Shop.SetActive(false); this.Blueprint.SetActive(false); this.Upgrade.SetActive(false); } if (name_ == "升级") { this.ClickChild(name_); this.Shop.SetActive(false); this.Blueprint.SetActive(false); this.Upgrade.SetActive(true); } if (name_ == "世界") { this.ClickChild(name_); } } /// /// 点击子对象运行该方法 /// /// private void ClickChild(string name_) { this.AllDiscoloration(); Color color_ = this.transform.Find(name_).GetComponent().color; color_.a = 255; this.transform.Find(name_).GetComponent().color = color_; this.transform.Find(name_).GetChild(0).GetComponent().AnimationState.SetAnimation(0, "play", false); } private void AllDiscoloration() { foreach (Transform item_ in this.transform) { Color32 color_=item_.GetComponent().color; color_.a = 150; item_.GetComponent().color = color_; } } // Start is called before the first frame update void Start() { this.LoadGame(); } // Update is called once per frame void Update() { } }