using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Experimental.VFX; using UnityEngine.UI; 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 float growingSpeed; public string stat = "wait"; float spawn_t; float total_t; float lerp_val; Vector3 final_pos; bool showObject; void Start() { stat = "wait"; debugUI.SetActive(debugMode); button.GetComponent().text = stat; spawn_t = 0; total_t = 0; lerp_val = 0; } // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.A)) { debugMode = !debugMode; debugUI.SetActive(debugMode); if (debugMode) { showObject = true; setObjectVisible(showObject); } else { showObject = false; setObjectVisible(showObject); } } else if (debugMode && Input.GetKeyDown(KeyCode.D)){ showObject = !showObject; setObjectVisible(showObject); } if(stat == "growing") { total_t += Time.deltaTime; lerp_val += growingSpeed; if(lerp_val >= 1) { lerp_val = 1; stat = "completed"; //vfx.SendEvent("Completed"); StartCoroutine("sendCompleted"); setButtonInteractable(true); button.GetComponent().text = stat; Debug.Log(stat); } } else if(stat == "vanishing") { vfx.SetBool("isEnteringVanish", false); lerp_val -= growingSpeed; if(lerp_val <= 0) { lerp_val = 0; stat = "wait"; setButtonInteractable(true); button.GetComponent().text = stat; Debug.Log(stat); } } lerp_val = Mathf.Clamp(lerp_val, 0, 1); vfx.SetFloat("_LerpVal", lerp_val); Vector3 base_pos = baseEmitter.GetComponent().position; Vector3 target_pos = target.GetComponent().position; emitter.GetComponent().position = Vector3.Lerp(base_pos, target_pos, lerp_val); /* if (debugMode && Input.GetMouseButtonDown(0)) { ray = Camera.main.ScreenPointToRay(Input.mousePosition); GameObject selected_obj = null; if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 200.0f)) { selected_obj = hit.collider.gameObject; Debug.Log("hit!!" + selected_obj.name); } if(selected_obj != null) { selected_obj.GetComponent().material.color = new Color(255, 100, 100); } } */ } 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 = stat; } public void enterGrow() { setButtonInteractable(false); spawn_t = total_t; stat = "growing"; vfx.SendEvent("MouseDown"); vfx.SetBool("isGrowing", true); Debug.Log(stat); } public void enterVanish() { setButtonInteractable(false); vfx.SetBool("isEnteringVanish", true); stat = "vanishing"; vfx.SendEvent("MouseUp"); vfx.SetBool("isGrowing", false); Debug.Log(stat); } private void setObjectVisible(bool isShowed) { baseEmitter.GetComponent().enabled = isShowed; target.GetComponent().enabled = isShowed; emitter.GetComponent().enabled = isShowed; } private void setButtonInteractable(bool _stat) { //GameObject g = GameObject.Find("Grow"); //GameObject v = GameObject.Find("Vanish"); //g.GetComponent