Files
TaiWan/Assets/Roaming/Extenders/ButtonEx/Scripts/BtnController.cs
2025-10-31 15:20:38 +08:00

382 lines
10 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using System.Linq;
/// <summary>
/// 按钮控制类
/// </summary>
public class BtnController : MonoBehaviour
{
public static BtnController Instance;
private void Awake()
{
Instance = this;
}
Animator anim;
/// <summary>
/// 展厅面板
/// </summary>
public GameObject pnlEx;
/// <summary>
/// 小地图
/// </summary>
public GameObject objMinimap;
/// <summary>
/// 音量按钮图像
/// </summary>
public Image imgBGSetting;
/// <summary>
/// 音量开图标
/// </summary>
public Sprite spMusicOn;
/// <summary>
/// 音量关图标
/// </summary>
public Sprite spMusicOff;
/// <summary>
/// 展厅选择面板是否显示
/// </summary>
public bool isPanelExShow;
private void Start()
{
// 控制所有按钮单击时不再接收射线检测
//Button[] btns = transform.GetComponentsInChildren<Button>(true);
//foreach (Button btn in btns)
//{
// btn.gameObject.AddComponent<BtnPreHandler>();
//}
//InputField[] inputs = transform.GetComponentsInChildren<InputField>(true);
//foreach (InputField input in inputs)
//{
// input.gameObject.AddComponent<BtnPreHandler>();
//}
rectMini.localScale = Vector3.one * 2;
// 移位圆角RawImage无法设置Pivot
rectMini.localPosition = new Vector3(
rectMini.localPosition.x - rectMini.rect.width / 2,
rectMini.localPosition.y - rectMini.rect.height / 2);
rectMiniBG.localScale = Vector3.one * 2;
rectMiniBG.localPosition = new Vector3(
rectMiniBG.localPosition.x - rectMiniBG.rect.width / 2,
rectMiniBG.localPosition.y - rectMiniBG.rect.height / 2);
anim = GetComponent<Animator>();
objImgHelp.GetComponentInChildren<Button>().onClick.AddListener(OnBtnHelpCloseClick);
objImgHelp.GetComponentInChildren<Button>().onClick.AddListener(OnBtnHelpClick);
}
public void OnBtnHelpCloseClick()
{
if(!H5Receiver.IsEnterGame)
{
BaseController.IsAnimatorOnControl = true;
FindObjectOfType<H5Receiver>().EnterGame();
objImgHelp.GetComponentInChildren<Button>().onClick.RemoveListener(OnBtnHelpCloseClick);
}
}
/// <summary>
/// 背景音乐按钮单击事件
/// </summary>
public void OnBtnBGMusicClick()
{
if (!BaseController.CanControl)
return;
AudioManager.Instance.SetBackgroundMute();
// 修改音乐图标
imgBGSetting.sprite =
AudioManager.Instance.IsBgMute ? spMusicOff : spMusicOn;
}
public Color defaultColor = Color.gray;
public Color selectedColor = Color.cyan;
/// <summary>
/// 展厅按钮单击事件
/// </summary>
public void OnBtnExLoaderClick()
{
if (!BaseController.CanControl)
return;
// 显示或隐藏展厅面板
isPanelExShow = !isPanelExShow;
if (isPanelExShow)
{
// Tween myTween = pnlEx.transform.DOLocalMoveY(302f, 1f);
// myTween.SetEase(Ease.OutQuint);
// 设置当前展厅图标颜色
for (int i = 0; i < 7; i++)
{
GameObject objBtn = GameObject.Find("BtnExLoader" + i);
if (objBtn != null)
{
if (i == SceneLoader.currentIndex)
{
objBtn.GetComponent<Image>().color = selectedColor;
objBtn.GetComponentInChildren<Text>().color = selectedColor;
}
else
{
objBtn.GetComponent<Image>().color = defaultColor;
objBtn.GetComponentInChildren<Text>().color = defaultColor;
}
}
}
}
else
{
// Tween myTween = pnlEx.transform.DOLocalRotate(Vector3.forward * 180, 1);
// Tween myTween = pnlEx.transform.DOLocalMoveY(-400f, 1f);
// myTween.SetEase(Ease.OutQuint);
}
}
public float move = 200f;
public void OnBtnLoadExClick(int index)
{
if (!BaseController.CanControl && index == SceneLoader.currentIndex)
return;
LoadScene(index);
}
public Text txtBtnName;
public void OnBtnLoadExEnter(string btnName)
{
//txtBtnName.text = btnName;
//txtBtnName.transform.parent.position =
// new Vector3(Input.mousePosition.x, Input.mousePosition.y + 50f, Input.mousePosition.z);
}
/// <summary>
/// 加载展厅
/// </summary>
/// <param name="index">展厅索引</param>
void LoadScene(int index)
{
StartCoroutine(SceneLoader.Instance.LoadScene(index));
OnBtnExLoaderClick();
}
public void OnBtnShowPointClick()
{
if (!BaseController.CanControl)
return;
ShowPointEx.Instance.ShowPanel(SceneLoader.currentIndex);
}
#region
/// <summary>
/// 小地图图标
/// </summary>
public RectTransform rectMini;
/// <summary>
/// 小地图背景
/// </summary>
public RectTransform rectMiniBG;
public GameObject imgMapZT;
/// <summary>
/// 小地图单击事件
/// </summary>
public void OnMinimapClick()
{
//if (!BaseController.CanControl)
// return;
imgMapZT.SetActive(true);
objMinimap.SetActive(false);
BaseController.CanControl = false;
// ZX9Controller.Instance.ShowPanel(SceneLoader.currentIndex);
#region
//if (rectMini.localScale == Vector3.one)
//{
// rectMini.localScale = Vector3.one * 4;
// // 移位圆角RawImage无法设置Pivot
// rectMini.localPosition = new Vector3(
// rectMini.localPosition.x - rectMini.rect.width / 2,
// rectMini.localPosition.y - rectMini.rect.height / 2);
// rectMiniBG.localScale = Vector3.one * 4;
// rectMiniBG.localPosition = new Vector3(
// rectMiniBG.localPosition.x - rectMiniBG.rect.width / 2,
// rectMiniBG.localPosition.y - rectMiniBG.rect.height / 2);
//}
//else
//{
// rectMini.localScale = Vector3.one;
// rectMiniBG.localScale = Vector3.one;
// rectMini.localPosition = new Vector3(
// rectMini.localPosition.x + rectMini.rect.width / 2,
// rectMini.localPosition.y + rectMini.rect.height / 2);
// rectMiniBG.localPosition = new Vector3(
// rectMiniBG.localPosition.x + rectMiniBG.rect.width / 2,
// rectMiniBG.localPosition.y + rectMiniBG.rect.height / 2);
//}
#endregion
}
public void OnMinimapEnter()
{
BaseController.CanControl = false;
}
public void OnMinimapExit()
{
BaseController.CanControl = true;
}
public void OnMapZTClick()
{
imgMapZT.SetActive(false);
objMinimap.SetActive(true);
BaseController.CanControl = true;
}
/// <summary>
/// 地图按钮单击事件
/// </summary>
public void OnBtnMinimapClick()
{
if (!BaseController.CanControl)
return;
objMinimap.SetActive(!objMinimap.activeSelf);
}
#endregion
#region
/// <summary>
/// 全屏事件处理程序
/// 注意不能使用Click否则需要再点击才能进入全屏
/// </summary>
public void OnBtnFullScreenPointerDown()
{
if (!BaseController.CanControl || H5Controller.IsMobileBroswer())
return;
Screen.fullScreen = !Screen.fullScreen;
}
#endregion
public GameObject objImgHelp;
public Image imgHelp;
public GameObject objTxtHelp;
public GameObject objBtnSkipAnim;
public void OnBtnHelpClick()
{
if (objImgHelp.activeSelf)
{
objTxtHelp.SetActive(false);
objImgHelp.SetActive(false);
if (!BaseController.IsAnimatorOnControl)
{
BaseController.CanControl = true;
}
else
{
objBtnSkipAnim.SetActive(true);
}
if (anim != null && anim.enabled)
{
anim.SetBool("IsHelp", false);
}
}
else
{
// StartCoroutine(ImageLoader<Image>.LoadImage(CommonData.UIImageFullPath + "Help.png", imgHelp));
objTxtHelp.SetActive(true);
objImgHelp.SetActive(true);
BaseController.CanControl = false;
if (anim != null && anim.enabled)
{
anim.SetBool("IsHelp", true);
}
}
}
public void SetCanControlDelay()
{
Invoke("SetControl", 0.2f);
}
void SetControl()
{
BaseController.CanControl = true;
}
/// <summary>
/// 自动导览开图标
/// </summary>
public Sprite spAutoOn;
/// <summary>
/// 自动导览关图标
/// </summary>
public Sprite spAutoOff;
public Image imgAutoNavigate;
public GameObject objGuider;
public void OnBtnAutoClick()
{
if (!BaseController.CanControl && !BaseController.IsAutoNavigating)
return;
BaseController.IsAutoNavigating = !BaseController.IsAutoNavigating;
imgAutoNavigate.sprite = BaseController.IsAutoNavigating ? spAutoOff : spAutoOn;
if (BaseController.IsAutoNavigating)
{
BaseController.CanControl = false;
GameObject obj = GameObject.Find("AutoGuiderEx");
if (obj != null)
{
objGuider.SetActive(false);
obj.GetComponent<AutoGuiderEx>().Navigate();
}
}
else
{
BaseController.CanControl = true;
GameObject obj = GameObject.Find("AutoGuiderEx");
if (obj != null)
{
objGuider.SetActive(true);
obj.GetComponent<AutoGuiderEx>().StopNavigate();
}
}
}
}