/// <summary>
/// 为不挂载脚本的UI添加接口:如拖动、点击等
/// </summary>
/// <param name="go">游戏物体</param>
/// <param name="triggerType">接口类型</param>
/// <param name="action">回调委托</param>
internal void AddEventTriggerInterface(GameObject go, EventTriggerType triggerType, UnityAction<BaseEventData> action)
{
var trigger = go.AddComponent<EventTrigger>();
var entry = new EventTrigger.Entry {eventID = triggerType, callback = new EventTrigger.TriggerEvent()};
entry.callback.AddListener(action);
trigger.triggers.Add(entry);
}
uiViewer.AddEventTriggerInterface(game, EventTriggerType.Drag,(dragHandler) =>
{
game.transform.position =
((PointerEventData) dragHandler).position;
});
这样弄出来的位置不知道什么位置,posX范围0-14000多,y范围-576 - 7500左右,也不是屏幕坐标啊,该怎么转换为localposition?