You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
3.3 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
6 years ago
using UnityEngine.Events;
using UnityEngine.UI;
6 years ago
using UltraCombos;
public class movieController : MonoBehaviour
{
6 years ago
DShowMoviePlayer player;
AudioSource aud;
public int id;
6 years ago
public int stat;
public float fade_speed;
public bool force_destroy;
public float destroy_timer;
public float wait_sec = 2f;
public float volume = 1f;
public DShowClip snow_01;
public DShowClip snow_02;
public DShowClip snow_03;
public DShowClip snow_04;
public AudioClip step1;
public AudioClip step2;
public AudioClip step3;
public AudioClip step4;
bool playAud;
float alpha;
6 years ago
void Awake()
{
player = GetComponent<DShowMoviePlayer>();
//aud = GetComponent<AudioSource>();
stat = 0;
force_destroy = false;
6 years ago
}
void Start()
{
6 years ago
//player = GetComponent<DShowMoviePlayer>();
6 years ago
GetComponent<RawImage>().color = Color.clear;
}
void Update()
{
aud.volume = volume;
if (playAud && aud.clip != null)
{
Debug.Log(aud.clip.name);
aud.Play();
playAud = false;
}
if(stat == 0){
alpha = 0;
if (player.IsPlaying)
stat = 1;
6 years ago
}
else if (stat == 1)
6 years ago
{
alpha += fade_speed * 5f;
if (alpha >= 1)
6 years ago
{
alpha = 1;
6 years ago
stat = 2;
}
}
else
if (stat == 2 && force_destroy)
{
stat = 3;
}
else if (stat == 3)
{
float t = Time.time;
if (t - destroy_timer > wait_sec)
{
//Debug.Log("fade");
alpha -= fade_speed;
if (alpha < 0)
{
Destroy(this.gameObject);
}
}
}
GetComponent<RawImage>().color = new Color(1f, 1f, 1f, alpha);
}
void OnEnable()
{
aud = gameObject.AddComponent<AudioSource>();
int seed = Random.Range(0, 4);
switch (seed){
case 0:
player.VideoAsset = snow_01;
aud.clip = step1;
break;
case 1:
player.VideoAsset = snow_02;
aud.clip = step2;
break;
case 2:
player.VideoAsset = snow_03;
aud.clip = step3;
break;
case 3:
player.VideoAsset = snow_04;
aud.clip = step4;
break;
}
//aud.Play();
playAud = true;
6 years ago
if (name != "RawImage") {
GetComponent<RawImage>().enabled = true;
}
6 years ago
//Debug.Log("Hi");
stat = 0;
alpha = 0f;
rotateImg();
player.Play();
}
void OnDestroy()
{
6 years ago
//Debug.Log("Bye");
}
public void rotateImg()
{
Vector3 rot_axis = new Vector3(0, 0, 1);
Vector3 mid_pt = new Vector3(GetComponent<RectTransform>().position.x, GetComponent<RectTransform>().position.y, 0);
float rand_deg = Random.Range(0, 360);
GetComponent<RectTransform>().Rotate(rot_axis, rand_deg);
}
}