用于指定笔状态的选项。例如,笔是否接触屏幕或平板电脑,笔是否倒置,以及按钮是否按下。您可以使用按位 OR 运算符组合状态。
在将事件处理为笔事件之前,您应该检查鼠标事件的PointerType(例如,EventType.MouseDown)。
当用户使用笔时,一些鼠标事件通常与笔事件混合在事件流中,并且您无法通过类型区分它们,因为鼠标事件和笔事件共享相同的EventType。相反,使用PointerType来区分它们。否则,Unity 会将所有传入的鼠标事件处理为笔事件,这会导致意外行为,因为鼠标事件(pointerType = Mouse)没有笔事件字段,例如 PenStatus 设置。
using UnityEngine;
public class Example : MonoBehaviour { void OnGUI() { Event m_Event = Event.current;
if (m_Event.type == EventType.MouseDown) { if (m_Event.pointerType == PointerType.Pen) //Check if it's a pen event. { if (m_Event.penStatus == PenStatus.None) Debug.Log("Pen is in a neutral state."); else if (m_Event.penStatus == PenStatus.Inverted) Debug.Log("The pen is inverted."); else if (m_Event.penStatus == PenStatus.Barrel) Debug.Log("Barrel button on pen is down."); else if (m_Event.penStatus == PenStatus.Contact) Debug.Log("Pen is in contact with screen or tablet."); else if (m_Event.penStatus == PenStatus.Eraser) Debug.Log("Pen is in erase mode."); } else Debug.Log("Mouse Down."); //If it's not a pen event, it's a mouse event. } } }