|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UltraCombos.Configuration;
|
|
|
|
|
|
|
|
|
|
|
|
public class tuio_event : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public movieController img;
|
|
|
|
|
|
public RectTransform canvas;
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<int, movieController> movies = new Dictionary<int, movieController>();
|
|
|
|
|
|
Dictionary<int, Vector2> pre_pos = new Dictionary<int, Vector2>();
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
public bool VisualizeTouches = false;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(1, 30)]
|
|
|
|
|
|
public int frame_gap = 20;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(50, 300)]
|
|
|
|
|
|
public int delta_threshold = 100;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(128, 1024)]
|
|
|
|
|
|
public int snow_size = 256;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(0.01f, 0.1f)]
|
|
|
|
|
|
public float img_fade_speed = 0.02f;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(0.01f, 5f)]
|
|
|
|
|
|
public float img_wait_sec = 2f;
|
|
|
|
|
|
|
|
|
|
|
|
[Config]
|
|
|
|
|
|
[Range(0.01f, 1.0f)]
|
|
|
|
|
|
public float snow_alpha_max = 1.0f;
|
|
|
|
|
|
//[Config]
|
|
|
|
|
|
//[Range(0f, 1f)]
|
|
|
|
|
|
//public float audio_volume = 1f;
|
|
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
GetComponent<touchVisualizer>().enabled = VisualizeTouches;
|
|
|
|
|
|
|
|
|
|
|
|
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.gameObject, canvas, false);
|
|
|
|
|
|
g.name = id.ToString();
|
|
|
|
|
|
movie = g.AddComponent<movieController>();
|
|
|
|
|
|
movie.fade_speed = img_fade_speed;
|
|
|
|
|
|
movie.wait_sec = img_wait_sec;
|
|
|
|
|
|
movie.size = new Vector2(snow_size, snow_size);
|
|
|
|
|
|
//movie.volume = audio_volume;
|
|
|
|
|
|
movie.id = id;
|
|
|
|
|
|
movie.alpha_max = snow_alpha_max;
|
|
|
|
|
|
movies.Add(id, movie);
|
|
|
|
|
|
var rt = movie.transform as RectTransform;
|
|
|
|
|
|
rt.anchoredPosition = touches[id].position;
|
|
|
|
|
|
//movie.transform.position = touches[id].position;
|
|
|
|
|
|
pre_pos[id] = touches[id].position;
|
|
|
|
|
|
}
|
|
|
|
|
|
else //update
|
|
|
|
|
|
{
|
|
|
|
|
|
movie = movies[id];
|
|
|
|
|
|
|
|
|
|
|
|
if (Time.frameCount % frame_gap == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
var rt = movie.transform as RectTransform;
|
|
|
|
|
|
float delta_pos = Vector2.Distance(pre_pos[id], rt.anchoredPosition);
|
|
|
|
|
|
//Debug.Log(delta_pos);
|
|
|
|
|
|
if (delta_pos > delta_threshold)
|
|
|
|
|
|
{
|
|
|
|
|
|
movie.force_destroy = true;
|
|
|
|
|
|
movie.destroy_timer = Time.time;
|
|
|
|
|
|
movies.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
pre_pos[id] = touches[id].position;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
var removes = new HashSet<int>();
|
|
|
|
|
|
foreach (var id in movies.Keys)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (touches.ContainsKey(id) == false) // remove
|
|
|
|
|
|
{
|
|
|
|
|
|
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.Remove(id);
|
|
|
|
|
|
pre_pos.Remove(id);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|