using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/*
* Author:W
* 检测PC端鼠标或者移动端手指是否按在了UI区域
*/
public class UIZoneTest : MonoBehaviour
{
private bool isClickUIZone = false;
/// <summary>
/// 标记玩家是否在按在了UI区域
/// </summary>
public bool IsClickUIZone
{
get { return this.isClickUIZone; }
set
{
this.isClickUIZone = value;
Debug.Log("WangLunQiang===>"+ this.isClickUIZone);
}
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
#if UNITY_STANDALONE_WIN || UNITY_EDITOR
if (Input.GetMouseButtonDown(0))
{
if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
{
IsClickUIZone = true;
}
}
if (Input.GetMouseButton(0))
{
}
if (Input.GetMouseButtonUp(0))
{
IsClickUIZone = false;
}
#endif
#if UNITY_ANDROID || UNITY_IPHONE
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
//判断手指触摸的地方是否有UI
if (UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
{
IsClickUIZone = true;
}
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
IsClickUIZone = false;
}
}
#endif
}
}
作用:当我们需要滑动旋转场景又不想在屏幕显示的UI面板区域操作拖动也会触发旋转场景操作时。