Subversion Repository Public Repository

Nextrek

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
using UnityEngine;
using System.Collections;

public class ObjectTouch : MonoBehaviour {


	private Camera cam;
	private Vector3 deltaPosition;
	
	void OnEnable(){
		EasyTouch.On_TouchStart += On_TouchStart;	
		EasyTouch.On_SimpleTap += On_SimpleTap;	
		EasyTouch.On_LongTap += On_LongTap;	
		EasyTouch.On_DragStart += On_DragStart;	
		EasyTouch.On_Drag += On_Drag;	
		EasyTouch.On_DragEnd += On_DragEnd;
		EasyTouch.On_PinchIn += On_PinchIn;
		EasyTouch.On_PinchOut += On_PinchOut;
		
	}

	void OnDisable(){
		UnsubscribeEvent();
	}
	
	void OnDestroy(){
		UnsubscribeEvent();
	}
	
	void UnsubscribeEvent(){
		EasyTouch.On_TouchStart -= On_TouchStart;	
		EasyTouch.On_SimpleTap -= On_SimpleTap;	
		EasyTouch.On_LongTap -= On_LongTap;	
		EasyTouch.On_DragStart -= On_DragStart;	
		EasyTouch.On_Drag -= On_Drag;	
		EasyTouch.On_DragEnd -= On_DragEnd;
		EasyTouch.On_PinchIn -= On_PinchIn;
		EasyTouch.On_PinchOut -= On_PinchOut;		
	}
	
	void Start(){
		cam = Camera.main;
	}
	
	void FixedUpdate(){
	
		Vector2 screenPos = cam.WorldToScreenPoint( GetComponent<Rigidbody>().position);
		
		if ( screenPos.x> Screen.width ||screenPos.y<0 ||screenPos.y> Screen.height)
			Destroy( gameObject);
			
		if (screenPos.x<transform.localScale.x/2){
			GetComponent<Rigidbody>().AddForce( GetComponent<Rigidbody>().velocity *-100);
		}
	}
	
	
	
	// ****************************************************
	// Easy Touch Message
	// ****************************************************
	
	void On_TouchStart(Gesture gesture){
		
		if (gesture.pickObject == gameObject){
			GetComponent<Rigidbody>().constraints  = RigidbodyConstraints.FreezeAll;
		}
	}
	
	// Simple Touch message
	void On_SimpleTap(Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			GameObject child=null;
			
			GetComponent<Rigidbody>().constraints  = RigidbodyConstraints.None;
			
			foreach (Transform childreen in transform ){
				if (childreen.name=="ring")
					child = childreen.gameObject;
			}
			
			if (child==null){
		
				GameObject ring = Instantiate(Resources.Load("Ring01"), transform.position , Quaternion.identity) as GameObject;
				ring.transform.localScale = transform.localScale * 1.5f;
				ring.AddComponent<SlowRotate>();
				ring.GetComponent<Renderer>().material.SetColor ("_TintColor", GetComponent<Renderer>().material.GetColor("_TintColor"));
				
				ring.transform.parent = transform;
				ring.name="ring";
			
			}
			else{
				Destroy( child);
			}
		
		}
		
	}
	
	// Long Touch message
	void On_LongTap(Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			GameObject child=null;
			
			GetComponent<Rigidbody>().constraints  = RigidbodyConstraints.None;
			
			foreach ( Transform childreen in transform){
				if (childreen.name=="ring")
					child = childreen.gameObject;
			}
			
			if (child!=null){
				child.GetComponent<SlowRotate>().rotateSpeed *= 1.1f;
			}
		}
	}
	
	// Drag_Start
	void On_DragStart(Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			Vector3 position = gesture.GetTouchToWordlPoint(8);
			deltaPosition = position - GetComponent<Rigidbody>().position;
			
			GetComponent<Rigidbody>().constraints  = RigidbodyConstraints.None;
		}
	}
	
	// Drag Message => move
	void On_Drag(Gesture gesture){
			
		if (gesture.pickObject == gameObject){
			Vector3 position = gesture.GetTouchToWordlPoint(8);
			
			GetComponent<Rigidbody>().position = position - deltaPosition;
		}
		
	}
	
	// Drag end => Add force whith the delta position
	void On_DragEnd( Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			GetComponent<Rigidbody>().AddForce( gesture.deltaPosition *  gesture.swipeLength/10 );
		}
		
	}
	
	// Pinch for size
	void On_PinchIn(Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			float zoom = Time.deltaTime * gesture.deltaPinch;
		
			Vector3 scale = transform.localScale ;
			transform.localScale = new Vector3( scale.x - zoom, scale.y -zoom,1);
		}
	}
	
	void On_PinchOut(Gesture gesture){
	
		if (gesture.pickObject == gameObject){
			float zoom = Time.deltaTime * gesture.deltaPinch;
		
			Vector3 scale = transform.localScale ;
			transform.localScale = new Vector3( scale.x + zoom, scale.y +zoom,1);
		}
		
	}
}

Commits for Nextrek/3DSpace/Assets/EasyTouch/Example/C# Example/Examples for EasyTouch/Example-Multiplefingers/ObjectTouch.cs

Diff revisions: vs.
Revision Author Commited Message
168 Diff Diff LMancini picture LMancini Wed 08 Apr, 2015 12:33:35 +0000
112 Diff Diff FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 14:21:59 +0000
107 FMMortaroli picture FMMortaroli Thu 09 Oct, 2014 11:56:46 +0000