using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; // 添加EventSystems命名空间 /// /// 头像组件 /// public class AvatarComponent : MonoBehaviour { public Button avatarButton; private bool isClicked = false; private void Awake() { avatarButton.onClick.AddListener(OpenAvatarPage); } private void Update() { // 检测空白处点击事件 HandleEmptyAreaClick(); } /// /// 处理空白处点击事件 /// private void HandleEmptyAreaClick() { // 检测鼠标左键点击 if (Input.GetMouseButtonDown(0)) { if (!isClicked) return; // 点击了空白处,触发空白处点击事件 OnEmptyAreaClick(); } // 检测触摸点击 if (Input.touchCount > 0) { // 获取第一个触摸点 Touch touch = Input.GetTouch(0); // 检查触摸阶段是否为触摸开始 if (touch.phase == TouchPhase.Began) { if (!isClicked) return; // 触摸了空白处,触发空白处点击事件 OnEmptyAreaClick(); // 输出触摸调试信息 Debug.Log($"检测到触摸空白处!触摸位置: {touch.position}, 触摸ID: {touch.fingerId}"); } } } /// /// 空白处点击事件处理 /// private void OnEmptyAreaClick() { isClicked = false; UIManager.Instance.HideUI("首页-头像"); } private void OpenAvatarPage() { isClicked = true; UIManager.Instance.ShowPage("首页-头像"); } }