From 3ad68338dff5229d3fd8ec9f3ee994d7e37fb0ed Mon Sep 17 00:00:00 2001 From: chai Date: Thu, 2 Sep 2021 09:59:31 +0800 Subject: *override rootmotion --- Assets/Scripts/Unit/Components/UnitAfterImage.cs | 41 ++++++++++++++++++++++ .../Scripts/Unit/Components/UnitAfterImage.cs.meta | 11 ++++++ .../Unit/Components/UnitAnimation/PCAnimation.cs | 28 +++++++++------ 3 files changed, 70 insertions(+), 10 deletions(-) create mode 100644 Assets/Scripts/Unit/Components/UnitAfterImage.cs create mode 100644 Assets/Scripts/Unit/Components/UnitAfterImage.cs.meta (limited to 'Assets/Scripts/Unit/Components') diff --git a/Assets/Scripts/Unit/Components/UnitAfterImage.cs b/Assets/Scripts/Unit/Components/UnitAfterImage.cs new file mode 100644 index 00000000..369f63c9 --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAfterImage.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class AfterImageSpawner +{ + private float m_CurTime; + + private float m_Duration; + + public void OnUpdate() + { + float dt = Time.deltaTime; + m_CurTime += dt; + + + } + +} + +[DisallowMultipleComponent] +public class UnitAfterImage : UnitComponent +{ + + private List m_Spawners; + + public override void OnUpdate() + { + base.OnUpdate(); + + if(m_Spawners != null) + { + for(int i = 0; i < m_Spawners.Count; ++i) + { + m_Spawners[i].OnUpdate(); + } + } + + } + +} \ No newline at end of file diff --git a/Assets/Scripts/Unit/Components/UnitAfterImage.cs.meta b/Assets/Scripts/Unit/Components/UnitAfterImage.cs.meta new file mode 100644 index 00000000..21cdf37f --- /dev/null +++ b/Assets/Scripts/Unit/Components/UnitAfterImage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 567816c152acc834f9bd41efec9ee51c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs index 33bd4d4e..dbd4dd49 100644 --- a/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs +++ b/Assets/Scripts/Unit/Components/UnitAnimation/PCAnimation.cs @@ -71,6 +71,8 @@ public class PCAnimation : UnitAnimation public bool applyRootMotion { get; set; }// 动态设置root motion public bool applyRootCurve { get; set; } // 程序生成的root motion + public bool updateAnimationAuto { get; private set; } // 自动更新动画 + public override void Initialize() { base.Initialize(); @@ -89,7 +91,9 @@ public class PCAnimation : UnitAnimation } applyRootMotion = true; - } + + updateAnimationAuto = true; + } public override void OnUpdate() { @@ -97,11 +101,8 @@ public class PCAnimation : UnitAnimation UpdateLayer(); UpdateAnimation(); - - if (applyRootMotion) - UpdateRootMotion(); - if (applyRootCurve) - UpdateRootCurve(); + UpdateRootMotion(); + UpdateRootCurve(); } void UpdateLayer() @@ -116,18 +117,25 @@ public class PCAnimation : UnitAnimation void UpdateAnimation() { - m_Animator.speed = 1; - m_Animator.Update(Time.deltaTime); - m_Animator.speed = 0; - } + if(updateAnimationAuto) + { + m_Animator.speed = 1; + m_Animator.Update(Time.deltaTime); + m_Animator.speed = 0; + } + } void UpdateRootMotion() { + if (!applyRootMotion) + return; m_Owner.unitRootMotion.UpdateRootMotion(); } void UpdateRootCurve() { + if (!applyRootCurve) + return; } public void AnimIdle() -- cgit v1.1-26-g67d0