You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.7 KiB

6 years ago
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class tuio_event : MonoBehaviour
{
6 years ago
#if true
public GameObject img;
public Transform canvas;
//public UltraCombos.GlobalMKHookInput tuio_input;
Dictionary<int, movieController> movies = new Dictionary<int, movieController>();
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);
}
else //update
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
{
Debug.Log("Remove");
Destroy(movies[id].gameObject);
//movies.Remove(id);
removes.Add(id);
}
}
foreach (var id in removes)
movies.Remove(id);
}
#else
6 years ago
// Start is called before the first frame update
public GameObject img;
public GameObject canvas;
6 years ago
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;
6 years ago
void Start()
{
cur_count = 0;
6 years ago
}
void Update()
{
6 years ago
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
6 years ago
{
//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
6 years ago
{
//Debug.Log("Remove");
6 years ago
int exit_id;
for (int i = 0; i < pre_count; i++)
{
int _id = pre_ids[i];
6 years ago
bool isExitTouch = !cur_ids.Contains(_id);
if (isExitTouch)
{
6 years ago
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");
6 years ago
//Debug.Log(objs.Length);
for (int i = 0; i < objs.Length; i++)
{
objs[i].GetComponent<movieController>().id = i - 1;
6 years ago
Debug.Log(objs[i].name + " / id = " + objs[i].GetComponent<movieController>().id.ToString());
6 years ago
}
}
6 years ago
#endif
6 years ago
}