75 lines
2.7 KiB
C#
75 lines
2.7 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using Ichni.RhythmGame;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.Events;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
|
||
|
|
namespace Ichni.Editor
|
||
|
|
{
|
||
|
|
public partial class CompositeParameterWindow : MovableWindow
|
||
|
|
{
|
||
|
|
public Button addNewUnitButton;
|
||
|
|
public GameObject unitPrefab;
|
||
|
|
public IBaseElement connectedBaseElement;
|
||
|
|
public List<DynamicUICompositeUnit> unitList;
|
||
|
|
public string parameterName;
|
||
|
|
public UnityAction ApplyParameters;
|
||
|
|
|
||
|
|
public void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||
|
|
{
|
||
|
|
this.connectedBaseElement = baseElement;
|
||
|
|
this.parameterName = parameterName;
|
||
|
|
this.title.text = title;
|
||
|
|
unitList = new List<DynamicUICompositeUnit>();
|
||
|
|
closeButton.onClick.AddListener(() =>
|
||
|
|
{
|
||
|
|
ApplyParameters();
|
||
|
|
Destroy(gameObject);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
public void RemoveUnit(DynamicUICompositeUnit unit)
|
||
|
|
{
|
||
|
|
unitList.Remove(unit);
|
||
|
|
Destroy(unit.gameObject);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public partial class CompositeParameterWindow
|
||
|
|
{
|
||
|
|
public void SetAsStringList()
|
||
|
|
{
|
||
|
|
unitPrefab = EditorManager.instance.basePrefabs.stringUnit;
|
||
|
|
addNewUnitButton.onClick.AddListener(() =>
|
||
|
|
{
|
||
|
|
DynamicUIStringUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUIStringUnit>();
|
||
|
|
unitList.Add(unit);
|
||
|
|
unit.SetUnit(this, "");
|
||
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||
|
|
});
|
||
|
|
|
||
|
|
List<string> list = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement) as List<string>;
|
||
|
|
|
||
|
|
foreach (var item in list)
|
||
|
|
{
|
||
|
|
DynamicUIStringUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUIStringUnit>();
|
||
|
|
unitList.Add(unit);
|
||
|
|
unit.SetUnit(this, item);
|
||
|
|
}
|
||
|
|
|
||
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||
|
|
|
||
|
|
ApplyParameters = () =>
|
||
|
|
{
|
||
|
|
List<string> list = new List<string>();
|
||
|
|
foreach (var unit in unitList)
|
||
|
|
{
|
||
|
|
list.Add((unit as DynamicUIStringUnit).GetValue());
|
||
|
|
Debug.Log((unit as DynamicUIStringUnit).GetValue());
|
||
|
|
}
|
||
|
|
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, list);
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|