Add UI to show available guards and doors
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
using DefaultNamespace;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
|
||||
public class DoorManager : MonoBehaviour
|
||||
public class DoorManager : MonoBehaviour, IDescribable
|
||||
{
|
||||
public string type;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
@@ -53,4 +54,14 @@ public class DoorManager : MonoBehaviour
|
||||
//else return base
|
||||
return answer;
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
return "Describe " + type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ using System;
|
||||
using DefaultNamespace;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
|
||||
public class GuardManager : MonoBehaviour
|
||||
public class GuardManager : MonoBehaviour, IDescribable
|
||||
{
|
||||
public string type;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
@@ -93,4 +94,14 @@ public class GuardManager : MonoBehaviour
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
return "Describe " + type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,8 @@ public class LevelLoader : Singleton<LevelLoader>
|
||||
|
||||
//dynamic dialog tree
|
||||
SpeechTree = JObject.Parse(levels[0].text)["dialog"] as JObject;
|
||||
|
||||
StatusManager.Instance.PopulatePanels();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
|
||||
public class StatusManager : Singleton<StatusManager>
|
||||
{
|
||||
public Transform doorPanel;
|
||||
public GameObject doorPrefab;
|
||||
public Transform guardPanel;
|
||||
public GameObject guardPrefab;
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void PopulatePanels()
|
||||
{
|
||||
PopulatePanel(doorPanel, doorPrefab, LevelLoader.Instance.Doors.Cast<IDescribable>().ToList());
|
||||
PopulatePanel(guardPanel, guardPrefab, LevelLoader.Instance.Guards.Cast<IDescribable>().ToList());
|
||||
}
|
||||
|
||||
private void PopulatePanel(Transform panel, GameObject template, List<IDescribable> items)
|
||||
{
|
||||
foreach (Transform child in panel)
|
||||
{
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
foreach (IDescribable item in items)
|
||||
{
|
||||
var obj = Instantiate(template, panel);
|
||||
|
||||
var titleMesh = obj.transform.FindChildRecursive("TITLE").GetComponent<TextMeshProUGUI>();
|
||||
var descMesh = obj.transform.FindChildRecursive("DESC").GetComponent<TextMeshProUGUI>();
|
||||
|
||||
titleMesh.text = item.GetName();
|
||||
descMesh.text = item.GetDescription();
|
||||
}
|
||||
}
|
||||
|
||||
private Dictionary<RectTransform, bool> panelStates = new();
|
||||
private float slideDuration = 0.3f;
|
||||
|
||||
public void TogglePanel(RectTransform panel)
|
||||
{
|
||||
if (!panelStates.ContainsKey(panel))
|
||||
panelStates[panel] = true; // Initially open
|
||||
|
||||
bool isOpen = panelStates[panel];
|
||||
|
||||
|
||||
|
||||
bool leftAligned = panel.anchorMin.x == 0f;
|
||||
|
||||
StartCoroutine(
|
||||
SlidePanel(panel, !isOpen, panel.rect.width * (leftAligned ? 1 : -1))
|
||||
);
|
||||
|
||||
panelStates[panel] = !isOpen;
|
||||
}
|
||||
|
||||
private IEnumerator SlidePanel(RectTransform rect, bool open, float dist)
|
||||
{
|
||||
Vector2 start = rect.anchoredPosition;
|
||||
|
||||
Vector2 target = open
|
||||
? start + Vector2.right * dist
|
||||
: start + Vector2.left * dist;
|
||||
|
||||
float elapsed = 0f;
|
||||
|
||||
while (elapsed < slideDuration)
|
||||
{
|
||||
elapsed += Time.deltaTime;
|
||||
|
||||
float t = Mathf.SmoothStep(
|
||||
0f,
|
||||
1f,
|
||||
elapsed / slideDuration
|
||||
);
|
||||
|
||||
rect.anchoredPosition = Vector2.Lerp(start, target, t);
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
rect.anchoredPosition = target;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 083d5cb0fbf072b8595a3f7edba0a6ed
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Utils
|
||||
{
|
||||
public interface IDescribable
|
||||
{
|
||||
public string GetName();
|
||||
public string GetDescription();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 824d28ca86a740f7b45d39b9049cf2c1
|
||||
timeCreated: 1787656397
|
||||
@@ -21,5 +21,16 @@ namespace Utils
|
||||
{
|
||||
public string type;
|
||||
public string action;
|
||||
|
||||
|
||||
public string GetName()
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
public string GetDescription()
|
||||
{
|
||||
return "Describe " + action;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user