using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.VFX; using UnityEngine.UI; using Assets.WasapiAudio.Scripts.Unity; public class Loader : MonoBehaviour { public KeyCode NextButton = KeyCode.Space; public KeyCode PrevButton = KeyCode.Return; public KeyCode MenuButton = KeyCode.Escape; public GameObject[] vis; public GameObject menu; public Text currentVis; private int _current = 0; private int _count; private bool _menu_visible = false; void Awake() { vis = GameObject.FindGameObjectsWithTag("VFX"); _count = vis.Length; foreach (GameObject v in vis) { // all visualisations are active // but their vfx components are disabled in editor v.SetActive(false); v.GetComponent().enabled = true; // v.GetComponent().enabled = true; // look for a canvas in children // bit sketchy... Canvas v_menu = v.GetComponentInChildren(); if (v_menu) v_menu.enabled = false; } ToggleMenu(_menu_visible); } void Start() { foreach (GameObject v in vis) { Debug.Log(v.ToString()); } foreach (var device in Microphone.devices) { Debug.Log("Microphone: " + device); } LoadVis(0); } void Update() { if (Input.GetKeyDown(NextButton)) { LoadNextVis(); } if (Input.GetKeyDown(MenuButton)) { ToggleMenu(!_menu_visible); } } void LoadVis(int i) { _current = i; vis[i].SetActive(true); currentVis.text = vis[i].name; // ensure menu is synced on vis change ToggleMenu(_menu_visible); } void LoadNextVis() { vis[_current].SetActive(false); int next = (_current + 1) % _count; LoadVis(next); } void VisMenuVisible(int i, bool v) { Canvas v_menu = vis[i].GetComponentInChildren(); if (v_menu) v_menu.enabled = v; } void ToggleMenu(bool visible) { if (visible) { menu.GetComponent().enabled = true; VisMenuVisible(_current, true); } else { menu.GetComponent().enabled = false; VisMenuVisible(_current, false); } _menu_visible = visible; } }