2025-02-13 02:04:41 -05:00
|
|
|
|
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()
|
|
|
|
|
|
{
|
2025-02-13 14:26:37 -05:00
|
|
|
|
//生成Unit
|
|
|
|
|
|
void GenerateUnit(string content)
|
2025-02-13 02:04:41 -05:00
|
|
|
|
{
|
|
|
|
|
|
DynamicUIStringUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUIStringUnit>();
|
|
|
|
|
|
unitList.Add(unit);
|
2025-02-13 14:26:37 -05:00
|
|
|
|
unit.SetUnit(this, content);
|
|
|
|
|
|
}
|
2025-02-13 02:04:41 -05:00
|
|
|
|
|
2025-02-13 14:26:37 -05:00
|
|
|
|
unitPrefab = EditorManager.instance.basePrefabs.stringUnit;
|
2025-02-13 02:04:41 -05:00
|
|
|
|
|
2025-02-13 14:26:37 -05:00
|
|
|
|
//初始化:获取当前的List<string>,并生成对应的Unit
|
|
|
|
|
|
List<string> list = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement) as List<string>;
|
|
|
|
|
|
foreach (string item in list)
|
2025-02-13 02:04:41 -05:00
|
|
|
|
{
|
2025-02-13 14:26:37 -05:00
|
|
|
|
GenerateUnit(item);
|
2025-02-13 02:04:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
2025-02-13 14:26:37 -05:00
|
|
|
|
|
|
|
|
|
|
//为添加新的Unit的按钮设置点击事件
|
|
|
|
|
|
addNewUnitButton.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
GenerateUnit("");
|
|
|
|
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
//将当前所有Unit的值应用到对应的变量中
|
2025-02-13 02:04:41 -05:00
|
|
|
|
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);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-02-13 14:26:37 -05:00
|
|
|
|
|
|
|
|
|
|
public void SetAsFlexibleFloat()
|
|
|
|
|
|
{
|
|
|
|
|
|
void GenerateUnit(AnimatedFloat content)
|
|
|
|
|
|
{
|
|
|
|
|
|
DynamicUIAnimatedFloatUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUIAnimatedFloatUnit>();
|
|
|
|
|
|
unitList.Add(unit);
|
|
|
|
|
|
unit.SetUnit(this, content);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
unitPrefab = EditorManager.instance.basePrefabs.animatedFloatUnit;
|
|
|
|
|
|
|
|
|
|
|
|
FlexibleFloat flexibleFloat = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement) as FlexibleFloat;
|
|
|
|
|
|
foreach (AnimatedFloat animatedFloat in flexibleFloat.animations)
|
|
|
|
|
|
{
|
|
|
|
|
|
GenerateUnit(animatedFloat);
|
|
|
|
|
|
}
|
|
|
|
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
|
|
|
|
|
|
|
|
|
|
|
addNewUnitButton.onClick.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
GenerateUnit(new AnimatedFloat(0, 0, 0, 0, AnimationCurveType.Linear));
|
|
|
|
|
|
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
ApplyParameters = () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
FlexibleFloat newFlexibleFloat = new FlexibleFloat();
|
|
|
|
|
|
foreach (var unit in unitList)
|
|
|
|
|
|
{
|
|
|
|
|
|
newFlexibleFloat.animations.Add((unit as DynamicUIAnimatedFloatUnit).GetValue());
|
|
|
|
|
|
}
|
|
|
|
|
|
connectedBaseElement.GetType().GetField(parameterName).SetValue(connectedBaseElement, newFlexibleFloat);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-02-13 02:04:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|