|
|
|
|
@ -9,6 +9,8 @@ public class tuio_event : MonoBehaviour |
|
|
|
|
public Transform canvas; |
|
|
|
|
//public UltraCombos.GlobalMKHookInput tuio_input; |
|
|
|
|
Dictionary<int, movieController> movies = new Dictionary<int, movieController>(); |
|
|
|
|
Dictionary<int, Vector2> pre_pos = new Dictionary<int, Vector2>(); |
|
|
|
|
|
|
|
|
|
void Update() |
|
|
|
|
{ |
|
|
|
|
var touches = TUIOManager.Instance.touches; |
|
|
|
|
@ -24,11 +26,43 @@ public class tuio_event : MonoBehaviour |
|
|
|
|
movie.id = id; |
|
|
|
|
movies.Add(id, movie); |
|
|
|
|
movie.transform.position = touches[id].position; |
|
|
|
|
pre_pos.Add(id, touches[id].position); |
|
|
|
|
} |
|
|
|
|
else //update |
|
|
|
|
{ |
|
|
|
|
if (Time.frameCount % 10 == 0) |
|
|
|
|
{ |
|
|
|
|
float delta_pos = Vector2.Distance(pre_pos[id], touches[id].position); |
|
|
|
|
if (delta_pos > 200) |
|
|
|
|
{ |
|
|
|
|
Debug.Log("generate new one"); |
|
|
|
|
GameObject g = Instantiate(img, canvas); |
|
|
|
|
int clone_id = id + Random.Range(5000, 10000); |
|
|
|
|
g.name = clone_id.ToString(); |
|
|
|
|
movie = g.AddComponent<movieController>(); |
|
|
|
|
movie.id = clone_id; |
|
|
|
|
movies.Add(clone_id, movie); |
|
|
|
|
movie.transform.position = pre_pos[id]; |
|
|
|
|
movie.transform.localRotation = movies[id].transform.localRotation; |
|
|
|
|
movie.alpha = 0.9f; |
|
|
|
|
|
|
|
|
|
movies[id].stat = 0; |
|
|
|
|
movies[id].transform.position = touches[id].position; |
|
|
|
|
movies[id].CanDsetroy = false; |
|
|
|
|
movies[id].rotateImg(); |
|
|
|
|
|
|
|
|
|
pre_pos[id] = touches[id].position; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
//movies[id].transform.position = touches[id].position; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
movie = movies[id]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//update or after adding |
|
|
|
|
//Debug.Log("Update"); |
|
|
|
|
//movie.transform.position = touches[id].position; |
|
|
|
|
@ -45,92 +79,16 @@ public class tuio_event : MonoBehaviour |
|
|
|
|
} |
|
|
|
|
foreach (var id in removes) |
|
|
|
|
{ |
|
|
|
|
if (movies[id].stat == 2) |
|
|
|
|
if (movies[id].stat == 2 || movies[id].stat == 3) |
|
|
|
|
{ |
|
|
|
|
movies[id].stat = 3; |
|
|
|
|
movies[id].destroy_timer = Time.time; |
|
|
|
|
movies[id].CanDsetroy = true; |
|
|
|
|
movies.Remove(id); |
|
|
|
|
Debug.Log("Remove"); |
|
|
|
|
} |
|
|
|
|
//movies[id].destroy_timer = Time.time; |
|
|
|
|
} |
|
|
|
|
//movies.Remove(id); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
// Start is called before the first frame update |
|
|
|
|
public GameObject img; |
|
|
|
|
public GameObject canvas; |
|
|
|
|
public UltraCombos.GlobalMKHookInput tuio_input; |
|
|
|
|
|
|
|
|
|
List<int> cur_ids = new List<int>(); |
|
|
|
|
List<int> pre_ids = new List<int>(); |
|
|
|
|
|
|
|
|
|
int pre_count; |
|
|
|
|
int cur_count; |
|
|
|
|
|
|
|
|
|
void Start() |
|
|
|
|
{ |
|
|
|
|
cur_count = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Update() |
|
|
|
|
{ |
|
|
|
|
reset_id(); |
|
|
|
|
pre_count = cur_count; |
|
|
|
|
pre_ids.Clear(); |
|
|
|
|
cur_ids.ForEach(i => pre_ids.Add(i)); |
|
|
|
|
|
|
|
|
|
cur_count = tuio_input.touchCount; |
|
|
|
|
cur_ids.Clear(); |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < cur_count; i++) |
|
|
|
|
{ |
|
|
|
|
cur_ids.Add(tuio_input.GetTouch(i).fingerId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (cur_count > pre_count) // Add |
|
|
|
|
{ |
|
|
|
|
//Debug.Log("Add"); |
|
|
|
|
for (int i = 0; i < cur_count; i++) |
|
|
|
|
{ |
|
|
|
|
int f_id = tuio_input.GetTouch(i).fingerId; |
|
|
|
|
bool isOldTouch = pre_ids.Contains(f_id); |
|
|
|
|
if (isOldTouch == false) |
|
|
|
|
{ |
|
|
|
|
GameObject g = Instantiate(img, canvas.GetComponent<Transform>()); |
|
|
|
|
g.name = f_id.ToString(); |
|
|
|
|
//g.GetComponent<movieController>().id = i; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (cur_count < pre_count) // Remove |
|
|
|
|
{ |
|
|
|
|
//Debug.Log("Remove"); |
|
|
|
|
int exit_id; |
|
|
|
|
for (int i = 0; i < pre_count; i++) |
|
|
|
|
{ |
|
|
|
|
int _id = pre_ids[i]; |
|
|
|
|
bool isExitTouch = !cur_ids.Contains(_id); |
|
|
|
|
if (isExitTouch) |
|
|
|
|
{ |
|
|
|
|
exit_id = _id; |
|
|
|
|
//GameObject.Find(_id.ToString()).GetComponent<movieController>().stat = 2; |
|
|
|
|
Destroy(GameObject.Find(_id.ToString())); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
reset_id(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void reset_id() |
|
|
|
|
{ |
|
|
|
|
GameObject[] objs = GameObject.FindGameObjectsWithTag("onFoot"); |
|
|
|
|
//Debug.Log(objs.Length); |
|
|
|
|
for (int i = 0; i < objs.Length; i++) |
|
|
|
|
{ |
|
|
|
|
objs[i].GetComponent<movieController>().id = i - 1; |
|
|
|
|
Debug.Log(objs[i].name + " / id = " + objs[i].GetComponent<movieController>().id.ToString()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|