[Puzzles] Add basic framework for ScriptableObject puzzle steps and puzzle solving.
This commit is contained in:
62
Assets/Scripts/DebugUIMessage.cs
Normal file
62
Assets/Scripts/DebugUIMessage.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System.Collections;
|
||||
|
||||
public class DebugUIMessage : MonoBehaviour
|
||||
{
|
||||
private static DebugUIMessage instance;
|
||||
private Text messageText;
|
||||
private Canvas canvas;
|
||||
private Coroutine hideCoroutine;
|
||||
|
||||
public static void Show(string message, float duration = 2f)
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
var go = new GameObject("DebugUIMessage");
|
||||
instance = go.AddComponent<DebugUIMessage>();
|
||||
instance.SetupUI();
|
||||
DontDestroyOnLoad(go);
|
||||
}
|
||||
instance.ShowMessage(message, duration);
|
||||
}
|
||||
|
||||
private void SetupUI()
|
||||
{
|
||||
canvas = new GameObject("DebugUICanvas").AddComponent<Canvas>();
|
||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
||||
canvas.sortingOrder = 9999;
|
||||
canvas.gameObject.transform.SetParent(transform);
|
||||
var textGO = new GameObject("DebugUIText");
|
||||
textGO.transform.SetParent(canvas.transform);
|
||||
messageText = textGO.AddComponent<Text>();
|
||||
messageText.alignment = TextAnchor.MiddleCenter;
|
||||
messageText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
|
||||
messageText.fontSize = 32;
|
||||
messageText.color = Color.yellow;
|
||||
var rect = messageText.GetComponent<RectTransform>();
|
||||
rect.anchorMin = new Vector2(0.5f, 0.1f);
|
||||
rect.anchorMax = new Vector2(0.5f, 0.1f);
|
||||
rect.pivot = new Vector2(0.5f, 0.5f);
|
||||
rect.anchoredPosition = Vector2.zero;
|
||||
rect.sizeDelta = new Vector2(800, 100);
|
||||
messageText.text = "";
|
||||
}
|
||||
|
||||
private void ShowMessage(string message, float duration)
|
||||
{
|
||||
messageText.text = message;
|
||||
messageText.enabled = true;
|
||||
if (hideCoroutine != null)
|
||||
StopCoroutine(hideCoroutine);
|
||||
hideCoroutine = StartCoroutine(HideAfterSeconds(duration));
|
||||
}
|
||||
|
||||
private IEnumerator HideAfterSeconds(float seconds)
|
||||
{
|
||||
yield return new WaitForSeconds(seconds);
|
||||
messageText.text = "";
|
||||
messageText.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user