using UnityEngine; using UnityEditor; using UnityEngine.UI; using TMPro; public class TaskTimerSetup : EditorWindow { private float taskDuration = 300f; private bool useTextMeshPro = true; private float canvasDistance = 2f; private Vector3 canvasPosition = new Vector3(0, 1.5f, 2f); [MenuItem("Tools/Setup Task Timer for VR")] public static void ShowWindow() { GetWindow("Task Timer Setup"); } private void OnGUI() { GUILayout.Label("Task Timer VR Setup", EditorStyles.boldLabel); GUILayout.Space(10); taskDuration = EditorGUILayout.FloatField("Task Duration (seconds)", taskDuration); useTextMeshPro = EditorGUILayout.Toggle("Use TextMeshPro", useTextMeshPro); canvasDistance = EditorGUILayout.FloatField("Distance from Camera", canvasDistance); canvasPosition = EditorGUILayout.Vector3Field("Canvas Position", canvasPosition); GUILayout.Space(10); if (GUILayout.Button("Create Task Timer UI", GUILayout.Height(30))) { CreateTaskTimerUI(); } GUILayout.Space(10); EditorGUILayout.HelpBox( "This will create:\n" + "• World Space Canvas for VR\n" + "• Timer display (TextMeshPro or UI Text)\n" + "• TaskTimer script configured and ready\n\n" + "The timer will automatically switch to Lobby scene when time expires.", MessageType.Info); } private void CreateTaskTimerUI() { // Create Canvas GameObject canvasObj = new GameObject("TaskTimer_Canvas"); Canvas canvas = canvasObj.AddComponent(); canvas.renderMode = RenderMode.WorldSpace; CanvasScaler scaler = canvasObj.AddComponent(); scaler.dynamicPixelsPerUnit = 10; canvasObj.AddComponent(); // Set canvas transform for VR RectTransform canvasRect = canvasObj.GetComponent(); canvasRect.sizeDelta = new Vector2(400, 100); canvasRect.localScale = new Vector3(0.01f, 0.01f, 0.01f); canvasRect.position = canvasPosition; // Create Panel Background GameObject panelObj = new GameObject("Background_Panel"); panelObj.transform.SetParent(canvasObj.transform, false); Image panelImage = panelObj.AddComponent(); panelImage.color = new Color(0, 0, 0, 0.7f); RectTransform panelRect = panelObj.GetComponent(); panelRect.anchorMin = new Vector2(0, 0); panelRect.anchorMax = new Vector2(1, 1); panelRect.sizeDelta = Vector2.zero; // Create Timer Text GameObject textObj = new GameObject("Timer_Text"); textObj.transform.SetParent(panelObj.transform, false); TaskTimer timerScript = canvasObj.AddComponent(); timerScript.taskDuration = taskDuration; timerScript.autoStart = true; RectTransform textRect; if (useTextMeshPro) { TextMeshProUGUI tmpText = textObj.AddComponent(); tmpText.text = "00:00"; tmpText.fontSize = 60; tmpText.alignment = TextAlignmentOptions.Center; tmpText.color = Color.white; tmpText.font = Resources.Load("Fonts & Materials/LiberationSans SDF"); timerScript.timerTextTMP = tmpText; textRect = textObj.GetComponent(); } else { Text legacyText = textObj.AddComponent(); legacyText.text = "00:00"; legacyText.fontSize = 60; legacyText.alignment = TextAnchor.MiddleCenter; legacyText.color = Color.white; legacyText.font = Resources.GetBuiltinResource("Arial.ttf"); timerScript.timerTextLegacy = legacyText; textRect = textObj.GetComponent(); } // Configure RectTransform after UI component is added textRect.anchorMin = new Vector2(0, 0); textRect.anchorMax = new Vector2(1, 1); textRect.sizeDelta = Vector2.zero; // Select the created object Selection.activeGameObject = canvasObj; Debug.Log("Task Timer UI created successfully! Configure position as needed for your VR setup."); } }