summaryrefslogtreecommitdiff
path: root/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts')
-rw-r--r--Assets/Scripts/Input/InputManager.cs63
-rw-r--r--Assets/Scripts/Props.meta8
-rw-r--r--Assets/Scripts/Scene.meta8
-rw-r--r--Assets/Scripts/Test 1/TestErika.cs2
-rw-r--r--Assets/Scripts/Test 1/TestInput.cs2
-rw-r--r--Assets/Scripts/Unit/AnimationData.cs1
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs5
-rw-r--r--Assets/Scripts/Unit/Collider/ColliderData.cs2
-rw-r--r--Assets/Scripts/Unit/Component/UnitAnimation.cs35
-rw-r--r--Assets/Scripts/Unit/Component/UnitState.cs135
-rw-r--r--Assets/Scripts/Unit/RootMotion/RootMotionData.cs12
-rw-r--r--Assets/Scripts/Unit/UnitRootMotion.cs6
12 files changed, 237 insertions, 42 deletions
diff --git a/Assets/Scripts/Input/InputManager.cs b/Assets/Scripts/Input/InputManager.cs
index b5e3d8a1..62fd5f91 100644
--- a/Assets/Scripts/Input/InputManager.cs
+++ b/Assets/Scripts/Input/InputManager.cs
@@ -2,12 +2,22 @@
using System.Collections.Generic;
using UnityEngine;
+public struct InputCommand
+{
+ public KeyCode key;
+ public float time;
+}
+
// 处理输入逻辑,不涉及读取输入,只处理逻辑
public class InputManager : SingletonMB<InputManager>
{
PCController _pc;
+ List<InputCommand> m_CommandQueue = new List<InputCommand>();
+
+ const float threshold = 3;
+
PCController pc
{
get
@@ -49,4 +59,57 @@ public class InputManager : SingletonMB<InputManager>
pc.unitState.ChangeState(UnitState.EUnitState.Attack, new UnitState.SkillParam());
}
+ public void OnUpdate()
+ {
+ foreach (KeyCode vKey in System.Enum.GetValues(typeof(KeyCode)))
+ {
+ if (Input.GetKeyDown(vKey))
+ {
+ InputCommand cmd = new InputCommand();
+ cmd.key = vKey;
+ cmd.time = Time.time;
+ m_CommandQueue.Add(cmd);
+ Debug.Log(cmd.time);
+ string cmdStr = "";
+ m_CommandQueue.ForEach(s => cmdStr += s.key.ToString() + ",");
+ Debug.Log(cmdStr);
+ }
+ }
+ float curTime = Time.time;
+ int removeCount = 0;
+ for(int i = 0; i < m_CommandQueue.Count; ++i)
+ {
+ if(curTime - m_CommandQueue[i].time > threshold)
+ {
+ removeCount++;
+ }
+ }
+ m_CommandQueue.RemoveRange(0, removeCount);
+ }
+
+ public bool TryCommand(float interval = 0.5f, params KeyCode[] keys)
+ {
+ if (keys.Length > m_CommandQueue.Count)
+ return false;
+ int count = m_CommandQueue.Count;
+ float preTime = m_CommandQueue[count - keys.Length].time;
+ for (int i = 0; i < keys.Length; ++i)
+ {
+ if(keys[i] == m_CommandQueue[i + count - keys.Length].key)
+ {
+ if(m_CommandQueue[i + count - keys.Length].time - preTime > interval)
+ {
+ return false;
+ }
+ preTime = m_CommandQueue[i + count - keys.Length].time;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ m_CommandQueue.RemoveRange(count - keys.Length, keys.Length);
+ return true;
+ }
+
}
diff --git a/Assets/Scripts/Props.meta b/Assets/Scripts/Props.meta
deleted file mode 100644
index bb96602e..00000000
--- a/Assets/Scripts/Props.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: f299520ed9fcf4a45858ad4ef5a8d5d1
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Scene.meta b/Assets/Scripts/Scene.meta
deleted file mode 100644
index eb7a8716..00000000
--- a/Assets/Scripts/Scene.meta
+++ /dev/null
@@ -1,8 +0,0 @@
-fileFormatVersion: 2
-guid: eaee2d0f48cff9b40baf0686a8105600
-folderAsset: yes
-DefaultImporter:
- externalObjects: {}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/Scripts/Test 1/TestErika.cs b/Assets/Scripts/Test 1/TestErika.cs
index deafc7c3..f6f9ba0e 100644
--- a/Assets/Scripts/Test 1/TestErika.cs
+++ b/Assets/Scripts/Test 1/TestErika.cs
@@ -25,7 +25,9 @@ public class TestErika : MonoBehaviour
unitController = GameObject.Instantiate(unitControllerPrefab);
unitController.transform.position = Vector3.zero;
unitController.transform.rotation = Quaternion.identity;
+
unit = GameObject.Instantiate(unitPrefab);
+ unit.transform.rotation = Quaternion.Euler(0, 90, 0);
unit.transform.SetParent(unitController.transform);
Init();
diff --git a/Assets/Scripts/Test 1/TestInput.cs b/Assets/Scripts/Test 1/TestInput.cs
index f7178549..72e0351b 100644
--- a/Assets/Scripts/Test 1/TestInput.cs
+++ b/Assets/Scripts/Test 1/TestInput.cs
@@ -7,6 +7,8 @@ public class TestInput : MonoBehaviour
private void Update()
{
+ InputManager.Instance.OnUpdate();
+
//if(Input.GetKeyDown("j"))
//{
// InputManager.Instance.OnAttack();
diff --git a/Assets/Scripts/Unit/AnimationData.cs b/Assets/Scripts/Unit/AnimationData.cs
index 32845da1..4d229346 100644
--- a/Assets/Scripts/Unit/AnimationData.cs
+++ b/Assets/Scripts/Unit/AnimationData.cs
@@ -12,6 +12,7 @@ public enum EAnimationToogle
{
Combo = 0, // 连击
SuperArmor = 1, //霸体
+ Break = 2, // 打断
}
[Serializable]
diff --git a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs
index 62c61006..788b457a 100644
--- a/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs
+++ b/Assets/Scripts/Unit/Collider/ColliderBox_Hurtbox.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
+using UnityEngine;
public partial class ColliderBox
{
diff --git a/Assets/Scripts/Unit/Collider/ColliderData.cs b/Assets/Scripts/Unit/Collider/ColliderData.cs
index 4c8e5bed..58743aff 100644
--- a/Assets/Scripts/Unit/Collider/ColliderData.cs
+++ b/Assets/Scripts/Unit/Collider/ColliderData.cs
@@ -101,7 +101,7 @@ public class ColliderData
frame.frame = frameIndex;
frame.active = true;
frame.position = Vector3.zero;
- frame.size = new Vector3(1,1,0.5f);
+ frame.size = new Vector3(0.5f,1,1);
frames.Add(frame);
frames.Sort((a, b) => {
if (a == null)
diff --git a/Assets/Scripts/Unit/Component/UnitAnimation.cs b/Assets/Scripts/Unit/Component/UnitAnimation.cs
index a6a7f3eb..4532023d 100644
--- a/Assets/Scripts/Unit/Component/UnitAnimation.cs
+++ b/Assets/Scripts/Unit/Component/UnitAnimation.cs
@@ -286,6 +286,9 @@ public class UnitAnimation : UnitComponent
public AnimatorLayerInfo[] layers { get { return m_LayerInfo; } }
private readonly AnimatorLayerInfo[] m_LayerInfo = new AnimatorLayerInfo[(int)ELayer.Count];
+ public bool applyRootMotion { get; set; }// 动态设置root motion
+ public bool applyRootCurve { get; set; } // 程序生成的root motion
+
public bool isInTransition
{
get
@@ -309,6 +312,8 @@ public class UnitAnimation : UnitComponent
{
LogHelper.LogError("没有挂Animator组件");
}
+
+ applyRootMotion = true;
}
public override void OnUpdate()
@@ -317,8 +322,12 @@ public class UnitAnimation : UnitComponent
UpdateLayer();
UpdateAnimation();
- UpdateRootMotion();
- }
+
+ if(applyRootMotion)
+ UpdateRootMotion();
+ if(applyRootCurve)
+ UpdateRootCurve();
+ }
void UpdateLayer()
{
@@ -342,7 +351,13 @@ public class UnitAnimation : UnitComponent
m_Owner.unitRootMotion.UpdateRootMotion();
}
- public void AnimIdle()
+ void UpdateRootCurve()
+ {
+
+ }
+
+
+ public void AnimIdle()
{
#if ANIM_CROSS_FADE
m_Animator.CrossFade("Idle", 0.2f, 0);
@@ -394,7 +409,19 @@ public class UnitAnimation : UnitComponent
#endif
}
- public void AnimLanding()
+ public void AnimAirDash()
+ {
+ if (layers[0].stateInfo.IsName("AirDash"))
+ {
+ m_Animator.Play("AirDash", 0, 0);
+ }
+ else
+ {
+ m_Animator.CrossFade("AirDash", 0.05f);
+ }
+ }
+
+ public void AnimLanding()
{
#if ANIM_CROSS_FADE
m_Animator.CrossFade("Landing", 0.05f);
diff --git a/Assets/Scripts/Unit/Component/UnitState.cs b/Assets/Scripts/Unit/Component/UnitState.cs
index 7a731b02..bc934f43 100644
--- a/Assets/Scripts/Unit/Component/UnitState.cs
+++ b/Assets/Scripts/Unit/Component/UnitState.cs
@@ -20,6 +20,7 @@ public class UnitState : UnitComponent
//
Attack ,
AirAttack ,
+ AirDash ,
//
HitAir ,
HitAirHit ,
@@ -63,6 +64,11 @@ public class UnitState : UnitComponent
}
+ public struct AirDashParam
+ {
+
+ }
+
public struct JumpParam
{ }
@@ -114,6 +120,21 @@ public class UnitState : UnitComponent
IEnumerator Nein() { yield break; }
void OnNienExit(EUnitState nextState) { }
+ public void TurnAround(bool bRight)
+ {
+ m_Owner.transform.rotation = Quaternion.Euler(0, bRight ? 0 : 180, 0);
+ }
+
+ public void TurnLeft()
+ {
+ TurnAround(false);
+ }
+
+ public void TurnRight()
+ {
+ TurnAround(true);
+ }
+
#region Idle
IEnumerator Idle(IdleParam param)
@@ -212,14 +233,36 @@ public class UnitState : UnitComponent
yield return null; // 等待animator更新
while (true)
{
- bool canAttack = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
- if(canAttack && Input.GetKeyDown("j") )
- {
- ++id;
- m_Owner.unitAnimation.AnimAirAttack(id);
- yield return null; // 等待animator更新
- yield return new WaitForTransitionDone(m_Owner.unitAnimation);
- }
+ bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
+ if(canCombo)
+ {
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
+ {
+ TurnLeft();
+ ChangeState(EUnitState.AirDash, new AirDashParam());
+ }
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
+ {
+ TurnRight();
+ ChangeState(EUnitState.AirDash, new AirDashParam());
+ }
+
+ if (Input.GetKeyDown("j"))
+ {
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ }
+ ++id;
+ m_Owner.unitAnimation.AnimAirAttack(id);
+ yield return null; // 等待animator更新
+ yield return new WaitForTransitionDone(m_Owner.unitAnimation);
+ }
+ }
bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1;
if (reachEnd)
@@ -236,11 +279,63 @@ public class UnitState : UnitComponent
}
- #endregion
+ #endregion
+
+ #region AirDash
+
+ IEnumerator AirDash(AirDashParam param)
+ {
+ m_Owner.unitAnimation.AnimAirDash();
+ yield return null;
+ while(true)
+ {
+ bool reachEnd = m_Owner.unitAnimation.layers[0].playbackNomralizedTime == 1;
+ if (reachEnd)
+ {
+ ChangeState(EUnitState.Landing, new LandingParam());
+ }
+
+ bool canCombo = m_Owner.unitAnimation.layers[0].IsToggleOpen(EAnimationToogle.Combo);
+ if(canCombo)
+ {
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.A, KeyCode.A))
+ {
+ TurnLeft();
+ m_Owner.unitAnimation.AnimAirDash();
+ }
+ if (InputManager.Instance.TryCommand(0.5f, KeyCode.D, KeyCode.D))
+ {
+ TurnRight();
+ m_Owner.unitAnimation.AnimAirDash();
+ }
+
+ if (Input.GetKeyDown("j"))
+ {
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ }
+ ChangeState(EUnitState.AirAttack, new SkillParam());
+ }
+ }
+
+ yield return null;
+ }
+ }
+
+ void OnAirDashExit(EUnitState next)
+ {
+ }
+
+ #endregion
- #region Jump
+ #region Jump
- IEnumerator Jump(JumpParam param)
+ IEnumerator Jump(JumpParam param)
{
unitAnimation.AnimJump();
yield return null;
@@ -271,18 +366,28 @@ public class UnitState : UnitComponent
m_Owner.unitAnimation.AnimLanding();
yield return null;
yield return new WaitForTransitionDone(m_Owner.unitAnimation);
- float vy = 0;
+ float vy = 2;
float g = 9.8f;
bool landingGround = false;
+ float vz = 5;
while (true)
{
Vector3 pos = m_Owner.transform.position;
vy += g * Time.deltaTime;
pos.y -= vy * Time.deltaTime;
pos.y = Mathf.Max(0, pos.y);
- m_Owner.transform.position = pos;
- Debug.Log(pos.y);
- if(pos.y > 0 && pos.y <= 1 && !landingGround)
+ if (Input.GetKey("a"))
+ {
+ TurnAround(false);
+ pos.x -= vz * Time.deltaTime;
+ }
+ if (Input.GetKey("d"))
+ {
+ TurnAround(true);
+ pos.x += vz * Time.deltaTime;
+ }
+ m_Owner.transform.position = pos;
+ if (pos.y > 0 && pos.y <= 1 && !landingGround)
{
landingGround = true;
m_Owner.unitAnimation.AnimLandingGround();
diff --git a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs
index 84a42ec1..f60689ad 100644
--- a/Assets/Scripts/Unit/RootMotion/RootMotionData.cs
+++ b/Assets/Scripts/Unit/RootMotion/RootMotionData.cs
@@ -40,3 +40,15 @@ public class RootMotionData : ScriptableObject
}
}
+
+public static class RootMotionUtility
+{
+ // zy平面的移动改为xy平面的移动
+ public static Vector3 ExchangeXZ(Vector3 dest)
+ {
+ float z = dest.z;
+ dest.z = dest.x;
+ dest.x = z;
+ return dest;
+ }
+}
diff --git a/Assets/Scripts/Unit/UnitRootMotion.cs b/Assets/Scripts/Unit/UnitRootMotion.cs
index c4d4b2c9..8c6edaa0 100644
--- a/Assets/Scripts/Unit/UnitRootMotion.cs
+++ b/Assets/Scripts/Unit/UnitRootMotion.cs
@@ -70,8 +70,9 @@ public class UnitRootMotion : UnitComponent
public void UpdateRootMotion()
{
+ // 因为Unti被旋转了90度,所以这里的deltaPosition的forward是x方向了
Vector3 dest = m_Owner.unitAnimation.animator.deltaPosition;
- dest.x = 0; //限制x轴始终在x=0
+ dest.z = 0;
var state = m_Owner.unitAnimation.layers[0].stateInfo;
if(state.IsTag("IgnoreY"))
@@ -79,7 +80,8 @@ public class UnitRootMotion : UnitComponent
dest.y = 0;
}
- m_Owner.transform.position += dest;
+ //m_Owner.transform.position += RootMotionUtility.ExchangeXZ(dest); // 不需要exchangeXZ
+ m_Owner.transform.position += dest;
}
#endif