EasyTouch 5.0.17 最新版本扩展方法

具体使用方法看自带的文档就可以了,我对相应的组建稍微封装了下,方便动态加载

EasyTouch下载链接-提取码:q3lu

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System;

using HedgehogTeam.EasyTouch;


public static class EasyTouchHandle
{
    /// 
    /// 添加拖拽组件
    /// 
    /// 
    /// 开始拖拽触发事件
    /// 拖拽过程中触发事件
    /// 拖拽结束时触发事件
    /// 
    public static QuickDrag  AddQuickDrag( this GameObject root,UnityAction DragStart = null, UnityAction Drag = null, UnityAction DragEnd = null)
    {

        QuickDrag tempQuickDrag = root.AddComponent();
        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;
    }
    /// 
    /// 添加触控组件
    /// 
    /// 
    /// 点击开始触发事件
    /// 点击中触发事件
    /// 点击结束时触发事件
    public static void AddQuickTouch(this GameObject root, UnityAction TouchStart=null, UnityAction TouchDown = null, UnityAction TouchUp = null)
    {
        if (TouchStart != null)
        {
            QuickTouch tempQuickTouch = root.AddComponent();
            tempQuickTouch.quickActionName = "QucikTouchStart";
            tempQuickTouch.is2Finger = false;//是否双指触发
            tempQuickTouch.actionTriggering = QuickTouch.ActionTriggering.Start;
            //if (tempQuickTouch == null)
            //{
            //    Debug.Log("AddQuickDrag参数为Null");
            //}

            //tempQuickTouch.onTouch
            tempQuickTouch.onTouch = new QuickTouch.OnTouch();
            tempQuickTouch.onTouch.AddListener(TouchStart);
        }

        if (TouchDown != null)
        {
            QuickTouch tempQuickTouch = root.AddComponent();
            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();
            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);
        }
    }

    /// 
    /// 添加滑动组建
    /// 
    /// 
    /// 
    /// 滑动方向
    /// 触发效果位置 角度 或 缩放
    /// 影响对应的轴向( X Y Z )
    /// 滑动所影响效果的速率
    /// 是否与滑动方向相反
    public static QuickSwipe AddQuickSwip(this GameObject root, UnityAction 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();
        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 Start = null, UnityAction InProgess = null, UnityAction End = null)
    {
        if (Start != null)
        {
            QuickLongTap tempQuickLongTap = root.AddComponent();
            tempQuickLongTap.quickActionName = "QuickLongTapStart";
            tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.Start;
            tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
            tempQuickLongTap.onLongTap.AddListener(Start);
        }
        if (InProgess != null)
        {
            QuickLongTap tempQuickLongTap = root.AddComponent();
            tempQuickLongTap.quickActionName = "QuickLongTapInProgess";
            tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.InProgress;
            tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
            tempQuickLongTap.onLongTap.AddListener(InProgess);
        }
        if (End != null)
        {
            QuickLongTap tempQuickLongTap = root.AddComponent();
            tempQuickLongTap.quickActionName = "QuickLongTapEnd";
            tempQuickLongTap.actionTriggering = QuickLongTap.ActionTriggering.End;
            tempQuickLongTap.onLongTap = new QuickLongTap.OnLongTap();
            tempQuickLongTap.onLongTap.AddListener(End);
        }
    }
}

你可能感兴趣的:(EasyTouch 5.0.17 最新版本扩展方法)