From ea3f62996a83bf33f737a1faf15368aa24a69b1b Mon Sep 17 00:00:00 2001 From: tigerchen Date: Fri, 6 Dec 2019 17:13:42 +0800 Subject: [PATCH] add fade out & remove update --- .../Assets/Scripts/movieController.cs | 23 +++++++++++++++--- .../Assets/Scripts/tuio_event.cs | 24 +++++++++++++------ 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs b/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs index ba8738e..17269ad 100644 --- a/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs +++ b/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs @@ -13,6 +13,8 @@ public class movieController : MonoBehaviour public float fade_speed = 0.02f; public int stat; float c; + public float destroy_timer; + float wait_sec = 3f; //Vector2 pos, pre_pos; //public Transform trans; @@ -66,14 +68,29 @@ public class movieController : MonoBehaviour if (stat == 1) { c += fade_speed; - if(c > 1) + if (c > 1) { c = 1; stat = 2; } - GetComponent().color = new Color(1f, 1f, 1f, c); - } + } + else if (stat == 3) + { + float t = Time.time; + if (t - destroy_timer > wait_sec) + { + Debug.Log("fade"); + c -= fade_speed; + if (c < 0) + { + Destroy(this.gameObject); + } + } + + } + + GetComponent().color = new Color(1f, 1f, 1f, c); } void OnEnable() diff --git a/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs b/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs index 96b730e..4dea273 100644 --- a/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs +++ b/08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs @@ -23,28 +23,38 @@ public class tuio_event : MonoBehaviour movie = g.AddComponent(); movie.id = id; movies.Add(id, movie); + movie.transform.position = touches[id].position; } else //update + { movie = movies[id]; - + } //update or after adding //Debug.Log("Update"); - movie.transform.position = touches[id].position; - + //movie.transform.position = touches[id].position; } var removes = new HashSet(); foreach (var id in movies.Keys) { if (touches.ContainsKey(id) == false) // remove - { - Debug.Log("Remove"); - Destroy(movies[id].gameObject); + { + //Destroy(movies[id].gameObject); //movies.Remove(id); removes.Add(id); } } foreach (var id in removes) - movies.Remove(id); + { + if (movies[id].stat == 2) + { + movies[id].stat = 3; + movies[id].destroy_timer = Time.time; + movies.Remove(id); + Debug.Log("Remove"); + } + //movies[id].destroy_timer = Time.time; + } + //movies.Remove(id); } #else // Start is called before the first frame update