fix floater FINALLY
This commit is contained in:
parent
452faae79a
commit
084c5eab2f
2 changed files with 37 additions and 48 deletions
|
|
@ -5,7 +5,8 @@ using gay.lilyy.aacshared.runtimecomponents;
|
|||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace gay.lilyy.aacshared.layers {
|
||||
namespace gay.lilyy.aacshared.layers
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class Floater : LayerGroup
|
||||
{
|
||||
|
|
@ -13,8 +14,8 @@ namespace gay.lilyy.aacshared.layers {
|
|||
public override bool experimental => false;
|
||||
public override bool shouldWarnIfNotApplicable => false;
|
||||
private static readonly Floater _instance = new();
|
||||
|
||||
static Floater() {}
|
||||
|
||||
static Floater() { }
|
||||
|
||||
public override string DisplayName => "Floater";
|
||||
public override string SystemName => "floater";
|
||||
|
|
@ -37,7 +38,7 @@ namespace gay.lilyy.aacshared.layers {
|
|||
Logger.LogWarning($"Floater system: Invalid spin axis '{multiDef.Definition.spinAxis}' in definition '{multiDef.Definition.name}'. Must be one of 'x', 'y', or 'z'. Skipping.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var state = layer.NewState("Floater").WithAnimation(assets.aac.NewClip().Animating(action =>
|
||||
{
|
||||
Logger.LogInfo($"Floater system: Creating animation for definition '{multiDef.Definition.name}' with {multiDef.Transforms.Count} transforms");
|
||||
|
|
@ -54,52 +55,39 @@ namespace gay.lilyy.aacshared.layers {
|
|||
.Easing(multiDef.Definition.loopInSeconds, t.transform.localPosition.y);
|
||||
});
|
||||
}
|
||||
if (multiDef.Definition.spinCycles > 0)
|
||||
{
|
||||
string axis = multiDef.Definition.spinAxis.ToLower();
|
||||
string prop = $"m_LocalEulerAngles.{axis}";
|
||||
float segment = multiDef.Definition.loopInSeconds / multiDef.Definition.spinCycles;
|
||||
if (multiDef.Definition.spinCycles > 0)
|
||||
{
|
||||
string axis = multiDef.Definition.spinAxis.ToLower();
|
||||
string prop = $"m_LocalEulerAnglesRaw.{axis}";
|
||||
float duration = multiDef.Definition.loopInSeconds;
|
||||
float totalRotation = 360f * multiDef.Definition.spinCycles;
|
||||
|
||||
for (int cycle = 0; cycle < multiDef.Definition.spinCycles; cycle++)
|
||||
{
|
||||
action.Animates(t, prop).WithSecondsUnit(unit =>
|
||||
{
|
||||
float baseAngle = 0f; // ignore quaternion components entirely
|
||||
float startTime = cycle * segment;
|
||||
float endTime = (cycle + 1) * segment;
|
||||
action.Animates(t, prop).WithSecondsUnit(unit =>
|
||||
{
|
||||
unit
|
||||
.Linear(0f, 0f)
|
||||
.Linear(duration, totalRotation);
|
||||
});
|
||||
|
||||
float startAngle = baseAngle + 360f * cycle;
|
||||
float endAngle = baseAngle + 360f * (cycle + 1);
|
||||
// Lock the other axes
|
||||
foreach (var other in new[] { "x", "y", "z" })
|
||||
{
|
||||
if (other == axis) continue;
|
||||
|
||||
Logger.LogDebug($"Floater system: Animating {t.name} {prop} on cycle {cycle} from {startAngle} to {endAngle} between {startTime}s and {endTime}s");
|
||||
unit
|
||||
.Linear(startTime, startAngle)
|
||||
.Linear(endTime, endAngle);
|
||||
|
||||
Logger.LogDebug($"unit.Linear({startTime}, {startAngle}).Linear({endTime}, {endAngle})");
|
||||
});
|
||||
}
|
||||
float current =
|
||||
other == "x" ? t.transform.localEulerAngles.x :
|
||||
other == "y" ? t.transform.localEulerAngles.y :
|
||||
t.transform.localEulerAngles.z;
|
||||
|
||||
// Fill OTHER Euler axes with constant values
|
||||
foreach (var other in new[] { "x", "y", "z" })
|
||||
{
|
||||
if (other == axis) continue;
|
||||
float current =
|
||||
other == "x" ? t.transform.localEulerAngles.x :
|
||||
other == "y" ? t.transform.localEulerAngles.y :
|
||||
t.transform.localEulerAngles.z;
|
||||
|
||||
Logger.LogDebug($"Floater system: Setting constant {t.name} {other} to {current}");
|
||||
|
||||
action.Animates(t, $"m_LocalEulerAngles.{other}")
|
||||
.WithSecondsUnit(unit =>
|
||||
{
|
||||
unit
|
||||
.Linear(0f, current)
|
||||
.Linear(multiDef.Definition.loopInSeconds, current);
|
||||
});
|
||||
}
|
||||
}
|
||||
action.Animates(t, $"m_LocalEulerAnglesRaw.{other}")
|
||||
.WithSecondsUnit(unit =>
|
||||
{
|
||||
unit
|
||||
.Linear(0f, current)
|
||||
.Linear(duration, current);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}).Looping());
|
||||
|
|
@ -140,7 +128,8 @@ namespace gay.lilyy.aacshared.layers {
|
|||
Definition = def,
|
||||
Transforms = new List<Transform>()
|
||||
};
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.LogInfo($"Floater system: Adding additional transform to definition '{def.name}'");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue