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 UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace gay.lilyy.aacshared.layers {
|
namespace gay.lilyy.aacshared.layers
|
||||||
|
{
|
||||||
[InitializeOnLoad]
|
[InitializeOnLoad]
|
||||||
public class Floater : LayerGroup
|
public class Floater : LayerGroup
|
||||||
{
|
{
|
||||||
|
|
@ -14,7 +15,7 @@ namespace gay.lilyy.aacshared.layers {
|
||||||
public override bool shouldWarnIfNotApplicable => false;
|
public override bool shouldWarnIfNotApplicable => false;
|
||||||
private static readonly Floater _instance = new();
|
private static readonly Floater _instance = new();
|
||||||
|
|
||||||
static Floater() {}
|
static Floater() { }
|
||||||
|
|
||||||
public override string DisplayName => "Floater";
|
public override string DisplayName => "Floater";
|
||||||
public override string SystemName => "floater";
|
public override string SystemName => "floater";
|
||||||
|
|
@ -54,52 +55,39 @@ namespace gay.lilyy.aacshared.layers {
|
||||||
.Easing(multiDef.Definition.loopInSeconds, t.transform.localPosition.y);
|
.Easing(multiDef.Definition.loopInSeconds, t.transform.localPosition.y);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (multiDef.Definition.spinCycles > 0)
|
if (multiDef.Definition.spinCycles > 0)
|
||||||
{
|
{
|
||||||
string axis = multiDef.Definition.spinAxis.ToLower();
|
string axis = multiDef.Definition.spinAxis.ToLower();
|
||||||
string prop = $"m_LocalEulerAngles.{axis}";
|
string prop = $"m_LocalEulerAnglesRaw.{axis}";
|
||||||
float segment = multiDef.Definition.loopInSeconds / multiDef.Definition.spinCycles;
|
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 =>
|
action.Animates(t, prop).WithSecondsUnit(unit =>
|
||||||
{
|
{
|
||||||
float baseAngle = 0f; // ignore quaternion components entirely
|
|
||||||
float startTime = cycle * segment;
|
|
||||||
float endTime = (cycle + 1) * segment;
|
|
||||||
|
|
||||||
float startAngle = baseAngle + 360f * cycle;
|
|
||||||
float endAngle = baseAngle + 360f * (cycle + 1);
|
|
||||||
|
|
||||||
Logger.LogDebug($"Floater system: Animating {t.name} {prop} on cycle {cycle} from {startAngle} to {endAngle} between {startTime}s and {endTime}s");
|
|
||||||
unit
|
unit
|
||||||
.Linear(startTime, startAngle)
|
.Linear(0f, 0f)
|
||||||
.Linear(endTime, endAngle);
|
.Linear(duration, totalRotation);
|
||||||
|
|
||||||
Logger.LogDebug($"unit.Linear({startTime}, {startAngle}).Linear({endTime}, {endAngle})");
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// Fill OTHER Euler axes with constant values
|
// Lock the other axes
|
||||||
foreach (var other in new[] { "x", "y", "z" })
|
foreach (var other in new[] { "x", "y", "z" })
|
||||||
{
|
{
|
||||||
if (other == axis) continue;
|
if (other == axis) continue;
|
||||||
|
|
||||||
float current =
|
float current =
|
||||||
other == "x" ? t.transform.localEulerAngles.x :
|
other == "x" ? t.transform.localEulerAngles.x :
|
||||||
other == "y" ? t.transform.localEulerAngles.y :
|
other == "y" ? t.transform.localEulerAngles.y :
|
||||||
t.transform.localEulerAngles.z;
|
t.transform.localEulerAngles.z;
|
||||||
|
|
||||||
Logger.LogDebug($"Floater system: Setting constant {t.name} {other} to {current}");
|
action.Animates(t, $"m_LocalEulerAnglesRaw.{other}")
|
||||||
|
|
||||||
action.Animates(t, $"m_LocalEulerAngles.{other}")
|
|
||||||
.WithSecondsUnit(unit =>
|
.WithSecondsUnit(unit =>
|
||||||
{
|
{
|
||||||
unit
|
unit
|
||||||
.Linear(0f, current)
|
.Linear(0f, current)
|
||||||
.Linear(multiDef.Definition.loopInSeconds, current);
|
.Linear(duration, current);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}).Looping());
|
}).Looping());
|
||||||
|
|
@ -140,7 +128,8 @@ namespace gay.lilyy.aacshared.layers {
|
||||||
Definition = def,
|
Definition = def,
|
||||||
Transforms = new List<Transform>()
|
Transforms = new List<Transform>()
|
||||||
};
|
};
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
Logger.LogInfo($"Floater system: Adding additional transform to definition '{def.name}'");
|
Logger.LogInfo($"Floater system: Adding additional transform to definition '{def.name}'");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ namespace gay.lilyy.aacshared.runtimecomponents
|
||||||
void Start(){}
|
void Start(){}
|
||||||
public float floatHeight = 0;
|
public float floatHeight = 0;
|
||||||
[Tooltip("Time in seconds for one full spin cycle")]
|
[Tooltip("Time in seconds for one full spin cycle")]
|
||||||
public float loopInSeconds = 10f;
|
public float loopInSeconds = 60f;
|
||||||
[Tooltip("Number of times object spins in one loop")]
|
[Tooltip("Number of times object spins in one loop")]
|
||||||
public int spinCycles = 2;
|
public int spinCycles = 2;
|
||||||
[Tooltip("Axis to spin around (x, y, or z)")]
|
[Tooltip("Axis to spin around (x, y, or z)")]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue