具体使用方法看自带的文档就可以了,我对相应的组建稍微封装了下,方便动态加载
EasyTouch下载链接-提取码:q3lu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System;
using HedgehogTeam.EasyTouch;
public static class EasyTouchHandle
{
/// <summary>
/// 添加拖拽组件
/// </summary>
/// <param name="root"></param>
/// <param name="DragStart">开始拖拽触发事件</param>
/// <param name="Drag">拖拽过程中触发事件</param>
/// <param name="dargEnd">拖拽结束时触发事件</param>
/// <returns></returns>
public static QuickDrag AddQuickDrag( this GameObject root,UnityAction<Gesture> DragStart = null, UnityAction<Gesture> Drag = null, UnityAction<Gesture> DragEnd = null)
{
QuickDrag tempQuickDrag = root.AddComponent<QuickDrag>();
tempQuickDrag.axesAction = QuickBase.AffectedAxesAction.XYZ;//拖拽轴向
tempQuickDrag.enablePickOverUI = false; //其他UI上拖拽和此拖拽物体叠加时可同时触发(false不触发)
tempQuickDrag.onDragStart = new QuickDrag.OnDragStart();
tempQuickDrag.onDrag = new QuickDrag.OnDrag();
tempQuickDrag.onDragEnd = new QuickDrag.OnDragEnd();
if (DragStart != null)
{
tempQuickDrag.onDragStart.AddListener(DragStart);
}
if (Drag != null)
{
tempQuickDrag.onDrag.AddListener(Drag);
}
if (DragEnd != null)
{
tempQuickDrag.onDragEnd.AddListener(DragEnd);
}
return tempQuickDrag;
}
/// <summary>
/// 添加触控组件
/// </summary>
/// <param name="root"></param>
/// <param name="TouchStart">点击开始触发事件</param>
/// <param name="TouchDown">点击中触发事件</param>
/// <param name="TouchUp">点击结束时触发事件</param>
public static void AddQuickTouch(this GameObject root, UnityAction<Gesture> TouchStart=null, UnityAction<Gesture> TouchDown = null, UnityAction<Gesture> TouchUp = null)
{
if (TouchStart != null)
{
QuickTouch tempQuickTouch = root.AddComponent<QuickTouch>();
tempQuickTouch.quickActionName = "QucikTouchStart";
tempQuickTouch.is2Finger = false;//是否双指触发
tempQuickTouch.actionTriggering = QuickTouch.ActionTriggering.Start;
//if (tempQuickTouch == null)
//{
// Debug.Log("<color=#ffff00ff><b>AddQuickDrag参数为Null</b></color>");
//}
//tempQuickTouch.onTouch
tempQuickTouch.onTouch = new QuickTouch.OnTouch();
tempQuickTouch.onTouch.AddListener(TouchStart);
}
if (TouchDown != null)
{
QuickTouch tempQuickTouch = root.AddComponent<QuickTouch>();
tempQuickTouch.quickActionName = "QucikTouchStart";
tempQuickTouch.is2Finger = false;//是否双指触发
tempQuickTouch.actionTriggering = QuickTouch.ActionTriggering.Down;
tempQuickTouch.onTouch = new QuickTouch.OnTouch();
tempQuickTouch.onTouch.AddListener(TouchDown);
}
if (TouchUp != null)
{
QuickTouch tempQuickTouch = root.AddComponent<QuickTouch>();
tempQuickTouch.quickActionName = "QucikTouchStart";
tempQuickTouch.is2Finger = false;//是否双指触发
tempQuickTouch.actionTriggering = QuickTouch.ActionTriggering.Up;
tempQuickTouch.onTouch = new QuickTouch.OnTouch();
tempQuickTouch.onTouchNotOverMe = new QuickTouch.OnTouchNotOverMe();
tempQuickTouch.onTouch.AddListener(TouchStart);
tempQuickTouch.onTouchNotOverMe.AddListener(TouchUp);
}
}
/// <summary>
/// 添加滑动组建
/// </summary>
/// <param name="root"></param>
/// <param name="Swipe"></param>
/// <param name="SwipeDirection">滑动方向</param>
/// <param name="DirectAction">触发效果位置 角度 或 缩放</param>
/// <param name="AffectedAxesAction">影响对应的轴向( X Y Z )</param>
/// <param name="SensibilitySpeed">滑动所影响效果的速率</param>
/// <param name="inverseAxisValue">是否与滑动方向相反</param>
public static QuickSwipe AddQuickSwip(this GameObject root, UnityAction<Gesture> Swipe = null,
QuickSwipe.SwipeDirection SwipeDirection = QuickSwipe.SwipeDirection.Horizontal,
QuickBase.DirectAction DirectAction = QuickBase.DirectAction.RotateLocal,
QuickBase.AffectedAxesAction AffectedAxesAction = QuickBase.AffectedAxesAction.Y,
float SensibilitySpeed = 1.0f,bool inverseAxisValue = false)
{
QuickSwipe tempQuickSwipe = root.AddComponent<QuickSwipe>();
tempQuickSwipe.quickActionName = "QuickSwipe";
tempQuickSwipe.allowSwipeStartOverMe = false; //作用在root上时无效
tempQuickSwipe.actionTriggering = QuickSwipe.ActionTriggering.InProgress;
tempQuickSwipe.swipeDirection = SwipeDirection;
tempQuickSwipe.enableSimpleAction = true;
tempQuickSwipe.directAction = DirectAction;
tempQuickSwipe.axesAction = AffectedAxesAction;
tempQuickSwipe.sensibility = SensibilitySpeed;
tempQuickSwipe.inverseAxisValue = inverseAxisValue;//顺时针逆时针
tempQuickSwipe.onSwipeAction = new QuickSwipe.OnSwipeAction();
if (Swipe != null)
{
tempQuickSwipe.onSwipeAction.AddListener(Swipe);
}
return tempQuickSwipe;
}
public static void AddQuickLongTap(this GameObject root,UnityAction<Gesture> Start = null, UnityAction<Gesture> InProgess = null, UnityAction<Gesture> End = null)
{
if (Start != null)
{
QuickLongTap tempQuickLongTap = root.AddComponent<QuickLongTap>();
tempQuickLongTap.quickActionName = "QuickLongTapStart";
tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.Start;
tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
tempQuickLongTap.onLongTap.AddListener(Start);
}
if (InProgess != null)
{
QuickLongTap tempQuickLongTap = root.AddComponent<QuickLongTap>();
tempQuickLongTap.quickActionName = "QuickLongTapInProgess";
tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.InProgress;
tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
tempQuickLongTap.onLongTap.AddListener(InProgess);
}
if (End != null)
{
QuickLongTap tempQuickLongTap = root.AddComponent<QuickLongTap>();
tempQuickLongTap.quickActionName = "QuickLongTapEnd";
tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.End;
tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
tempQuickLongTap.onLongTap.AddListener(End);
}
}
}