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.

190 lines
4.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.VFX;
using UnityEngine.UI;
using UltraCombos.Configuration;
using TUIO;
public class DebugUI : MonoBehaviour
{
public bool debugMode = true;
public GameObject debugUI;
public VisualEffect vfx;
public GameObject baseEmitter;
public GameObject target;
public GameObject emitter;
public GameObject button;
public string stat = "wait";
[Config]
[Range(0f, 5f)]
public float Emitter_x = 2.5f;
[Config]
[Range(-5f, 0f)]
public float Target_x = -2.5f;
[Config]
[Range(-3f, 3f)]
public float Common_z = 0f;
[Config]
[Range(0f, 0.05f)]
public float growingSpeed;
[Config]
[Range(10, 30)]
public float fadeSpeed;
[Config]
[Range(0f, 0.5f)]
public float smooth;
float lerp_val;
Vector3 final_pos;
bool showObject;
int cur_blob_count;
void Start()
{
QualitySettings.vSyncCount = 0;
stat = "wait";
debugUI.SetActive(debugMode);
button.GetComponent<Text>().text = stat;
lerp_val = 0;
cur_blob_count = 0;
}
// Update is called once per frame
void Update()
{
cur_blob_count = TUIOManager.Instance.touches.Count;
if (button.GetComponentInParent<Button>().interactable)
{
if (cur_blob_count == 0 && stat == "completed")
{
enterVanish();
}
else if (cur_blob_count > 0 && stat == "wait")
{
enterGrow();
}
}
updateVFX();
if (Input.GetKeyDown(KeyCode.F1))
{
debugMode = !debugMode;
debugUI.GetComponent<Canvas>().enabled = debugMode;
if (debugMode)
{
showObject = true;
setObjectVisible(showObject);
} else
{
showObject = false;
setObjectVisible(showObject);
}
}
else if (debugMode && Input.GetKeyDown(KeyCode.F2)){
showObject = !showObject;
setObjectVisible(showObject);
}
if(stat == "growing")
{
lerp_val += growingSpeed;
if(lerp_val >= 1)
{
lerp_val = 1;
stat = "completed";
StartCoroutine("sendCompleted");
Invoke("setButtonInteractable", 1);
button.GetComponent<Text>().text = stat;
Debug.Log(stat);
}
}
else if(stat == "vanishing")
{
lerp_val -= growingSpeed;
if(lerp_val <= 0)
{
lerp_val = 0;
stat = "wait";
Invoke("setButtonInteractable", 1);
button.GetComponent<Text>().text = stat;
Debug.Log(stat);
}
}
lerp_val = Mathf.Clamp(lerp_val, 0, 1);
vfx.SetFloat("Lerp_Val", lerp_val);
Transform base_trans = baseEmitter.GetComponent<Transform>();
Transform targ_trans = target.GetComponent<Transform>();
base_trans.position = new Vector3(Emitter_x, 0, Common_z);
targ_trans.position = new Vector3(Target_x, 0, Common_z);
emitter.GetComponent<Transform>().position = Vector3.Lerp(base_trans.position, targ_trans.position, lerp_val);
}
IEnumerator sendCompleted()
{
yield return new WaitForSeconds(0.5f);
vfx.SendEvent("Completed");
}
public void switchStat()
{
if(stat == "wait")
{
enterGrow();
}
else if(stat == "completed")
{
enterVanish();
}
button.GetComponent<Text>().text = stat;
}
public void enterGrow()
{
setButtonInteractable();
stat = "growing";
vfx.SendEvent("Emit");
vfx.SetBool("isGrowing", true);
button.GetComponent<Text>().text = stat;
Debug.Log(stat);
}
public void enterVanish()
{
setButtonInteractable();
stat = "vanishing";
vfx.SetBool("isGrowing", false);
button.GetComponent<Text>().text = stat;
Debug.Log(stat);
}
private void setObjectVisible(bool isShowed)
{
baseEmitter.GetComponent<Renderer>().enabled = isShowed;
target.GetComponent<Renderer>().enabled = isShowed;
emitter.GetComponent<Renderer>().enabled = isShowed;
}
private void setButtonInteractable()
{
bool _stat = button.GetComponentInParent<Button>().interactable;
button.GetComponentInParent<Button>().interactable = !_stat;
}
void updateVFX()
{
}
}