StandaloneInputModule和TouchInputModule两个组件会检测一些输入操作,以事件的方式(message系统)通知目标对象,那么这两个组件支持的事件主要有以下:
只要目标对象的mono脚本实现了以上接口,那么输入模块会将检测到的事件通过这些接口通知给目标对象。
参考:http://docs.unity3d.com/Manual/SupportedEvents.html
部分实现
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class ScenePictureEdit : UIBehaviour, IDragHandler, IEndDragHandler, IPointerDownHandler,IPointerUpHandler, IBeginDragHandler
{
private RectTransform ViewRectTran;
private float IPointerDown, IPointerUp;
private bool IPointerDownBool = false, OnDragBool = false;
private Vector2 m_PinPos;
public GameObject EventDataGo;
void Start ()
{
ViewRectTran = GetComponent
}
void Update()
{
if (Time.time - IPointerDown > 1 && IPointerDownBool)
{
EventDataGo.GetComponent
EventDataGo.GetComponent
OnDragBool = true;
IPointerDownBool = false;
}
}
public virtual void OnDrag(PointerEventData eventData)
{
IPointerDownBool = false;
Vector2 vector;
if (((eventData.button == PointerEventData.InputButton.Left) && this.IsActive()) && RectTransformUtility.ScreenPointToLocalPointInRectangle(this.ViewRectTran, eventData.position, eventData.pressEventCamera, out vector))
{
/*if (!OnDragBool)*/ ViewRectTran.localPosition +=new Vector3((vector.x - m_PinPos.x),0,0);
//else EventDataGo.GetComponent
m_PinPos = vector;
}
}
public void OnEndDrag(PointerEventData eventData)
{
Debug.Log(1);
}
public void OnPointerDown(PointerEventData eventData)
{
EventDataGo = eventData.pointerEnter.GetComponentInParent
IPointerDownBool = true;
IPointerDown = Time.time;
}
public void OnPointerUp(PointerEventData eventData)
{
IPointerUp = Time.time;
if (IPointerUp- IPointerDown < 0.3)
{
if (GameObject.Find("Book_Bg").GetComponent
GameObject.Find("Book_Bg").GetComponent
}
IPointerDownBool = false;
if (OnDragBool)
{
EventDataGo.GetComponent
EventDataGo.GetComponent
}
OnDragBool = false;
}
public void OnBeginDrag(PointerEventData eventData)
{
Vector2 vector;
if (((eventData.button == PointerEventData.InputButton.Left) && this.IsActive()) && RectTransformUtility.ScreenPointToLocalPointInRectangle(this.ViewRectTran, eventData.position, eventData.pressEventCamera, out vector))
{
m_PinPos = vector;
}
}
}