mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-13 00:37:37 +02:00
Persistent Settings (#234)
* modularize tabs-style menus * make remix properties use modular design * add persistent settings
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -10,6 +11,9 @@ namespace HeavenStudio.Editor
|
||||
public class TabsManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] GameObject activeContent;
|
||||
[SerializeField] public Transform contentHolder;
|
||||
[SerializeField] public Transform buttonsHolder;
|
||||
[SerializeField] private GameObject buttonPrefab;
|
||||
|
||||
public void SetActiveContent(GameObject content)
|
||||
{
|
||||
@ -38,5 +42,49 @@ namespace HeavenStudio.Editor
|
||||
activeContent.GetComponent<TabsContent>().OnCloseTab();
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user