using System; using UnityEngine; [Serializable] public class UnluckFlagGUI : MonoBehaviour { public GameObject[] prefabs; public Material[] bgrs; public Light[] lights; public GameObject nextButton; public GameObject prevButton; public GameObject bgrButton; public GameObject lightButton; public GameObject texturePreview; private GameObject activeObj; private int counter; private int bCounter; private int lCounter; public TextMesh txt; public TextMesh debug; public virtual void Start() { Swap(); if (!txt) { txt = (TextMesh)transform.Find("txt").GetComponent(typeof(TextMesh)); } if (!nextButton) { nextButton = (GameObject)(object)transform.Find("nextButton").GetComponent(typeof(GameObject)); } if (!prevButton) { prevButton = (GameObject)(object)transform.Find("prevButton").GetComponent(typeof(GameObject)); } if (!bgrButton) { bgrButton = (GameObject)(object)transform.Find("bgrButton").GetComponent(typeof(GameObject)); } if (!lightButton) { lightButton = transform.Find("lightButton").gameObject; } if (!texturePreview) { texturePreview = (GameObject)(object)transform.Find("texturePreview").GetComponent(typeof(GameObject)); } if (!debug) { debug = (TextMesh)transform.Find("debug").GetComponent(typeof(TextMesh)); } } public virtual void Update() { if (Input.GetMouseButtonUp(0)) { ButtonUp(); } if (Input.GetKeyUp("right")) { Next(); } if (Input.GetKeyUp("left")) { Prev(); } if (Input.GetKeyUp("space")) { nextButton.SetActive(!nextButton.activeInHierarchy); prevButton.SetActive(nextButton.activeInHierarchy); bgrButton.SetActive(nextButton.activeInHierarchy); texturePreview.SetActive(nextButton.activeInHierarchy); txt.gameObject.SetActive(nextButton.activeInHierarchy); } } public virtual void ButtonUp() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo = default(RaycastHit); if (Physics.Raycast(ray, out hitInfo)) { if (hitInfo.transform.gameObject == nextButton) { Next(); } else if (hitInfo.transform.gameObject == prevButton) { Prev(); } else if (hitInfo.transform.gameObject == bgrButton) { NextBgr(); } else if (hitInfo.transform.gameObject == lightButton) { LightChange(); } } } public virtual void LightChange() { if (lights.Length > 0) { lights[lCounter].enabled = false; lCounter++; if (lCounter >= lights.Length) { lCounter = 0; } lights[lCounter].enabled = true; } } public virtual void NextBgr() { if (bgrs.Length > 0) { bCounter++; if (bCounter >= bgrs.Length) { bCounter = 0; } RenderSettings.skybox = bgrs[bCounter]; } } public virtual void Next() { counter++; if (counter > prefabs.Length - 1) { counter = 0; } Swap(); } public virtual void Prev() { counter--; if (counter < 0) { counter = prefabs.Length - 1; } Swap(); } public virtual void Swap() { if (prefabs.Length > 0) { UnityEngine.Object.Destroy(activeObj); GameObject gameObject = UnityEngine.Object.Instantiate(prefabs[counter]); activeObj = gameObject; if ((bool)txt) { txt.text = activeObj.name; txt.text = txt.text.Replace("(Clone)", string.Empty); txt.text = txt.text + " " + ((UnluckAnimatedMesh)activeObj.GetComponent(typeof(UnluckAnimatedMesh))).meshContainerFBX.name; txt.text = txt.text.Replace("_", " "); txt.text = txt.text.Replace("Flag ", string.Empty); } if ((bool)texturePreview) { ((Renderer)texturePreview.GetComponent(typeof(Renderer))).sharedMaterial = ((Renderer)activeObj.GetComponent(typeof(Renderer))).sharedMaterial; } } } public virtual void Main() { } }