|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class tuio_event : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
#if true
|
|
|
|
|
|
public GameObject img;
|
|
|
|
|
|
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;
|
|
|
|
|
|
foreach (var id in touches.Keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
movieController movie = null;
|
|
|
|
|
|
if (movies.ContainsKey(id) == false) // Add
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.Log("Add");
|
|
|
|
|
|
GameObject g = Instantiate(img, canvas);
|
|
|
|
|
|
g.name = id.ToString();
|
|
|
|
|
|
movie = g.AddComponent<movieController>();
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
var removes = new HashSet<int>();
|
|
|
|
|
|
foreach (var id in movies.Keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (touches.ContainsKey(id) == false) // remove
|
|
|
|
|
|
{
|
|
|
|
|
|
//Destroy(movies[id].gameObject);
|
|
|
|
|
|
//movies.Remove(id);
|
|
|
|
|
|
removes.Add(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var id in removes)
|
|
|
|
|
|
{
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
|
|
|
}
|