TimelineImprovements
This commit is contained in:
1 parent
e312131725
commit
f927552adc
2211 files changed
+115416
-540944
No files matched your search
@@ -98,7 +98,8 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
/// <summary>
|
||||
/// Полное детерминированное восстановление для старта/перезапекания физической симуляции.
|
||||
/// </summary>
|
||||
public static void RestoreForSimulation(EntityProperties entity, Transform[] cachedBones, in EntitySnapshot snapshot)
|
||||
public static void RestoreForSimulation(EntityProperties entity, Transform[] cachedBones,
|
||||
in EntitySnapshot snapshot)
|
||||
{
|
||||
var motor = entity.KinematicCharacterMotor;
|
||||
var moveCtrl = entity.MovementController;
|
||||
@@ -220,6 +221,7 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
case AnimatorControllerParameterType.Trigger: pSnap.BoolValue = animator.GetBool(hash); break;
|
||||
}
|
||||
|
||||
_parameters[i] = pSnap;
|
||||
}
|
||||
}
|
||||
@@ -228,7 +230,9 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
{
|
||||
if (targetAnimator == null || _layers == null) return;
|
||||
|
||||
targetAnimator.applyRootMotion = false;
|
||||
// 1. ВАЖНО: включаем исходный режим RootMotion ДО перемотки,
|
||||
// чтобы Mecanim вычислял позу и внутренний курсор корня в правильном режиме!
|
||||
targetAnimator.applyRootMotion = _applyRootMotion;
|
||||
targetAnimator.speed = _speed;
|
||||
|
||||
if (_parameters != null)
|
||||
@@ -240,9 +244,12 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
switch (p.Type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float: targetAnimator.SetFloat(p.NameHash, p.FloatValue); break;
|
||||
case AnimatorControllerParameterType.Int: targetAnimator.SetInteger(p.NameHash, p.IntValue); break;
|
||||
case AnimatorControllerParameterType.Bool: targetAnimator.SetBool(p.NameHash, p.BoolValue); break;
|
||||
case AnimatorControllerParameterType.Float:
|
||||
targetAnimator.SetFloat(p.NameHash, p.FloatValue); break;
|
||||
case AnimatorControllerParameterType.Int:
|
||||
targetAnimator.SetInteger(p.NameHash, p.IntValue); break;
|
||||
case AnimatorControllerParameterType.Bool:
|
||||
targetAnimator.SetBool(p.NameHash, p.BoolValue); break;
|
||||
case AnimatorControllerParameterType.Trigger:
|
||||
if (p.BoolValue) targetAnimator.SetTrigger(p.NameHash);
|
||||
else targetAnimator.ResetTrigger(p.NameHash);
|
||||
@@ -251,7 +258,9 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
}
|
||||
}
|
||||
|
||||
const float warmupEpsilon = 0.0001f;
|
||||
int layerCount = Mathf.Min(_layers.Length, targetAnimator.layerCount);
|
||||
|
||||
for (int i = 0; i < layerCount; i++)
|
||||
{
|
||||
var layer = _layers[i];
|
||||
@@ -259,15 +268,22 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
|
||||
if (!layer.IsInTransition || layer.NextFullPathHash == 0)
|
||||
{
|
||||
float timeInSeconds = Mathf.Max(0f, layer.NormalizedTime * layer.StateLength);
|
||||
targetAnimator.CrossFadeInFixedTime(layer.FullPathHash, 0f, i, timeInSeconds);
|
||||
float targetSeconds = Mathf.Max(0f, layer.NormalizedTime * layer.StateLength);
|
||||
float preSeconds = Mathf.Max(0f, targetSeconds - warmupEpsilon);
|
||||
float dt = targetSeconds - preSeconds;
|
||||
|
||||
targetAnimator.CrossFadeInFixedTime(layer.FullPathHash, 0f, i, preSeconds);
|
||||
targetAnimator.Update(0f);
|
||||
|
||||
// Ненулевой микрошаг прогревает m_PrevRootPosition ровно до targetSeconds!
|
||||
if (dt > 0f)
|
||||
targetAnimator.Update(dt);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Защита от отрицательного времени (фикс бага старого AnimatorSnapshot)
|
||||
float startSecondsA = Mathf.Max(0f, (layer.NormalizedTime * layer.StateLength) - layer.ElapsedTransitionTime);
|
||||
float startSecondsB = Mathf.Max(0f, (layer.NextNormalizedTime * layer.NextStateLength) - layer.ElapsedTransitionTime);
|
||||
float elapsed = Mathf.Max(warmupEpsilon, layer.ElapsedTransitionTime);
|
||||
float startSecondsA = Mathf.Max(0f, (layer.NormalizedTime * layer.StateLength) - elapsed);
|
||||
float startSecondsB = Mathf.Max(0f, (layer.NextNormalizedTime * layer.NextStateLength) - elapsed);
|
||||
|
||||
targetAnimator.CrossFadeInFixedTime(layer.FullPathHash, 0f, i, startSecondsA);
|
||||
targetAnimator.Update(0f);
|
||||
@@ -278,14 +294,15 @@ namespace Code.OfficeGame.BattleMode.Actions
|
||||
i,
|
||||
startSecondsB);
|
||||
|
||||
targetAnimator.Update(layer.ElapsedTransitionTime);
|
||||
targetAnimator.Update(elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Отбрасываем любое смещение, которое произошло во время прогрева,
|
||||
// сохраняя родной локальный оффсет модели
|
||||
Transform targetTransform = targetAnimator.transform;
|
||||
targetTransform.localPosition = _localPosition;
|
||||
targetTransform.localRotation = _localRotation;
|
||||
targetAnimator.applyRootMotion = _applyRootMotion;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user