mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-04 03:39:55 +00:00
parent
0e9bfdd9ae
commit
dcb36a2820
@ -6,14 +6,13 @@ namespace QSB
|
||||
{
|
||||
public class AnimatorMirror : MonoBehaviour
|
||||
{
|
||||
private const float SmoothTime = 0.02f;
|
||||
private const float SmoothTime = 0.05f;
|
||||
|
||||
private Animator _from;
|
||||
private Animator _to;
|
||||
private bool _isRunning;
|
||||
|
||||
private float _smoothVelocity;
|
||||
private readonly Dictionary<string, float> _floatParams = new Dictionary<string, float>();
|
||||
private readonly Dictionary<string, FloatAnimParam> _floatParams = new Dictionary<string, FloatAnimParam>();
|
||||
|
||||
public void Init(Animator from, Animator to)
|
||||
{
|
||||
@ -29,7 +28,7 @@ namespace QSB
|
||||
}
|
||||
foreach (var param in _from.parameters.Where(p => p.type == AnimatorControllerParameterType.Float))
|
||||
{
|
||||
_floatParams.Add(param.name, param.defaultFloat);
|
||||
_floatParams.Add(param.name, new FloatAnimParam());
|
||||
}
|
||||
_isRunning = true;
|
||||
}
|
||||
@ -51,7 +50,7 @@ namespace QSB
|
||||
switch (fromParam.type)
|
||||
{
|
||||
case AnimatorControllerParameterType.Float:
|
||||
_floatParams[fromParam.name] = _from.GetFloat(fromParam.name);
|
||||
_floatParams[fromParam.name].Target = _from.GetFloat(fromParam.name);
|
||||
break;
|
||||
case AnimatorControllerParameterType.Int:
|
||||
_to.SetInteger(fromParam.name, _from.GetInteger(fromParam.name));
|
||||
@ -67,9 +66,8 @@ namespace QSB
|
||||
{
|
||||
foreach (var floatParam in _floatParams)
|
||||
{
|
||||
var current = _to.GetFloat(floatParam.Key);
|
||||
var value = Mathf.SmoothDamp(current, floatParam.Value, ref _smoothVelocity, SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, value);
|
||||
var current = floatParam.Value.Smooth(SmoothTime);
|
||||
_to.SetFloat(floatParam.Key, current);
|
||||
}
|
||||
}
|
||||
|
||||
|
19
QSB/FloatAnimParam.cs
Normal file
19
QSB/FloatAnimParam.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace QSB
|
||||
{
|
||||
public class FloatAnimParam
|
||||
{
|
||||
public float Current { get; private set; }
|
||||
public float Target { get; set; }
|
||||
|
||||
private float _velocity;
|
||||
|
||||
public float Smooth(float smoothTime)
|
||||
{
|
||||
Current = Mathf.SmoothDamp(Current, Target, ref _velocity, smoothTime);
|
||||
return Current;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -92,6 +92,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="AnimationSync.cs" />
|
||||
<Compile Include="AnimatorMirror.cs" />
|
||||
<Compile Include="FloatAnimParam.cs" />
|
||||
<Compile Include="DebugLog.cs" />
|
||||
<Compile Include="QSBBehaviour.cs" />
|
||||
<Compile Include="PreserveTimeScale.cs" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user