• QQ
  • nahooten@sina.com
  • 常州市九洲新世界花苑15-2

游戏开发

Unity3d 插件研讨之EasyTouch插件

原创内容,转载请注明原文网址:http://homeqin.cn/a/wenzhangboke/jishutiandi/youxikaifa/2019/0815/600.html

 
 
手机App外包创立步骤:
点击菜单栏的Tools->Hedgehog Team->Easy Touch->Extensions->Add a new Joystick 完成以上骤,此时就会在Game试图左下角看到创立了虚拟遥感的实例。 
  这里写图片描绘 
  这里写图片描绘 
   
  
 
属性面板的组件预览
 
  这里写图片描绘 
  
属性面板组件参数
 
  
joystick properties
 
  这里写图片描绘 
  Joystick properties下的Joystick name的命名很重要(名字要设置好,脚本代码能够依据这个名字找到是哪个摇杆触发的),等下脚本要用到它。 
  
joystick position & size
 
  这里写图片描绘 
  
joystick axes properties & events
 
  这里写图片描绘 
  Interaction type(事情驱动类型)选择Event Notification。 
  
joystick textures
 
  这里写图片描绘 
  参数Speed,控制的是摇杆的x,y轴向的灵活度,都改为1即可。
以上设置完成后,我们新建一个脚本Move.cs
 
添加如下代码。 
using UnityEngine; 
using System.Collections;
 
public class Move : MonoBehaviour {
 
 void OnEnable()  
 
    {    
           EasyJoystick.On_JoystickMove += OnJoystickMove;  
    }  
                   //  此函数是摇杆挪动中所要处置的事
  void OnJoystickMove(MovingJoystick move)  
      {    
                 if (move.joystickName != "new joystick")       //  在这里的名字new joystick 就是上面所说的很重要的名字,在上面图片中joystickName的你修正了什么名字,这里就要写你修正的好的名字(不然脚本不起作用)。
           {  
                     return;  
           }  
 
   float PositionX = move.joystickAxis.x;       //   获取摇杆偏移摇杆中心的x坐标
   float PositionY = move.joystickAxis.y;      //    获取摇杆偏移摇杆中心的y坐标
 
         if (PositionY != 0 || PositionX != 0)  
           {                //  设置控制角色或物体方块的朝向(当前坐标+摇杆偏移量)
                   transform.LookAt(new Vector3(transform.position.x + PositionX, transform.position.y, transform.position.z + PositionY));  
                              //  挪动角色或物体的位置(按其所朝向的位置挪动)
                   transform.Translate(Vector3.forward * Time.deltaTime * 25);  
           }  
     } 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   
把此脚本放到需求用摇杆控制的物体上,即可完成摇杆控制物体挪动。
 
App开发培训实例一
场景里放一个cube,当我用一根手指在屏幕上滑动的时分,我需求cube旋转;当我对它拖拽时,需求它跟着手指挪动;当我用两根手指滑动时相机平面挪动;当我双指向内捏或者向外拉时相机拉近或远。
 
这里写图片描绘 
1.首先添加 easytouch游戏对象,它自身有许多设置选项,我大约过了一下,然后,啥也没记住。 
这个简易demo里也不需求修正什么。 
2.创立cube 
3.创立脚本,并挂给cube 
4.编写脚本
 
这里写图片描绘
 
这是easytouch中订阅事情的办法,EasyTouch下定义了各品种型的事情,我们只需求编写相应处置办法,然后+=订阅。在OnEnable中订阅,在OnDisable和OnDestroy中取消订阅。办法要传一个Gesture类型的参数,包含了手势的数据。
 
我的EasyTouchTest 
using System.Collections; 
using System.Collections.Generic; 
using UnityEngine; 
using HedgehogTeam.EasyTouch; 
using UnityEngine.UI; 
public class EasyTouchTest : MonoBehaviour { 
public Button BtnReset; 
// Use this for initialization 
void Start () {
 
}  
 
// Update is called once per frame  
void Update () {  
 
}  
 
void OnEnable() {  
    EasyTouch.On_Swipe += On_Swipe;  
    EasyTouch.On_Drag += On_Drag;  
    EasyTouch.On_Swipe2Fingers += On_Swipe2Fingers;  
    EasyTouch.On_Pinch += On_Pinch;  
    BtnReset.onClick.AddListener(ResetScene);  
}  
 
void OnDisable() {  
    EasyTouch.On_Swipe -= On_Swipe;  
    EasyTouch.On_Drag -= On_Drag;  
    EasyTouch.On_Swipe2Fingers -= On_Swipe2Fingers;  
    EasyTouch.On_Pinch -= On_Pinch;  
    BtnReset.onClick.RemoveListener(ResetScene);  
}  
 
void OnDestroy() {  
    EasyTouch.On_Swipe -= On_Swipe;  
    EasyTouch.On_Drag -= On_Drag;  
    EasyTouch.On_Swipe2Fingers -= On_Swipe2Fingers;  
    EasyTouch.On_Pinch -= On_Pinch;  
    BtnReset.onClick.RemoveListener(ResetScene);  
}  
 
/// <summary>  
/// 重置cube和相机  
/// </summary>  
void ResetScene() {  
    transform.position = Vector3.zero;  
    transform.rotation = Quaternion.Euler(Vector3.zero);  
    Camera.main.transform.position = new Vector3(0, 0, -10);  
}  
 
/// <summary>  
/// 滑动使cube旋转  
/// </summary>  
/// <param name="ges"></param>  
void On_Swipe(Gesture ges) {  
    Vector3 vec = new Vector3(ges.deltaPosition.y, ges.deltaPosition.x, 0);  
    transform.Rotate(vec ,Space.World);  
}  
 
/// <summary>  
/// 拖拽挪动cube  
/// </summary>  
/// <param name="ges"></param>  
void On_Drag(Gesture ges) {  
    if (ges.pickedObject == gameObject) {  
        transform.position = ges.GetTouchToWorldPoint(10);//相机z=-10 cube 0  
    }  
}  
 
/// <summary>  
/// 双指滑动 平面挪动相机  
/// </summary>  
/// <param name="ges"></param>  
void On_Swipe2Fingers(Gesture ges) {  
    Camera.main.transform.Translate(new Vector3(-ges.deltaPosition.x, -ges.deltaPosition.y, 0));  
}  
 
/// <summary>  
/// 拉近拉远相机  
/// </summary>  
/// <param name="ges"></param>  
void On_Pinch(Gesture ges) {  
    Camera.main.transform.Translate(new Vector3(0, 0, ges.deltaPinch));  
}  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
}
 
参数还需求调整,但之前的小目的是完成了,由于容易一下子就把我的小Cube弄不见了,我就添加了一个复位按钮。
 
摇杆 
剩下的我比拟感兴味的也就是摇杆了,毕竟这个东西挺常用,而且,假如你说要让我本人从头做一个,我还是觉得挺懵逼的··· 
右键EasyTouchControls->Joystick创立一个摇杆 
常用的设置可能也就是Type,决议了摇杆是动态的还是静态的,静态就是坐标固定,动态的话当手指分开屏幕,摇杆会消逝,手触摸的时分在手指触摸的坐标生成摇杆。 
设为动态时能够选择摇杆区域全屏,半屏,还能够自定义区域。 
摇杆的值
 
Debug.Log(ETCInput.GetAxis(“Horizontal”)+”,”+ ETCInput.GetAxis(“Vertical”));
 
easytouch真的非常强大便当易上手,并且跟UGUI没有什么抵触。更多的功用只要在实践运用中去研讨了。
 
常州网站开发培训实例二
摇杆控制人物挪动
 
创立虚拟摇杆: 
这里写图片描绘
这里写图片描绘
好了,开端运用EasyTouch5完成角色的转向: 
如下设置虚拟摇杆参数: 
这里写图片描绘 
这里写图片描绘 
完成角色转动,效果: 
这里写图片描绘
这里写图片描绘
以上是虚拟摇杆简单的应用,下面我们将完成角色第一人称的挪动&转向: 
这里写图片描绘
这里写图片描绘 
好了,第一人称视角的挪动+转向完成!如今经过摇杆控制角色挪动,相时机跟随在角色背后。
 
接着是第三人称视角: 
这里写图片描绘
 
只需求将Turn&Move 选项勾选上,即可控制人物挪动&转向。
 
完成!哈哈,是不是好简单。完整不用接触代码层面,直接经过视图面板设置,这最合适初学者不过。但是没有接触过,或者只是运用过旧版的人可能就一头雾水了。
 
实例三
RPG类的游戏的摇杆控制人物挪动 
1、以下是EasyTouch插件的运用步骤: 
1.import“EasyTouch”资源包
 
2.创立空物体,命名为EasyTouch(当然你也能够改成其他名字)
 
3.添加EasyTouch.cs脚本在刚刚创立的空物体(EasyTouch)上
 
4.选择改物体但不要将BroadcastMessages勾选
 
5.创立一个新的C#脚本,命名MyFirstTouch,然后添加以下办法
 
void OnEnable(){ 
EasyTouch.On_TouchStart += On_TouchStart; 
// Unsubscribe 
void OnDisable(){ 
EasyTouch.On_TouchStart -= On_TouchStart; 
// Unsubscribe 
void OnDestroy(){ 
EasyTouch.On_TouchStart -= On_TouchStart; 
// Touch start event 
public void On_TouchStart(Gesture gesture){ 
Debug.Log( “Touch in ” + gesture.position); 
6.再创立一个空物体,命名为Receiver
 
7.将MyFirstTouch脚本添加到空物体Receiver上
 
8.运转并且点击遥感,会发现控制台打印了当前按下的坐标
 
2、依据官方的这些提示,本人来做一个属于本人的人物遥感控制
 
1.导入EasyTouch3资源包 
2.做好前期准备,包括人物模型、地形的创立 
3.添加JoyStick实例:HedgehogTeam->EasyTouch->Extensions->Add a new Joystick。此时就会在左下角创立虚拟遥感实例 
这里写图片描绘
5 .创立脚本MoveController.cs用来接纳遥感事情控制角色的挪动 
using UnityEngine; 
using System.Collections;
 
public class MoveController : MonoBehaviour {
 
void OnEnable()    
{    
    EasyJoystick.On_JoystickMove += OnJoystickMove;    
    EasyJoystick.On_JoystickMoveEnd += OnJoystickMoveEnd;    
}    
 
 
//挪动摇杆完毕    
void OnJoystickMoveEnd(MovingJoystick move)    
{    
    //中止时,角色恢复idle    
    if (move.joystickName == "MoveJoystick")    
    {    
        animation.CrossFade("idle");    
    }    
}    
 
 
//挪动摇杆中    
void OnJoystickMove(MovingJoystick move)    
{    
    if (move.joystickName != "MoveJoystick")    
    {    
        return;    
    }    
 
    //获取摇杆中心偏移的坐标    
    float joyPositionX = move.joystickAxis.x;    
    float joyPositionY = move.joystickAxis.y;    
 
 
    if (joyPositionY != 0 || joyPositionX != 0)    
    {    
        //设置角色的朝向(朝向当前坐标+摇杆偏移量)    
       transform.LookAt(new Vector3(transform.position.x + joyPositionX, transform.position.y, transform.position.z + joyPositionY));    
        //挪动玩家的位置(按朝向位置挪动)    
        transform.Translate(Vector3.forward * Time.deltaTime * 5);    
        //播放奔跑动画    
        animation.CrossFade("run");    
    }    
}    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
}
 
6.创立点击按钮 
点击HedgehogTeam->EasyTouch->Extensions->Create a new Button,会在屏幕右下角创立一个button 
然后调理面板参数:
 
代码添加跟Unity中Button按钮添加办法相似。
 
最后附上研讨的EasyTouch3.1.6 API
EasyTouch.On_TouchStart 
函数作用:在点击的时分触发 
运用例子: 
public void On_TouchStart(Gesture gesture) 
// Verification that the action on the object 
if (gesture.pickObject == gameObject) 
gameObject.GetComponent().material.color = new Color( Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f)); 
}
 
EasyTouch.On_TouchDown 
企业培训函数作用:在按下的时分触发 
运用例子: 
// Verification that the action on the object 
if (gesture.pickObject == gameObject) 
textMesh.text = “Down since :” + gesture.actionTime.ToString(“f2”); 
}
 
EasyTouch.On_TouchUp 
函数作用:在松开的时分触发 
运用例子: 
public void On_TouchUp(Gesture gesture) 
// Verification that the action on the object 
if (gesture.pickObject == gameObject) 
gameObject.GetComponent().material.color = new Color( 1f,1f,1f); 
textMesh.text =”Touch Start/Up”; 
}
 
EasyTouch.On_DoubleTap 
函数作用:在双击的时分触发 
运用例子: 
private void On_DoubleTap( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
 
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
    }
}
1
2
3
4
5
6
7
EasyTouch.On_SimpleTap 
函数作用:在普通的点击时分触发 
运用例子: 
private void On_SimpleTap( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
    }
}
1
2
3
4
5
6
EasyTouch.On_LongTapStart 
函数作用:在长点击的时分触发 
运用例子: 
private void On_LongTapStart( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject==gameObject){
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
    }
}
1
2
3
4
5
6
EasyTouch.On_LongTap 
函数作用:在长点击期间的时分触发 
运用例子: 
private void On_LongTap( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject==gameObject){
        textMesh.text = gesture.actionTime.ToString("f2");
    }
 
}
1
2
3
4
5
6
7
EasyTouch.On_LongTapEnd 
函数作用:在长点击完毕的时分触发 
运用例子: 
private void On_LongTapEnd( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject==gameObject){
        gameObject.GetComponent<Renderer>().material.color = Color.white;
        textMesh.text="Long tap";
    }
 
}
1
2
3
4
5
6
7
8
EasyTouch.On_Drag 
函数作用:在拖拽期间的时分触发 
常州软件技术培训运用例子: 
void On_Drag(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
 
        // the world coordinate from touch for z=5
        Vector3 position = gesture.GetTouchToWordlPoint(5);
 
        transform.position = position - deltaPosition;
 
        // Get the drag angle
        float angle = gesture.GetSwipeOrDragAngle();
 
        textMesh.text = gesture.swipe.ToString() + " / angle :" + angle.ToString("f2");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
EasyTouch.On_DragStart 
函数作用:在拖拽开端的时分触发 
运用例子: 
void On_DragStart( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
 
        // the world coordinate from touch for z=5
        Vector3 position = gesture.GetTouchToWordlPoint(5);
 
 
        deltaPosition = position - transform.position;
    }   
}
1
2
3
4
5
6
7
8
9
10
11
12
EasyTouch.On_DragEnd 
函数作用:在拖拽完毕的时分触发 
运用例子: 
void On_DragEnd(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        transform.position= new Vector3(3f,1.8f,-5f);
        gameObject.GetComponent<Renderer>().material.color = Color.white;
        textMesh.text="Drag me";
    }
}
1
2
3
4
5
6
7
8
EasyTouch.On_TouchStart2Fingers 
函数作用:按住Ctrl然后点击的时分触发 
运用例子: 
void On_TouchStart2Fingers( Gesture gesture){ 
// Verification that the action on the object 
if (gesture.pickObject == gameObject){ 
gameObject.GetComponent().material.color = new Color( Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f)); 
}
 
EasyTouch.On_TouchDown2Fingers 
函数作用:按住Ctrl然后按下的时分触发 
运用例子: 
void On_TouchDown2Fingers(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        textMesh.text = "Down since :" + gesture.actionTime.ToString("f2");
    }
}
1
2
3
4
5
6
EasyTouch.On_TouchUp2Fingers 
函数作用:按住Ctrl然后松开的时分触发 
运用例子: 
void On_TouchUp2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        gameObject.GetComponent<Renderer>().material.color = Color.white;
        textMesh.text ="Touch Start/Up";
    }
}
1
2
3
4
5
6
7
EasyTouch.On_Cancel2Fingers 
函数作用:按住Ctrl然后取消的时分触发 
运用例子: 
void On_Cancel2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        gameObject.GetComponent<Renderer>().material.color = Color.white;
        textMesh.text ="Touch Start/Up";
    }
}
1
2
3
4
5
6
7
EasyTouch.On_SimpleTap2Fingers 
函数作用:按住Ctrl然后普通点击的时分触发 
运用常州平台运营例子: 
void On_SimpleTap2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
 
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
    }
}
1
2
3
4
5
6
7
EasyTouch.On_DoubleTap2Fingers 
函数作用:按住Ctrl然后双击的时分触发 
运用例子: 
void On_DoubleTap2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
    }
}
1
2
3
4
5
6
EasyTouch.On_LongTapStart2Fingers 
函数作用:按住Ctrl然后长点击的时分触发 
运用例子: 
void On_LongTapStart2Fingers( Gesture gesture){ 
// Verification that the action on the object 
if (gesture.pickObject == gameObject){ 
gameObject.GetComponent().material.color = new Color( Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f)); 
}
 
EasyTouch.On_LongTap2Fingers 
函数作用:按住Ctrl然后长点击的期间的时分触发 
运用例子: 
void On_LongTap2Fingers( Gesture gesture){ 
// Verification that the action on the object 
if (gesture.pickObject == gameObject){ 
textMesh.text = gesture.actionTime.ToString(“f2”); 
}
 
EasyTouch.On_LongTapEnd2Fingers 
函数作用:按住Ctrl然后长点击完毕的时分触发 
运用例子: 
void On_LongTapEnd2Fingers( Gesture gesture){ 
// Verification that the action on the object 
if (gesture.pickObject == gameObject){ 
gameObject.GetComponent().material.color = new Color(1f,1f,1f); 
textMesh.text=”Long tap”; 
}
 
EasyTouch.On_Cancel2Fingers 
函数作用:按住Ctrl然后长点击取消的时分触发 
运用例子: 
void On_Cancel2Fingers(Gesture gesture){ 
gameObject.GetComponent().material.color = new Color(1f,1f,1f); 
textMesh.text=”Long tap”; 
}
 
EasyTouch.On_PinchIn 
函数作用:按住Next然后拖动的时分触发,减少 
运用例子: 
// At the 2 fingers touch beginning 
private void On_TouchStart2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){      
        // disable twist gesture recognize for a real pinch end
        EasyTouch.SetEnableTwist( false);
        EasyTouch.SetEnablePinch( true);
    }
}
1
2
3
4
5
6
7
8
private void On_PinchIn(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
 
        float zoom = Time.deltaTime * gesture.deltaPinch;
 
        Vector3 scale = transform.localScale ;
        transform.localScale = new Vector3( scale.x - zoom, scale.y -zoom, scale.z-zoom);
 
        textMesh.text = "Delta pinch : " + gesture.deltaPinch.ToString();
    }
 
}
1
2
3
4
5
6
7
8
9
10
11
12
13
EasyTouch.On_PinchOut 
常州微信公众平台函数作用:按住Next然后拖动的时分触发,扩展 
运用例子: 
private void On_PinchOut(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        float zoom = Time.deltaTime * gesture.deltaPinch;
 
        Vector3  scale = transform.localScale ;
        transform.localScale = new Vector3( scale.x + zoom, scale.y +zoom,scale.z+zoom);
 
        textMesh.text = "Delta pinch : " + gesture.deltaPinch.ToString();
    }
}
1
2
3
4
5
6
7
8
9
10
11
EasyTouch.On_PinchEnd 
函数作用:按住Next然后拖动完毕的时分触发 
运用例子: 
private void On_PinchEnd(Gesture gesture){
 
    if (gesture.pickObject == gameObject){
        transform.localScale =new Vector3(1.7f,1.7f,1.7f);
        EasyTouch.SetEnableTwist( true);
        textMesh.text="Pinch me";
    }
 
}
1
2
3
4
5
6
7
8
EasyTouch.On_Twist 
函数作用:按住Next然后旋转的时分触发 
运用例子: 
// At the 2 fingers touch beginning 
void On_TouchStart2Fingers( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){          
        EasyTouch.SetEnablePinch( false);
        EasyTouch.SetEnableTwist( true);
    }
}
 
// during the txist
void On_Twist( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        transform.Rotate( new Vector3(0,0,gesture.twistAngle));
        textMesh.text = "Delta angle : " + gesture.twistAngle.ToString();
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
EasyTouch.On_TwistEnd 
函数作用:按住Next然后旋转完毕的时分触发 
运用例子: 
void On_TwistEnd( Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){
        EasyTouch.SetEnablePinch( true);
        transform.rotation = Quaternion.identity;
        textMesh.text ="Twist me";
    }
}
1
2
3
4
5
6
7
8
EasyTouch.On_Drag2Fingers 
常州微信小程序开发函数作用:按住Ctrl然后拖动的时分触发 
运用例子: 
// At the drag beginning 
void On_DragStart2Fingers(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        gameObject.GetComponent<Renderer>().material.color = new Color( Random.Range(0.0f,1.0f),  Random.Range(0.0f,1.0f), Random.Range(0.0f,1.0f));
 
        Vector3 position =  gesture.GetTouchToWordlPoint(  5);
        deltaPosition = position - transform.position;
    }
}
 
// During the drag
void On_Drag2Fingers(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){  
        Vector3 position = gesture.GetTouchToWordlPoint(  5);
 
        transform.position = position - deltaPosition;
 
        float angles =  gesture.GetSwipeOrDragAngle(); 
 
        textMesh.text = gesture.swipe.ToString() + " / angle :" + angles.ToString("f2");
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
EasyTouch.On_DragEnd2Fingers 
函数作用:按住Ctrl然后拖动完毕的时分触发 
运用例子: 
// At the drag end 
void On_DragEnd2Fingers(Gesture gesture){
 
    // Verification that the action on the object
    if (gesture.pickObject == gameObject){          
        transform.position=new Vector3(2.5f,-0.5f,-5f);
        gameObject.GetComponent<Renderer>().material.color = new Color(1f,1f,1f);
        textMesh.text="Drag me";
    }
}
1
2
3
4
5
6
7
8
Joystick.On_Manual 
函数作用:手动摇杆,参数是Vecotr2 
运用例子: 
Joystick.On_Manual(new Vector2(Input.GetAxis (“Horizontal”), Input.GetAxis(“Vertical”)));
 
EasyJoystick.On_JoystickMove 
函数作用:挪动的时分触发 
运用例子: 
void On_JoystickMove( MovingJoystick move){
 
    float angle = move.Axis2Angle(true);
    transform.rotation  = Quaternion.Euler( new Vector3(0,angle,0));
    transform.Translate( Vector3.forward * move.joystickValue.magnitude * Time.deltaTime);  
 
    model.GetComponent<Animation>().CrossFade("Run");
 
}
1
2
3
4
5
6
7
8
EasyJoystick.On_JoystickMoveEnd 
函数作用:挪动完毕的时分触发 
运用例子: 
void On_JoystickMoveEnd (MovingJoystick move) 
model.GetComponent().CrossFade(“idle”); 
 
}

上篇:上一篇:cocos2d-x 对一个方法延时执行操作
下篇:下一篇:Unity3D中JavaScript与C#区别