rimworld-animation-studio/Assets/Scripts/Managers/StageCardManager.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2022-09-19 05:35:34 +00:00
using System;
using System.Collections;
2022-09-17 07:17:26 +00:00
using System.Collections.Generic;
2022-10-14 19:00:57 +00:00
using System.Linq;
2022-09-17 07:17:26 +00:00
using UnityEngine;
using UnityEngine.UI;
namespace RimWorldAnimationStudio
{
public class StageCardManager : Singleton<StageCardManager>
{
public StageCard stageCardPrefab;
2022-10-27 05:56:04 +00:00
public void Start()
2022-09-17 07:17:26 +00:00
{
2022-10-28 05:28:51 +00:00
EventsManager.onAnimationChanged.AddListener(delegate { Initialize(); });
EventsManager.onStageIDChanged.AddListener(delegate { Initialize(); });
2022-10-27 05:56:04 +00:00
EventsManager.onStageCountChanged.AddListener(delegate { Initialize(); });
2022-10-28 05:28:51 +00:00
Initialize();
2022-10-27 05:56:04 +00:00
}
2022-10-14 19:00:57 +00:00
2022-10-27 05:56:04 +00:00
public void Initialize()
{
int stageCount = Workspace.animationDef.AnimationStages.Count;
2022-10-14 19:00:57 +00:00
int childCount = GetComponentsInChildren<StageCard>().Count();
for (int i = 0; i < Mathf.Max(stageCount, childCount); i++)
{
// Add new stage cards as required
if (i >= childCount)
{ Instantiate(stageCardPrefab, transform); }
// Get objects to update
StageCard stageCard = GetComponentsInChildren<StageCard>()[i];
// Update values
if (i < stageCount)
2022-10-27 05:56:04 +00:00
{ stageCard.Initialize(Workspace.animationDef.AnimationStages[i].StageName); }
2022-10-14 19:00:57 +00:00
// Remove excess objects as required
else
{ Destroy(stageCard.gameObject); }
}
}
2022-09-17 07:17:26 +00:00
}
}