WXGame/b1/Assets/脚本/下菜单/DownMenu_Mon.cs
2024-10-23 09:14:01 +08:00

137 lines
3.5 KiB
C#

using Spine.Unity;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
/// <summary>
/// 下菜单脚本组件
/// </summary>
public class DownMenu_Mon : MonoBehaviour, IPointerClickHandler
{
/// <summary>
/// 商店页面
/// </summary>
private GameObject Shop;
/// <summary>
/// 主页锻造页面
/// </summary>
private GameObject Main;
/// <summary>
/// 图纸页面
/// </summary>
private GameObject Blueprint;
/// <summary>
/// 升级页面
/// </summary>
private GameObject Upgrade;
private void LoadGame()
{
this.AllDiscoloration();
Color color_ = this.transform.Find("店铺").GetComponent<Image>().color;
color_.a = 255;
this.transform.Find("店铺").GetComponent<Image>().color=color_;
this.Main = GameObject.Find("店铺UI");
// 查找所有对象,包括未激活的
GameObject[] allObjects = GameObject.FindObjectsOfType<GameObject>(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_);
}
}
/// <summary>
/// 点击子对象运行该方法
/// </summary>
/// <param name="name_"></param>
private void ClickChild(string name_)
{
this.AllDiscoloration();
Color color_ = this.transform.Find(name_).GetComponent<Image>().color;
color_.a = 255;
this.transform.Find(name_).GetComponent<Image>().color = color_;
this.transform.Find(name_).GetChild(0).GetComponent<SkeletonGraphic>().AnimationState.SetAnimation(0, "play", false);
}
private void AllDiscoloration()
{
foreach (Transform item_ in this.transform)
{
Color32 color_=item_.GetComponent<Image>().color;
color_.a = 150;
item_.GetComponent<Image>().color = color_;
}
}
// Start is called before the first frame update
void Start()
{
this.LoadGame();
}
// Update is called once per frame
void Update()
{
}
}