From 97b64a629a95980d9a2f6c9e37b4cb44acf33a59 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 26 Oct 2020 21:33:09 +0800 Subject: =?UTF-8?q?*=E8=B7=B3=E8=B7=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Test/SaionjiScript.cs | 17 ++++++++--- Assets/Scripts/Test/SaionjiScript_Ability.cs | 42 ++++++++++++++++++++++------ Assets/Scripts/Test/SaionjiScript_Anim.cs | 11 ++++++++ Assets/Scripts/Test/SaionjiScript_Physics.cs | 1 + 4 files changed, 58 insertions(+), 13 deletions(-) (limited to 'Assets/Scripts/Test') diff --git a/Assets/Scripts/Test/SaionjiScript.cs b/Assets/Scripts/Test/SaionjiScript.cs index 7fac11f3..03dfbf8d 100644 --- a/Assets/Scripts/Test/SaionjiScript.cs +++ b/Assets/Scripts/Test/SaionjiScript.cs @@ -49,11 +49,20 @@ public partial class SaionjiScript : MonoBehaviour, IInteractable void OnAnimatorMove() { Animator animator = GetComponent(); - - // animator.deltaPosition和animator.deltaRotation是animator做的root motion后的结果 - // 在后面做一个硬性约束z=0,将角色限制在z=0平面上 - if (animator) + if (animator == null) + return; + + AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0); + + if(stateInfo.IsTag("IgnoreRootMotion")) + { + // ignore root motion + Debug.Log("ignore root motion "); + } + else { + // animator.deltaPosition和animator.deltaRotation是animator做的root motion后的结果 + // 在后面做一个硬性约束z=0,将角色限制在z=0平面上 Vector3 position = transform.position; position.x += animator.deltaPosition.x; position.y += animator.deltaPosition.y; diff --git a/Assets/Scripts/Test/SaionjiScript_Ability.cs b/Assets/Scripts/Test/SaionjiScript_Ability.cs index 21901096..c3fa94ce 100644 --- a/Assets/Scripts/Test/SaionjiScript_Ability.cs +++ b/Assets/Scripts/Test/SaionjiScript_Ability.cs @@ -37,6 +37,19 @@ public partial class SaionjiScript : MonoBehaviour MoveAbility move = new MoveAbility(animator, Anim_Run); MoveAbility dash = new MoveAbility(animator, Anim_DashWithSword); + JumpAbilityConfig jumpConfig = new JumpAbilityConfig(); + jumpConfig.animator = animator; + jumpConfig.collider = m_BodyCollider; + jumpConfig.body = m_Body; + jumpConfig.neutralJumpSpeedY = 10f; + jumpConfig.fowardJumpSpeedX = 1f; + jumpConfig.backwardJumpSpeedX = -1f; + jumpConfig.animJump = Anim_JumpStart; + jumpConfig.animJumpEnd = Anim_JumpEnd; + jumpConfig.animNU = Anim_JumpUp; + jumpConfig.animND = Anim_JumpDown; + JumpAbility jump = new JumpAbility(jumpConfig); + AttackAbilityConfig config; //招式会绑定一个motion @@ -69,6 +82,8 @@ public partial class SaionjiScript : MonoBehaviour ActionTowardLeft towardLeft = new ActionTowardLeft(this.transform); ActionTowardRight towardRight = new ActionTowardRight(this.transform); + ActionJump toJump = new ActionJump(m_AbilitySystem, jump); + ActionSwitchAbility switchToMove = new ActionSwitchAbility(m_AbilitySystem, move); ActionSwitchAbility switchToIdle = new ActionSwitchAbility(m_AbilitySystem, idle); ActionSwitchAbility switchToAttk1 = new ActionSwitchAbility(m_AbilitySystem, attk1); @@ -99,8 +114,9 @@ public partial class SaionjiScript : MonoBehaviour ConditionNoMoveButtonHold condNoMoveButtonHold = new ConditionNoMoveButtonHold(); ConditionButtonHold condRightButtonHold = new ConditionButtonHold(GamepadButton.Right); ConditionButtonHold condLeftButtonHold = new ConditionButtonHold(GamepadButton.Left); + ConditionCommand condTriangleCmd = new ConditionCommand(GamepadButton.Triangle); ConditionCommand condCircleCmd = new ConditionCommand(GamepadButton.Circle); - ConditionCommand condCrossCmd = new ConditionCommand(GamepadButton.Cross); + ConditionCommand condCrossCmd = new ConditionCommand(GamepadButton.Cross); ConditionCommand condSquareCmd = new ConditionCommand(GamepadButton.Square); ConditionTowardLeft condTowardLeft = new ConditionTowardLeft(this.transform); ConditionTowardRight condTowardRight = new ConditionTowardRight(this.transform); @@ -111,19 +127,23 @@ public partial class SaionjiScript : MonoBehaviour ConditionHit condIsHit = new ConditionHit(this); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // common triggers - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - Trigger triggerTurnRight = new Trigger(And(condRightCmd, Not(condTowardRight)), towardRight); + ConditionJumpDone condJumpDone = new ConditionJumpDone(jump); + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // common triggers + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + Trigger triggerTurnRight = new Trigger(And(condRightCmd, Not(condTowardRight)), towardRight); Trigger triggerTurnLeft = new Trigger(And(condLeftCmd, Not(condTowardLeft)), towardLeft); Trigger trigger = null; - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // ability setup - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // ability setup + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - // idle ability + // idle ability + trigger = new Trigger(condTriangleCmd, toJump) ; + idle.AddTrigger(trigger); trigger = new Trigger(And(condTowardRight, condDRC), new List { wipeCmdRecord, switchToSuperKick }); idle.AddTrigger(trigger); trigger = new Trigger(And(condTowardLeft, condDLC), new List { wipeCmdRecord, switchToSuperKick }); @@ -167,6 +187,10 @@ public partial class SaionjiScript : MonoBehaviour trigger = new Trigger(condCrossCmd, switchToSideKick); move.AddTrigger(trigger); + // jump ability + trigger = new Trigger(condJumpDone, switchToIdle); + jump.AddTrigger(trigger); + // dash ability trigger = new Trigger(And(new ConditionMotionRange(animator, 0.5f, 1.0f), condCircleCmd), switchToAttk1); dash.AddTrigger(trigger); diff --git a/Assets/Scripts/Test/SaionjiScript_Anim.cs b/Assets/Scripts/Test/SaionjiScript_Anim.cs index 082729f7..5dec9db6 100644 --- a/Assets/Scripts/Test/SaionjiScript_Anim.cs +++ b/Assets/Scripts/Test/SaionjiScript_Anim.cs @@ -22,6 +22,11 @@ public partial class SaionjiScript : MonoBehaviour int Anim_Gun3; int Anim_Gun4; + int Anim_JumpStart; + int Anim_JumpUp; + int Anim_JumpDown; + int Anim_JumpEnd; + void GetAnimHash() { //Anim_Idle = Animator.StringToHash("Idle_Gun"); @@ -46,6 +51,12 @@ public partial class SaionjiScript : MonoBehaviour Anim_Gun2 = Animator.StringToHash("Gun02"); Anim_Gun3 = Animator.StringToHash("Gun03"); Anim_Gun4 = Animator.StringToHash("Gun04"); + + + Anim_JumpStart = Animator.StringToHash("Jump_Start"); + Anim_JumpUp = Animator.StringToHash("Jump_Up"); + Anim_JumpDown = Animator.StringToHash("Jump_Down"); + Anim_JumpEnd = Animator.StringToHash("Jump_End"); } } diff --git a/Assets/Scripts/Test/SaionjiScript_Physics.cs b/Assets/Scripts/Test/SaionjiScript_Physics.cs index 99926afe..1b296f43 100644 --- a/Assets/Scripts/Test/SaionjiScript_Physics.cs +++ b/Assets/Scripts/Test/SaionjiScript_Physics.cs @@ -7,6 +7,7 @@ public partial class SaionjiScript : MonoBehaviour, IInteractable public PhysicsBox[] m_Hitbox; public PhysicsBox[] m_Hurtbox; public PhysicsBody m_Body; + public PhysicsBox m_BodyCollider; public PhysicsPrimitive[] GetAllPrimitive() { -- cgit v1.1-26-g67d0