add fade out & remove update

master
tigerchen 6 years ago
parent 24f5de0ac6
commit ea3f62996a
  1. 23
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs
  2. 24
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs

@ -13,6 +13,8 @@ public class movieController : MonoBehaviour
public float fade_speed = 0.02f; public float fade_speed = 0.02f;
public int stat; public int stat;
float c; float c;
public float destroy_timer;
float wait_sec = 3f;
//Vector2 pos, pre_pos; //Vector2 pos, pre_pos;
//public Transform trans; //public Transform trans;
@ -66,14 +68,29 @@ public class movieController : MonoBehaviour
if (stat == 1) if (stat == 1)
{ {
c += fade_speed; c += fade_speed;
if(c > 1) if (c > 1)
{ {
c = 1; c = 1;
stat = 2; stat = 2;
} }
GetComponent<RawImage>().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<RawImage>().color = new Color(1f, 1f, 1f, c);
} }
void OnEnable() void OnEnable()

@ -23,28 +23,38 @@ public class tuio_event : MonoBehaviour
movie = g.AddComponent<movieController>(); movie = g.AddComponent<movieController>();
movie.id = id; movie.id = id;
movies.Add(id, movie); movies.Add(id, movie);
movie.transform.position = touches[id].position;
} }
else //update else //update
{
movie = movies[id]; movie = movies[id];
}
//update or after adding //update or after adding
//Debug.Log("Update"); //Debug.Log("Update");
movie.transform.position = touches[id].position; //movie.transform.position = touches[id].position;
} }
var removes = new HashSet<int>(); var removes = new HashSet<int>();
foreach (var id in movies.Keys) foreach (var id in movies.Keys)
{ {
if (touches.ContainsKey(id) == false) // remove if (touches.ContainsKey(id) == false) // remove
{ {
Debug.Log("Remove"); //Destroy(movies[id].gameObject);
Destroy(movies[id].gameObject);
//movies.Remove(id); //movies.Remove(id);
removes.Add(id); removes.Add(id);
} }
} }
foreach (var id in removes) 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 #else
// Start is called before the first frame update // Start is called before the first frame update

Loading…
Cancel
Save