Files
modular-vr/Assets/Engine/Runtime/UI/PuzzlePlan.cs
2022-12-15 23:29:02 +01:00

56 lines
1.7 KiB
C#

using System.Collections.Generic;
using EscapeRoomEngine.Engine.Runtime.Modules;
using NaughtyAttributes;
using UnityEngine;
using UnityEngine.UI;
namespace EscapeRoomEngine.Engine.Runtime.UI
{
public class PuzzlePlan : MonoBehaviour
{
[SerializeField]
private Vector2 entryOffset;
[BoxGroup("Internal")] [SerializeField]
private RectTransform plan;
[BoxGroup("Internal")] [SerializeField]
private PuzzlePlanEntry currentPuzzle, entryPrefab;
[BoxGroup("Internal")] [SerializeField]
private GameObject currentPuzzleTitle, planTitle;
public PuzzleModuleDescription CurrentPuzzle
{
set
{
currentPuzzleTitle.SetActive(true);
currentPuzzle.gameObject.SetActive(true);
// set the current puzzle
currentPuzzle.Puzzle = value;
}
}
public List<PuzzleModuleDescription> Puzzles
{
set
{
planTitle.SetActive(true);
plan.gameObject.SetActive(true);
// remove the old children
foreach (RectTransform child in plan)
{
Destroy(child.gameObject);
}
// add the new children
var offset = Vector2.zero;
value.ForEach(puzzle =>
{
var entry = Instantiate(entryPrefab, plan, false);
entry.Position = offset;
entry.Puzzle = puzzle;
offset += entryOffset;
});
}
}
}
}