summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2020-10-18 08:22:25 +0800
committerchai <chaifix@163.com>2020-10-18 08:22:25 +0800
commit3e8ab8f4b98086e9a1a4b2fd1221e86e9abceea4 (patch)
tree2adcf957bfb97362c144de5a44bc7be5dbd09356 /Assets/Scripts
parentc83b9abffe8988f9322a027b7fefd68e7f3fa6ba (diff)
+gamepad
+superkick combo
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs3
-rw-r--r--Assets/Scripts/Input/InputManager.cs65
-rw-r--r--Assets/Scripts/Test/SaionjiScript_Ability.cs22
-rw-r--r--Assets/Scripts/Test/SaionjiScript_Anim.cs5
4 files changed, 80 insertions, 15 deletions
diff --git a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs
index 85a5a0a6..5dbe6d6c 100644
--- a/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs
+++ b/Assets/Scripts/AbilitySystem/Abilities/AttackAbility.cs
@@ -44,7 +44,8 @@ public class AttackAbility : AbilityBase
public override void OnEnter()
{
m_TimeCount = 0;
- m_Animator.CrossFadeInFixedTime(m_AnimHash, 0.25f);
+ // 招式不要有过渡时间
+ m_Animator.CrossFade(m_AnimHash, 0);
}
public override void OnExit()
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs
index f24a3efa..6bce55c6 100644
--- a/Assets/Scripts/Input/InputManager.cs
+++ b/Assets/Scripts/Input/InputManager.cs
@@ -24,32 +24,63 @@ public class InputManager : Singleton<InputManager>
}
}
+ private enum Axis { Up, Down, Left, Right};
+
+ private bool[] m_Axis = new bool[4] { false, false, false, false};
+
public void Init()
{
m_CommandRecord = new List<Command>();
m_CurrentCommand = new Command(GamepadButton.Blank, 0);
}
+ private bool GetAxis(Axis axis)
+ {
+ return false;
+ bool axisRaw = false;
+ switch (axis)
+ {
+ case Axis.Left: axisRaw = Input.GetAxisRaw("Horizontal") == -1; break;
+ case Axis.Right: axisRaw = Input.GetAxisRaw("Horizontal") == 1; break;
+ case Axis.Down: axisRaw = Input.GetAxisRaw("Vertical") == -1; break;
+ case Axis.Up: axisRaw = Input.GetAxisRaw("Vertical") == 1; break;
+ }
+ if (axisRaw)
+ {
+ if(!m_Axis[(int)axis])
+ {
+ m_Axis[(int)axis] = true;
+ return true;
+ }
+ return false;
+ }
+ else
+ {
+ m_Axis[(int)axis] = false;
+ return false;
+ }
+ }
+
public void Update()
{
GamepadButton cmd = GamepadButton.Blank;
// 移动
- if (Input.GetKeyDown("w"))
+ if (Input.GetKeyDown("w") || GetAxis(Axis.Up))
cmd = GamepadButton.Up;
- if (Input.GetKeyDown("s"))
+ if (Input.GetKeyDown("s") || GetAxis(Axis.Down))
cmd = GamepadButton.Down;
- if (Input.GetKeyDown("a"))
+ if (Input.GetKeyDown("a") || GetAxis(Axis.Left))
cmd = GamepadButton.Left;
- if (Input.GetKeyDown("d"))
+ if (Input.GetKeyDown("d") || GetAxis(Axis.Right))
cmd = GamepadButton.Right;
// 动作
- if (Input.GetKeyDown("j"))
+ if (Input.GetKeyDown("j") || Input.GetKeyDown(KeyCode.Joystick1Button2))
cmd = GamepadButton.Circle;
- if (Input.GetKeyDown("k"))
+ if (Input.GetKeyDown("k") || Input.GetKeyDown(KeyCode.Joystick1Button0))
cmd = GamepadButton.Triangle;
- if (Input.GetKeyDown("l"))
+ if (Input.GetKeyDown("l") || Input.GetKeyDown(KeyCode.Joystick1Button1))
cmd = GamepadButton.Square;
- if(Input.GetKeyDown("u"))
+ if (Input.GetKeyDown("u") || Input.GetKeyDown(KeyCode.Joystick1Button3))
cmd = GamepadButton.Cross;
if(cmd != GamepadButton.Blank)
@@ -109,9 +140,25 @@ public class InputManager : Singleton<InputManager>
return "";
}
+ bool GetGamepadButtonState(GamepadButton button)
+ {
+ switch (button)
+ {
+ case GamepadButton.Up: return m_Axis[(int)Axis.Up];
+ case GamepadButton.Down: return m_Axis[(int)Axis.Down];
+ case GamepadButton.Left: return m_Axis[(int)Axis.Left];
+ case GamepadButton.Right: return m_Axis[(int)Axis.Right];
+ case GamepadButton.Circle: return Input.GetKey(KeyCode.Joystick1Button2);
+ case GamepadButton.Triangle: return Input.GetKey(KeyCode.Joystick1Button0);
+ case GamepadButton.Square: return Input.GetKey(KeyCode.Joystick1Button1);
+ case GamepadButton.Cross: return Input.GetKey(KeyCode.Joystick1Button3);
+ }
+ return false;
+ }
+
public bool IsButtonHold(GamepadButton button)
{
- return Input.GetKey(GetGamepadButtonKey(button));
+ return Input.GetKey(GetGamepadButtonKey(button)) || GetGamepadButtonState(button);
}
}
diff --git a/Assets/Scripts/Test/SaionjiScript_Ability.cs b/Assets/Scripts/Test/SaionjiScript_Ability.cs
index bd62c138..49c0b5e9 100644
--- a/Assets/Scripts/Test/SaionjiScript_Ability.cs
+++ b/Assets/Scripts/Test/SaionjiScript_Ability.cs
@@ -41,6 +41,7 @@ public partial class SaionjiScript : MonoBehaviour
AttackAbility attk4 = new AttackAbility(animator, Anim_LightAttack4);
AttackAbility attk5 = new AttackAbility(animator, Anim_LightAttack5);
AttackAbility sideKick = new AttackAbility(animator, Anim_SideKick);
+ AttackAbility superKick = new AttackAbility(animator, Anim_SuperKick);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// actions
@@ -58,6 +59,7 @@ public partial class SaionjiScript : MonoBehaviour
ActionSwitchAbility switchToAttk5 = new ActionSwitchAbility(m_AbilitySystem, attk5);
ActionSwitchAbility switchToSideKick = new ActionSwitchAbility(m_AbilitySystem, sideKick);
ActionSwitchAbility switchToDash = new ActionSwitchAbility(m_AbilitySystem, dash);
+ ActionSwitchAbility switchToSuperKick = new ActionSwitchAbility(m_AbilitySystem, superKick);
ActionWipeCmdRecord wipeCmdRecord = new ActionWipeCmdRecord();
@@ -74,13 +76,15 @@ public partial class SaionjiScript : MonoBehaviour
ConditionTowardLeft condTowardLeft = new ConditionTowardLeft(this.transform);
ConditionTowardRight condTowardRight = new ConditionTowardRight(this.transform);
ConditionCommandSeq condRight2Cmd = new ConditionCommandSeq(new List<GamepadButton>{GamepadButton.Right, GamepadButton.Right }, 1f);
- ConditionCommandSeq condLeft2Cmd = new ConditionCommandSeq(new List<GamepadButton>{GamepadButton.Left, GamepadButton.Left }, 1f);
+ ConditionCommandSeq condLeft2Cmd = new ConditionCommandSeq(new List<GamepadButton> { GamepadButton.Left, GamepadButton.Left }, 1f);
+ ConditionCommandSeq condDRC = new ConditionCommandSeq(new List<GamepadButton> { GamepadButton.Down, GamepadButton.Right, GamepadButton.Circle}, 1f);
+ ConditionCommandSeq condDLC = new ConditionCommandSeq(new List<GamepadButton> { GamepadButton.Down, GamepadButton.Left, GamepadButton.Circle}, 1f);
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// common triggers
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- Trigger triggerTurnRight = new Trigger(And(condRightButtonHold, Not(condTowardRight)), towardRight);
- Trigger triggerTurnLeft = new Trigger(And(condLeftButtonHold, Not(condTowardLeft)), towardLeft);
+ Trigger triggerTurnRight = new Trigger(And(condRightCmd, Not(condTowardRight)), towardRight);
+ Trigger triggerTurnLeft = new Trigger(And(condLeftCmd, Not(condTowardLeft)), towardLeft);
Trigger trigger = null;
@@ -89,6 +93,10 @@ public partial class SaionjiScript : MonoBehaviour
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// idle ability
+ trigger = new Trigger(And(condTowardRight, condDRC), new List<ActionBase> { wipeCmdRecord, switchToSuperKick });
+ idle.AddTrigger(trigger);
+ trigger = new Trigger(And(condTowardLeft, condDLC), new List<ActionBase> { wipeCmdRecord, switchToSuperKick });
+ idle.AddTrigger(trigger);
trigger = new Trigger(And(condTowardRight, And(condRightCmd, condRight2Cmd)), new List<ActionBase> { wipeCmdRecord , switchToDash });
idle.AddTrigger(trigger);
trigger = new Trigger(And(condTowardLeft, And(condLeftCmd, condLeft2Cmd)), new List<ActionBase> { wipeCmdRecord , switchToDash });
@@ -101,8 +109,8 @@ public partial class SaionjiScript : MonoBehaviour
idle.AddTrigger(trigger);
trigger = new Trigger(condCrossCmd, switchToSideKick);
idle.AddTrigger(trigger);
- trigger = new Trigger(condLeftCmd, turn180);
- idle.AddTrigger(trigger);
+ idle.AddTrigger(triggerTurnRight);
+ idle.AddTrigger(triggerTurnLeft);
// move ability
trigger = new Trigger(And(condTowardRight, And(condRightCmd, condRight2Cmd)), new List<ActionBase> { wipeCmdRecord, switchToDash, });
@@ -174,6 +182,10 @@ public partial class SaionjiScript : MonoBehaviour
trigger = new Trigger(condSideKickExpireTime, switchToIdle);
sideKick.AddTrigger(trigger);
+ ConditionAttkExpireTime condSuperKickExpireTime = new ConditionAttkExpireTime(superKick, expireTime);
+ trigger = new Trigger(condSuperKickExpireTime, switchToIdle);
+ superKick.AddTrigger(trigger);
+
m_AbilitySystem.ForceStart(idle);
}
diff --git a/Assets/Scripts/Test/SaionjiScript_Anim.cs b/Assets/Scripts/Test/SaionjiScript_Anim.cs
index 03d1671a..f7c29d3b 100644
--- a/Assets/Scripts/Test/SaionjiScript_Anim.cs
+++ b/Assets/Scripts/Test/SaionjiScript_Anim.cs
@@ -14,6 +14,7 @@ public partial class SaionjiScript : MonoBehaviour
int Anim_LightAttack5;
int Anim_SideKick;
int Anim_DashWithSword;
+ int Anim_SuperKick;
void GetAnimHash()
{
@@ -25,7 +26,11 @@ public partial class SaionjiScript : MonoBehaviour
Anim_LightAttack3 = Animator.StringToHash("Light_Attk_3");
Anim_LightAttack4 = Animator.StringToHash("Light_Attk_4");
Anim_LightAttack5 = Animator.StringToHash("Light_Attk_5");
+
Anim_SideKick = Animator.StringToHash("SideKick");
+
+ Anim_SuperKick = Animator.StringToHash("SuperKickCombo");
+
Anim_DashWithSword = Animator.StringToHash("Dash_With_Sword");
}