码迷,mamicode.com
首页 > 其他好文 > 详细

EasyTouch的使用

时间:2017-06-17 13:08:47      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:cal   http   这一   vector   插件   blog   system   技术分享   tap   

EasyTouch插件包含三个模块:Easy Button 、 Joystick 、 事件

关于按钮和事件这一块,在实际的工作中,你可以用Easy Button,也可以用其它插件,比如NGUI,效果上都是一样的

下面就具体说说Easy Button的使用,有两种使用方法: 
方法一,请看如下截图 
技术分享 
技术分享 
技术分享 
技术分享 
按钮使用方法二: 通过按钮的名字区分点击的是哪个按钮 
技术分享

关于Joystick,重点掌握以下几个方面: 
技术分享 
关于Joystick必须掌握三个语句: 
语句一: joystick.JoystickAxis 
技术分享 
语句二: float angle = move.Axis2Angle(true); 
技术分享 
语句三: move.joystickValue

最后对两个语句做个总结,如下图: 
技术分享 
技术分享

下面说说EasyTouch提供的一整套针对移动设备的事件,包括常用的单手指按下开始、单手指拖动、双手指拉大、双手指缩小、双手指扭动旋转等,代码如下:

 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 public class Photo : MonoBehaviour {
 5     private Vector3 deltaPosition;
 6     private Vector3 rotation;
 7     private bool newPivot=false;    
 8         // Subscribe to events
 9     void OnEnable(){
10         EasyTouch.On_DragStart += On_DragStart;
11         EasyTouch.On_Drag += On_Drag;
12         EasyTouch.On_TouchStart2Fingers += On_TouchStart2Fingers;
13         EasyTouch.On_TouchDown2Fingers += On_TouchDown2Fingers;
14         EasyTouch.On_PinchIn += On_PinchIn;
15         EasyTouch.On_PinchOut += On_PinchOut;
16         EasyTouch.On_Twist += On_Twist;
17         EasyTouch.On_Cancel2Fingers += On_Cancel2Fingers;
18     }
19     void OnDisable(){
20         UnsubscribeEvent();
21     }
22     void OnDestroy(){
23         UnsubscribeEvent();
24     }   
25     void UnsubscribeEvent(){
26         EasyTouch.On_DragStart -= On_DragStart;
27         EasyTouch.On_Drag -= On_Drag;
28         EasyTouch.On_TouchStart2Fingers -= On_TouchStart2Fingers;
29         EasyTouch.On_TouchDown2Fingers -= On_TouchDown2Fingers;
30         EasyTouch.On_PinchIn -= On_PinchIn;
31         EasyTouch.On_PinchOut -= On_PinchOut;
32         EasyTouch.On_Twist -= On_Twist; 
33         EasyTouch.On_Cancel2Fingers -= On_Cancel2Fingers;
34     }   
35     void On_Cancel2Fingers( Gesture gesture){
36         if (gesture.touchCount>0){
37             newPivot=true;  
38         }
39     }
40     // One finger drag
41     void On_DragStart( Gesture gesture){
42 
43         // restricted when there is only one touch 
44         if (gesture.touchCount==1){
45             // Calculate the delta position between touch and photo center position
46             Vector3 position = gesture.GetTouchToWordlPoint(1);
47             deltaPosition = position - transform.position;
48         }
49     }   
50     void On_Drag( Gesture gesture){
51 
52         if (gesture.touchCount==1){
53             Vector3 position = gesture.GetTouchToWordlPoint(1); 
54             if (newPivot){
55                 deltaPosition = position - transform.position;
56                 newPivot = false;
57             }
58 
59             transform.position = position - deltaPosition;
60         }
61 
62     }   
63     // when a two finger gesture begining
64     void On_TouchStart2Fingers(Gesture gesture){
65 
66         // Calculate the delta position between touch and photo center position
67         Vector3 position = gesture.GetTouchToWordlPoint(1);
68         deltaPosition = position - transform.position;
69     }   
70     void On_TouchDown2Fingers(Gesture gesture){
71 
72         // Moving during pinch & twist
73         Vector3 position = gesture.GetTouchToWordlPoint(1);
74         transform.position = position - deltaPosition;
75     }   
76     // 双手指缩小
77     void On_PinchIn(Gesture gesture){
78 
79         float zoom = Time.deltaTime * gesture.deltaPinch/25;
80         Vector3 scale = transform.localScale ;
81 
82         if ( scale.x - zoom>0.1)
83             transform.localScale = new Vector3( scale.x - zoom, scale.y -zoom,1f);
84     }
85     // 双手指放大
86     void On_PinchOut(Gesture gesture){
87 
88         float zoom = Time.deltaTime * gesture.deltaPinch/25;
89         Vector3 scale = transform.localScale ;
90 
91         if ( scale.x + zoom<3 )
92             transform.localScale = new Vector3( scale.x + zoom, scale.y +zoom,1f);
93     }   
94     //双手指按压扭动旋转
95     void  On_Twist( Gesture gesture){
96 
97         transform.Rotate(new Vector3(0,0,gesture.twistAngle));
98     }    
99 }

 原文地址:http://blog.csdn.net/qq_15267341/article/details/51581730

EasyTouch的使用

标签:cal   http   这一   vector   插件   blog   system   技术分享   tap   

原文地址:http://www.cnblogs.com/AaronBlogs/p/7039828.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!