|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class tuio_event : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Input.GetKeyDown(KeyCode.K))
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(GameObject.Find("eee"));
|
|
|
|
|
|
}
|
|
|
|
|
|
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 _id = tuio_input.GetTouch(i).fingerId;
|
|
|
|
|
|
bool isOldTouch = pre_ids.Contains(_id);
|
|
|
|
|
|
if (isOldTouch == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
GameObject g = Instantiate(img, canvas.GetComponent<Transform>());
|
|
|
|
|
|
g.name = _id.ToString();
|
|
|
|
|
|
g.GetComponent<movieController>().id = i;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
else if (cur_count < pre_count) // Remove
|
|
|
|
|
|
{
|
|
|
|
|
|
//Debug.Log("Remove");
|
|
|
|
|
|
for (int i = 0; i < pre_count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
int _id = pre_ids[i];
|
|
|
|
|
|
bool isExitTouch = cur_ids.Contains(_id);
|
|
|
|
|
|
if (isExitTouch == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Destroy(GameObject.Find(_id.ToString()));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
//Vector2 pos = tuio_input.GetTouch(0).position;
|
|
|
|
|
|
//img.GetComponent<RectTransform>().position = new Vector3(pos.x, pos.y, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|