HeavenStudioPlus/Assets/Scripts/LevelEditor/RemixPropertiesDialog/Tabs/ChartInfoProperties.cs

132 lines
4.6 KiB
C#
Raw Normal View History

using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace HeavenStudio.Editor
{
2022-09-02 00:57:47 +00:00
public class ChartInfoProperties : TabsContent
{
[Header("General References")]
[SerializeField] private GameObject propertyHolder;
2022-09-03 23:46:54 +00:00
RemixPropertiesDialog dialog;
[Header("Property Prefabs")]
[SerializeField] private GameObject IntegerP;
[SerializeField] private GameObject FloatP;
[SerializeField] private GameObject BooleanP;
[SerializeField] private GameObject DropdownP;
[SerializeField] private GameObject ColorP;
[SerializeField] private GameObject StringP;
2022-09-03 23:46:54 +00:00
[Header("Layout Prefabs")]
[SerializeField] private GameObject DividerP;
2022-09-04 02:29:50 +00:00
[SerializeField] private GameObject HeaderP;
[SerializeField] private GameObject SubHeaderP;
2022-09-03 23:46:54 +00:00
[Header("Editable Properties")]
[SerializeField] RemixPropertiesDialog.PropertyTag[] tags;
2022-09-03 23:46:54 +00:00
public void Init(RemixPropertiesDialog diag)
{
dialog = diag;
}
2022-09-03 23:10:27 +00:00
public void AddParam(RemixPropertiesDialog diag, string propertyName, object type, string caption, bool isReadOnly = false, string tooltip = "")
{
GameObject prefab = IntegerP;
GameObject input;
var objType = type.GetType();
if (objType == typeof(EntityTypes.Integer))
{
prefab = IntegerP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(EntityTypes.Float))
{
prefab = FloatP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<NumberChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (type is bool)
{
prefab = BooleanP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<BoolChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType.IsEnum)
{
prefab = DropdownP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<EnumChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(Color))
{
prefab = ColorP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<ColorChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else if (objType == typeof(string))
{
prefab = StringP;
input = InitPrefab(prefab, tooltip);
2022-09-02 00:57:47 +00:00
var property = input.GetComponent<StringChartPropertyPrefab>();
property.SetProperties(diag, propertyName, type, caption);
}
else
{
Debug.LogError("Can't make property interface of type: " + type.GetType());
return;
}
}
2022-09-03 23:46:54 +00:00
public void AddDivider(RemixPropertiesDialog diag)
{
2022-09-04 02:29:50 +00:00
InitPrefab(DividerP);
2022-09-03 23:46:54 +00:00
}
2022-09-04 02:29:50 +00:00
public void AddHeader(RemixPropertiesDialog diag, string text)
{
var input = InitPrefab(HeaderP);
input.GetComponent<RemixPropertyPrefab>().InitProperties(diag, "", text);
}
public void AddSubHeader(RemixPropertiesDialog diag, string text)
{
var input = InitPrefab(SubHeaderP);
input.GetComponent<RemixPropertyPrefab>().InitProperties(diag, "", text);
}
private GameObject InitPrefab(GameObject prefab, string tooltip = "")
{
GameObject input = Instantiate(prefab);
input.transform.SetParent(propertyHolder.transform);
input.SetActive(true);
input.transform.localScale = Vector2.one;
if(tooltip != string.Empty)
Tooltip.AddTooltip(input, "", tooltip);
return input;
}
2022-09-02 00:57:47 +00:00
public override void OnOpenTab()
{
dialog.SetupDialog(tags, this);
2022-09-02 00:57:47 +00:00
}
public override void OnCloseTab()
{
2022-09-03 23:10:27 +00:00
foreach (Transform child in propertyHolder.transform) {
Destroy(child.gameObject);
}
2022-09-02 00:57:47 +00:00
}
}
}