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.

108 lines
2.9 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UltraCombos.Frozen
{
public class GiantSnowflake : MonoBehaviour
{
Material material;
float alpha = 0.0f;
float smooth = 0.025f;
DShowMoviePlayer player;
[SerializeField]
KinectOpticalFlowMath kinect;
[SerializeField]
float triggerRadius = 1.5f;
[SerializeField]
float cooldown = 2.0f;
private void Start()
{
material = GetComponent<MeshRenderer>().sharedMaterial;
player = GetComponent<DShowMoviePlayer>();
StartCoroutine(Flow());
}
private void FixedUpdate()
{
if (SceneController.Instance.rate < 0.5f)
{
alpha = Mathf.Lerp(alpha, 1.0f, smooth);
}
else
{
alpha = Mathf.Lerp(alpha, 0.0f, smooth);
}
material.color = new Color(1.0f, 1.0f, 1.0f, alpha);
}
private void OnDrawGizmosSelected()
{
var pos = kinect.averagePositinon;
Gizmos.DrawWireSphere(pos, 0.5f);
if (new Vector2(pos.x - transform.position.x, pos.z - transform.position.z).magnitude < triggerRadius)
{
Gizmos.color = Color.red;
}
Gizmos.DrawWireSphere(transform.position, triggerRadius);
Gizmos.color = Color.white;
}
[SerializeField, Range(0, 1)]
float breakProgress = 0.1f;
IEnumerator Flow()
{
float video_stamp = 0.0f;
float progress = 0.0f;
while (true)
{
video_stamp = Time.time;
progress = 0.0f;
player.Pause();
player.Frame = 0;
Debug.Log("Begin");
while (progress < breakProgress)
{
var pos = kinect.averagePositinon;
float dist = new Vector2(pos.x - transform.position.x, pos.z - transform.position.z).magnitude;
if (dist < triggerRadius)
{
//Debug.Log("OK");
progress += 0.001f;
}
else
{
progress = Mathf.Max(progress - 0.001f, 0.0f);
}
player.Frame = (uint)(player.TotalNumFrames * progress);
yield return null;
}
Debug.Log("Play the rest");
player.Play();
while (player.IsFinished == false)
{
yield return null;
}
yield return new WaitForSeconds(cooldown);
Debug.Log("Flow done");
}
}
}
}