add : animations omnissiah stele
This commit is contained in:
@@ -62,6 +62,9 @@ namespace OctoCore.Components
|
||||
|
||||
[Tooltip("Scale amount relative to initial scale")]
|
||||
public Vector3 Scale = Vector3.zero;
|
||||
|
||||
[Tooltip("Play on enable")]
|
||||
public bool PlayOnEnable = false;
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
@@ -82,15 +85,26 @@ namespace OctoCore.Components
|
||||
[SerializeField] private State _state;
|
||||
|
||||
private bool _started;
|
||||
private bool _initialized;
|
||||
private float _timeOffset;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
// Capture the reference transform as early as possible, before any other
|
||||
// component's Awake()/Start() can call PlayAnimation() on us.
|
||||
CaptureInitialState();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if(_settings.PlayOnEnable)
|
||||
PlayAnimation();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_state.InitialPosition = transform.localPosition;
|
||||
_state.InitialRotation = transform.localRotation;
|
||||
_state.InitialScale = transform.localScale;
|
||||
_state.CurrentTime = _settings.CycleOffset;
|
||||
_state.IsFinished = false;
|
||||
_state.CurrentTime = _settings.CycleOffset;
|
||||
_state.IsFinished = false;
|
||||
|
||||
_timeOffset = Time.timeSinceLevelLoad;
|
||||
}
|
||||
@@ -118,6 +132,11 @@ namespace OctoCore.Components
|
||||
[ContextMenu("PlayAnimation")]
|
||||
public void PlayAnimation()
|
||||
{
|
||||
// Safety net: guarantees InitialPosition/Rotation/Scale hold the real
|
||||
// transform values even if this is called before Awake() has run
|
||||
// (e.g. from the Editor context menu, or from another script's Awake()).
|
||||
CaptureInitialState();
|
||||
|
||||
ResetAnimation();
|
||||
_timeOffset = Time.timeSinceLevelLoad;
|
||||
_started = true;
|
||||
@@ -143,6 +162,23 @@ namespace OctoCore.Components
|
||||
enabled = !paused;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Captures the transform's current local position/rotation/scale as the
|
||||
/// animation's reference state. Guarded by _initialized so it only runs once:
|
||||
/// InitialPosition/Rotation/Scale must stay frozen at the pre-animation pose,
|
||||
/// not get overwritten mid-animation by a later Awake() or PlayAnimation() call.
|
||||
/// </summary>
|
||||
private void CaptureInitialState()
|
||||
{
|
||||
if (_initialized)
|
||||
return;
|
||||
|
||||
_state.InitialPosition = transform.localPosition;
|
||||
_state.InitialRotation = transform.localRotation;
|
||||
_state.InitialScale = transform.localScale;
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets normalized time [0,1] based on animation type.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user