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. 52
      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
value:
objectReference: {fileID: 914806966}
- target: {fileID: 2829506254029656376, guid: 8bbc036a3be21954681613cbe4f0e9a8,
type: 3}
propertyPath: fade_speed
value: 0.02
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 8bbc036a3be21954681613cbe4f0e9a8, type: 3}
--- !u!224 &490275148 stripped

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

@ -23,10 +23,6 @@ public class tuio_event : MonoBehaviour
// 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));
@ -54,17 +50,17 @@ public class tuio_event : MonoBehaviour
}
}
}
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)
bool isExitTouch = !cur_ids.Contains(_id);
if (isExitTouch)
{
Destroy(GameObject.Find(_id.ToString()));
GameObject.Find(_id.ToString()).GetComponent<movieController>().stat = 2;
//Destroy(GameObject.Find(_id.ToString()));
}
}
}

Loading…
Cancel
Save