2023-01-24 19:31:49 +00:00
|
|
|
using System;
|
2022-07-10 03:22:59 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using HeavenStudio.Editor.Track;
|
|
|
|
|
|
|
|
using TMPro;
|
|
|
|
|
|
|
|
namespace HeavenStudio.Editor
|
|
|
|
{
|
|
|
|
public class TabsManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField] GameObject activeContent;
|
2023-01-24 19:31:49 +00:00
|
|
|
[SerializeField] public Transform contentHolder;
|
|
|
|
[SerializeField] public Transform buttonsHolder;
|
|
|
|
[SerializeField] private GameObject buttonPrefab;
|
2022-07-10 03:22:59 +00:00
|
|
|
|
|
|
|
public void SetActiveContent(GameObject content)
|
|
|
|
{
|
|
|
|
if (activeContent != null)
|
|
|
|
{
|
2022-09-03 23:10:27 +00:00
|
|
|
activeContent.GetComponent<TabsContent>().OnCloseTab();
|
2022-07-10 03:22:59 +00:00
|
|
|
activeContent.SetActive(false);
|
|
|
|
}
|
|
|
|
activeContent = content;
|
|
|
|
activeContent.SetActive(true);
|
2022-09-03 23:10:27 +00:00
|
|
|
activeContent.GetComponent<TabsContent>().OnOpenTab();
|
|
|
|
}
|
|
|
|
|
2022-09-03 23:46:54 +00:00
|
|
|
public void OpenContent()
|
|
|
|
{
|
|
|
|
if (activeContent != null)
|
|
|
|
{
|
|
|
|
activeContent.GetComponent<TabsContent>().OnOpenTab();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-03 23:10:27 +00:00
|
|
|
public void CloseContent()
|
|
|
|
{
|
|
|
|
if (activeContent != null)
|
|
|
|
{
|
|
|
|
activeContent.GetComponent<TabsContent>().OnCloseTab();
|
|
|
|
}
|
2022-07-10 03:22:59 +00:00
|
|
|
}
|
2023-01-24 19:31:49 +00:00
|
|
|
|
|
|
|
public List<GameObject> GenerateTabs(TabsEntry[] tabs)
|
|
|
|
{
|
|
|
|
List<GameObject> tabContents = new List<GameObject>();
|
|
|
|
bool madeFirst = false;
|
|
|
|
foreach(var tab in tabs)
|
|
|
|
{
|
|
|
|
var button = Instantiate(buttonPrefab, buttonsHolder);
|
|
|
|
button.GetComponentInChildren<TMP_Text>().text = tab.name;
|
|
|
|
var tabContent = Instantiate(tab.tabPrefab, contentHolder);
|
|
|
|
if(!madeFirst)
|
|
|
|
{
|
|
|
|
madeFirst = true;
|
|
|
|
SetActiveContent(tabContent);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tabContent.SetActive(false);
|
|
|
|
}
|
|
|
|
button.GetComponent<TabButton>().Content = tabContent;
|
|
|
|
tabContents.Add(tabContent);
|
|
|
|
}
|
|
|
|
return tabContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void CleanTabs()
|
|
|
|
{
|
|
|
|
foreach(Transform child in buttonsHolder)
|
|
|
|
{
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
}
|
|
|
|
foreach(Transform child in contentHolder)
|
|
|
|
{
|
|
|
|
child.GetComponent<TabsContent>()?.OnCloseTab();
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
public struct TabsEntry
|
|
|
|
{
|
|
|
|
public string name;
|
|
|
|
public GameObject tabPrefab;
|
|
|
|
}
|
2022-07-10 03:22:59 +00:00
|
|
|
}
|
|
|
|
}
|