add fade effect

master
tigerchen 6 years ago
parent 438e62751f
commit 62cc5034c3
  1. 5
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scenes/DarkSea.unity
  2. 56
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/movieController.cs
  3. 12
      08_DarkSea/Unity-19050-08-DarkSea/19050-08-DarkSea/Assets/Scripts/tuio_event.cs

@ -418,6 +418,11 @@ PrefabInstance:
propertyPath: tuio_event propertyPath: tuio_event
value: value:
objectReference: {fileID: 914806966} objectReference: {fileID: 914806966}
- target: {fileID: 2829506254029656376, guid: 8bbc036a3be21954681613cbe4f0e9a8,
type: 3}
propertyPath: fade_speed
value: 0.02
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8bbc036a3be21954681613cbe4f0e9a8, type: 3} m_SourcePrefab: {fileID: 100100000, guid: 8bbc036a3be21954681613cbe4f0e9a8, type: 3}
--- !u!224 &490275148 stripped --- !u!224 &490275148 stripped

@ -8,70 +8,66 @@ public class movieController : MonoBehaviour
public float totalTime = 0.5f; public float totalTime = 0.5f;
public int id; public int id;
public tuio_event tuio_event; public tuio_event tuio_event;
int stat; public float fade_speed = 0.02f;
public int stat;
Vector2 final_size; Vector2 final_size;
float c;
Vector2 pos, pre_pos;
//public Transform trans; //public Transform trans;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
final_size = GetComponent<RectTransform>().sizeDelta = Vector2.zero; final_size = GetComponent<RectTransform>().sizeDelta;
GetComponent<RectTransform>().sizeDelta = Vector2.zero; GetComponent<RawImage>().color = Color.clear;
stat = 0; pos = Vector2.zero;
} }
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if(name == "RawImage") //Debug.Log(stat);
pre_pos = pos;
if (name == "RawImage")
{ {
GetComponent<RawImage>().enabled = false; GetComponent<RawImage>().enabled = false;
} }
else else
{ {
GetComponent<RawImage>().enabled = true; GetComponent<RawImage>().enabled = true;
//Debug.Log(stat);
} }
if (tuio_event.tuio_input.touchCount > 0) if (tuio_event.tuio_input.touchCount > 0)
{ {
transform.gameObject.SetActive(true); transform.gameObject.SetActive(true);
Vector2 pos = tuio_event.tuio_input.GetTouch(id).position; if (stat == 1)
pos = tuio_event.tuio_input.GetTouch(id).position;
else if (stat == 2)
pos = pre_pos;
GetComponent<RectTransform>().position = new Vector3(pos.x, pos.y, 0); GetComponent<RectTransform>().position = new Vector3(pos.x, pos.y, 0);
} }
} if(stat == 1)
{
void wake() c += fade_speed;
{ }
else if (stat == 2)
}
void die()
{
Destroy(this);
}
void doScaling(float to)
{
float from = transform.localScale.x;
float scale = from;
float startTime = Time.time;
while (scale != to)
{ {
float duration = Time.time - startTime; c -= fade_speed;
scale = Mathf.Lerp(from, to, duration / totalTime); if (c < 0f) Destroy(gameObject);
transform.localScale = new Vector3(scale, scale, 1);
} }
c = Mathf.Clamp(c, 0f, 1f);
GetComponent<RawImage>().color = new Color(1f, 1f, 1f, c);
} }
private void OnEnable() private void OnEnable()
{ {
//doScaling(1); stat = 1;
c = 0f;
Debug.Log("Hi"); Debug.Log("Hi");
} }
private void OnDestroy() private void OnDestroy()
{ {
//doScaling(0);
Debug.Log("Bye"); Debug.Log("Bye");
} }
} }

@ -23,10 +23,6 @@ public class tuio_event : MonoBehaviour
// Update is called once per frame // Update is called once per frame
void Update() void Update()
{ {
if (Input.GetKeyDown(KeyCode.K))
{
Destroy(GameObject.Find("eee"));
}
pre_count = cur_count; pre_count = cur_count;
pre_ids.Clear(); pre_ids.Clear();
cur_ids.ForEach(i => pre_ids.Add(i)); cur_ids.ForEach(i => pre_ids.Add(i));
@ -54,17 +50,17 @@ public class tuio_event : MonoBehaviour
} }
} }
} }
else if (cur_count < pre_count) // Remove else if (cur_count < pre_count) // Remove
{ {
//Debug.Log("Remove"); //Debug.Log("Remove");
for (int i = 0; i < pre_count; i++) for (int i = 0; i < pre_count; i++)
{ {
int _id = pre_ids[i]; int _id = pre_ids[i];
bool isExitTouch = cur_ids.Contains(_id); bool isExitTouch = !cur_ids.Contains(_id);
if (isExitTouch == false) if (isExitTouch)
{ {
Destroy(GameObject.Find(_id.ToString())); GameObject.Find(_id.ToString()).GetComponent<movieController>().stat = 2;
//Destroy(GameObject.Find(_id.ToString()));
} }
} }
} }

Loading…
Cancel
Save