@@ -240,63 +240,87 @@ namespace Ichni.Editor
|
||||
public KeyframeVisualizer keyframeVisualizer;
|
||||
public CompositeParameterWindow SetAsCustomCurve()
|
||||
{
|
||||
|
||||
//生成一个预览器先
|
||||
keyframeVisualizer.gameObject.SetActive(true);
|
||||
//
|
||||
|
||||
// 获取字段信息和曲线数据
|
||||
unitPrefab = EditorManager.instance.basePrefabs.customCurveKeyframeUnit;
|
||||
FieldInfo fieldInfo = connectedBaseElement.GetType().GetField(parameterName);
|
||||
AnimationCurve curve = fieldInfo.GetValue(connectedBaseElement) as AnimationCurve;
|
||||
|
||||
if (curve == null) curve = AnimationCurve.Linear(0, 0, 1, 1);
|
||||
|
||||
// 初始化预览器
|
||||
keyframeVisualizer.curve = curve;
|
||||
keyframeVisualizer.DrawCurveToRawImage();
|
||||
keyframeVisualizer.RebuildInteractablePoints();
|
||||
|
||||
// 关键点:松开手柄时的回调
|
||||
keyframeVisualizer.OnEditFinished = () =>
|
||||
{
|
||||
// 同步左侧 Unit 列表的数值显示(假设 unitList[0] 是 WrapMode)
|
||||
for (int i = 0; i < keyframeVisualizer.curve.length; i++)
|
||||
{
|
||||
int unitIdx = i + 1;
|
||||
if (unitIdx < unitList.Count)
|
||||
{
|
||||
var unit = unitList[unitIdx] as DynamicUICustomCurveKeyframeUnit;
|
||||
if (unit != null) unit.SetUnit(this, keyframeVisualizer.curve.keys[i]);
|
||||
}
|
||||
}
|
||||
ApplyParameters?.Invoke();
|
||||
};
|
||||
|
||||
// 生成 WrapMode 单元
|
||||
WarpModes warpModes = new WarpModes(curve.preWrapMode, curve.postWrapMode);
|
||||
var wmUnit = Instantiate(EditorManager.instance.basePrefabs.customCurveWrapModeUnit, windowRect)
|
||||
.GetComponent<DynamicUICustomCurveWrapModeUnit>();
|
||||
unitList.Add(wmUnit);
|
||||
wmUnit.SetUnit(this, warpModes);
|
||||
|
||||
// 生成 Keyframe 单元
|
||||
void GenerateUnit(Keyframe content)
|
||||
{
|
||||
DynamicUICustomCurveKeyframeUnit unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUICustomCurveKeyframeUnit>();
|
||||
var unit = Instantiate(unitPrefab, windowRect).GetComponent<DynamicUICustomCurveKeyframeUnit>();
|
||||
unitList.Add(unit);
|
||||
unit.SetUnit(this, content);
|
||||
}
|
||||
|
||||
unitPrefab = EditorManager.instance.basePrefabs.customCurveKeyframeUnit;
|
||||
AnimationCurve curve = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement) as AnimationCurve;
|
||||
List<Keyframe> keyframes = curve.keys.ToList();
|
||||
WarpModes warpModes = new WarpModes(curve.preWrapMode, curve.postWrapMode);
|
||||
|
||||
//生成warpModes的Unit
|
||||
DynamicUICustomCurveWrapModeUnit warpModesUnit =
|
||||
Instantiate(EditorManager.instance.basePrefabs.customCurveWrapModeUnit, windowRect).GetComponent<DynamicUICustomCurveWrapModeUnit>();
|
||||
unitList.Add(warpModesUnit);
|
||||
warpModesUnit.SetUnit(this, warpModes);
|
||||
//
|
||||
keyframeVisualizer.curve = curve;
|
||||
keyframeVisualizer.DrawCurveToRawImage();
|
||||
keyframeVisualizer.CreateKeyframeImages();
|
||||
//
|
||||
|
||||
foreach (Keyframe keyframe in keyframes)
|
||||
{
|
||||
GenerateUnit(keyframe);
|
||||
}
|
||||
foreach (Keyframe k in curve.keys) GenerateUnit(k);
|
||||
|
||||
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||||
|
||||
addNewUnitButton.onClick.AddListener(() =>
|
||||
{
|
||||
GenerateUnit(new Keyframe(0, 0, 0, 0));
|
||||
Keyframe newKey = new Keyframe(0.5f, 0.5f, 0, 0);
|
||||
keyframeVisualizer.curve.AddKey(newKey);
|
||||
GenerateUnit(newKey);
|
||||
keyframeVisualizer.RebuildInteractablePoints();
|
||||
keyframeVisualizer.DrawCurveToRawImage();
|
||||
addNewUnitButton.GetComponent<RectTransform>().SetAsLastSibling();
|
||||
});
|
||||
|
||||
// 真正的应用/保存逻辑
|
||||
ApplyParameters = () =>
|
||||
{
|
||||
AnimationCurve newCurve = new AnimationCurve();
|
||||
DynamicUICustomCurveWrapModeUnit warpModesUnit = unitList[0] as DynamicUICustomCurveWrapModeUnit;
|
||||
newCurve.preWrapMode = warpModesUnit.GetValue().preWrapMode;
|
||||
newCurve.postWrapMode = warpModesUnit.GetValue().postWrapMode;
|
||||
// 1. 获取 WrapMode
|
||||
var wUnit = unitList[0] as DynamicUICustomCurveWrapModeUnit;
|
||||
newCurve.preWrapMode = wUnit.GetValue().preWrapMode;
|
||||
newCurve.postWrapMode = wUnit.GetValue().postWrapMode;
|
||||
|
||||
// 2. 获取所有 Keyframes
|
||||
for (int i = 1; i < unitList.Count; i++)
|
||||
{
|
||||
DynamicUICustomCurveKeyframeUnit unit = unitList[i] as DynamicUICustomCurveKeyframeUnit;
|
||||
newCurve.AddKey(unit.GetValue());
|
||||
var kUnit = unitList[i] as DynamicUICustomCurveKeyframeUnit;
|
||||
newCurve.AddKey(kUnit.GetValue());
|
||||
}
|
||||
FieldInfo fieldInfo = connectedBaseElement.GetType().GetField(parameterName);
|
||||
|
||||
fieldInfo.SetValue(connectedBaseElement, newCurve);
|
||||
keyframeVisualizer.curve = newCurve;
|
||||
keyframeVisualizer.DrawCurveToRawImage();
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompositeParameterWindow SetAsGradientColorKeys()
|
||||
{
|
||||
void GenerateUnit(GradientColorKey content)
|
||||
|
||||
Reference in New Issue
Block a user