|
|
@@ -229,11 +229,6 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public override void FixedUpdate()
|
|
|
- {
|
|
|
- base.FixedUpdate();
|
|
|
- }
|
|
|
-
|
|
|
public void Jump()
|
|
|
{
|
|
|
SetUpSpeed(jumpSpeed);
|
|
|
@@ -256,6 +251,31 @@ public class PlayerController : MoveCharacter
|
|
|
//animalAni.SetInteger("state", (int)PlayerState.Rise);
|
|
|
}
|
|
|
|
|
|
+ public bool CheckSummon()
|
|
|
+ {
|
|
|
+ if (cacheSummonTime > 0)
|
|
|
+ {
|
|
|
+ Summon(cacheSummonId);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (btnWestPress)
|
|
|
+ {
|
|
|
+ Summon(0);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (btnSouthPress)
|
|
|
+ {
|
|
|
+ Summon(1);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (btnEastPress)
|
|
|
+ {
|
|
|
+ Summon(2);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
//角色处于可自由活动状态时的通用切换状态逻辑,如Idle、Run状态,以及别的状态结束时准备回到Idle状态前
|
|
|
public bool CheckPlayerChangeState(CharacterState excludeState = CharacterState.None)
|
|
|
{
|
|
|
@@ -297,35 +317,10 @@ public class PlayerController : MoveCharacter
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
- if (cacheSummonTime > 0)
|
|
|
- {
|
|
|
- if (excludeState != CharacterState.Summon)
|
|
|
- {
|
|
|
- Summon(cacheSummonId);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (btnWestPress)
|
|
|
- {
|
|
|
- if (excludeState != CharacterState.Summon)
|
|
|
- {
|
|
|
- Summon(0);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (btnSouthPress)
|
|
|
+ if (excludeState != CharacterState.Summon)
|
|
|
{
|
|
|
- if (excludeState != CharacterState.Summon)
|
|
|
+ if (CheckSummon())
|
|
|
{
|
|
|
- Summon(1);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (btnEastPress)
|
|
|
- {
|
|
|
- if (excludeState != CharacterState.Summon)
|
|
|
- {
|
|
|
- Summon(2);
|
|
|
return true;
|
|
|
}
|
|
|
}
|
|
|
@@ -417,6 +412,8 @@ public class PlayerController : MoveCharacter
|
|
|
rushTime -= Time.deltaTime;
|
|
|
cacheRushTime -= Time.deltaTime;
|
|
|
dieKeepTime -= Time.deltaTime;
|
|
|
+
|
|
|
+ Vector3 velocity = rb.velocity;
|
|
|
switch (state)
|
|
|
{
|
|
|
case CharacterState.Idle:
|
|
|
@@ -424,7 +421,6 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- //rb.velocity = Vector3.zero;
|
|
|
break;
|
|
|
case CharacterState.Run:
|
|
|
if (CheckPlayerChangeState(CharacterState.Run))
|
|
|
@@ -442,6 +438,10 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
break;
|
|
|
case CharacterState.Rise:
|
|
|
+ if (CheckSummon())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
|
|
|
{
|
|
|
ChangeState(CharacterState.Rush);
|
|
|
@@ -462,10 +462,13 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
}
|
|
|
CachedPlayerInput();
|
|
|
- rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
|
|
|
- AirMove();
|
|
|
+ rb.velocity = AirMove(rb.velocity);
|
|
|
break;
|
|
|
case CharacterState.Fall:
|
|
|
+ if (CheckSummon())
|
|
|
+ {
|
|
|
+ break;
|
|
|
+ }
|
|
|
if ((btnRushPress || cacheRushTime > 0) && mp >= rushCostMp)
|
|
|
{
|
|
|
ChangeState(CharacterState.Rush);
|
|
|
@@ -505,8 +508,7 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
}
|
|
|
CachedPlayerInput();
|
|
|
- rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
|
|
|
- AirMove();
|
|
|
+ rb.velocity = AirMove(rb.velocity);
|
|
|
break;
|
|
|
case CharacterState.Hurt:
|
|
|
if (hurtKeepTime <= 0)
|
|
|
@@ -517,11 +519,6 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
}
|
|
|
CachedPlayerInput();
|
|
|
- if (!foot.TrigGround)
|
|
|
- {
|
|
|
- rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
|
|
|
- }
|
|
|
- rb.velocity = rb.velocity / 5 * 4;
|
|
|
break;
|
|
|
case CharacterState.Attack:
|
|
|
if (attackTime <= 0)
|
|
|
@@ -556,7 +553,6 @@ public class PlayerController : MoveCharacter
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- Vector3 velocity = rb.velocity;
|
|
|
switch (attackState)
|
|
|
{
|
|
|
case PlayerAttackState.Idle:
|
|
|
@@ -566,12 +562,14 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkBack);
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x < -0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkForward);
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -581,16 +579,19 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkForward);
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x < -0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkBack);
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
velocity.x = 0;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
case PlayerAttackState.WalkForward:
|
|
|
if (bodyTrans.localScale.x > 0)
|
|
|
@@ -599,17 +600,20 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkBack);
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.Idle);
|
|
|
velocity.x = 0;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -618,17 +622,20 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkBack);
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.Idle);
|
|
|
velocity.x = 0;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
@@ -639,17 +646,20 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkForward);
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x > -0.3f && leftDir.x < 0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.Idle);
|
|
|
velocity.x = 0;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
@@ -658,24 +668,26 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.WalkForward);
|
|
|
velocity.x = attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else if (leftDir.x > -0.3f && leftDir.x > 0.3f)
|
|
|
{
|
|
|
SetAttackState(PlayerAttackState.Idle);
|
|
|
velocity.x = 0;
|
|
|
+ rb.velocity = velocity;
|
|
|
break;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
velocity.x = -attackMoveSpeed;
|
|
|
+ rb.velocity = velocity;
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- rb.velocity = velocity;
|
|
|
break;
|
|
|
case CharacterState.Summon:
|
|
|
if (summonTime <= 0)
|
|
|
@@ -747,6 +759,18 @@ public class PlayerController : MoveCharacter
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ if (!foot.TrigGround)
|
|
|
+ {
|
|
|
+ if (rb.velocity.y > 0)
|
|
|
+ {
|
|
|
+ rb.velocity += Vector3.up * extraRiseGravity * Time.deltaTime;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ rb.velocity += Vector3.up * extraFallGravity * Time.deltaTime;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
isClickBtnRush = false;
|
|
|
isKeepBtnRush = false;
|
|
|
isClickBtnJump = false;
|
|
|
@@ -775,18 +799,17 @@ public class PlayerController : MoveCharacter
|
|
|
|
|
|
public override void ChangeState(CharacterState newState)
|
|
|
{
|
|
|
- //print("ChangeState:" + state + ";" + newState);
|
|
|
+ Vector3 velocity = rb.velocity;
|
|
|
switch (state)
|
|
|
{
|
|
|
case CharacterState.Idle:
|
|
|
break;
|
|
|
case CharacterState.Run:
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
+ velocity.x = 0;
|
|
|
break;
|
|
|
case CharacterState.Rise:
|
|
|
break;
|
|
|
case CharacterState.Fall:
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
break;
|
|
|
case CharacterState.Hurt:
|
|
|
break;
|
|
|
@@ -799,10 +822,10 @@ public class PlayerController : MoveCharacter
|
|
|
case CharacterState.Summon:
|
|
|
break;
|
|
|
case CharacterState.Rush:
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
+ velocity = Vector3.zero;
|
|
|
break;
|
|
|
case CharacterState.Sprint:
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
+ velocity = Vector3.zero;
|
|
|
break;
|
|
|
case CharacterState.Die:
|
|
|
isDie = false;
|
|
|
@@ -824,7 +847,7 @@ public class PlayerController : MoveCharacter
|
|
|
{
|
|
|
ani.Play("idle", 0, 0);
|
|
|
}
|
|
|
- rb.velocity = Vector3.zero;
|
|
|
+ velocity = Vector3.zero;
|
|
|
//animalAni.SetInteger("state", (int)PlayerState.Idle);
|
|
|
break;
|
|
|
case CharacterState.Run:
|
|
|
@@ -866,11 +889,11 @@ public class PlayerController : MoveCharacter
|
|
|
invincibleTime = rushInvincibleTime;
|
|
|
if (bodyTrans.localScale.x > 0)
|
|
|
{
|
|
|
- rb.velocity = Vector3.left * rushSpeed;
|
|
|
+ velocity = Vector3.left * rushSpeed;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- rb.velocity = Vector3.right * rushSpeed;
|
|
|
+ velocity = Vector3.right * rushSpeed;
|
|
|
}
|
|
|
mp -= rushCostMp;
|
|
|
uiMp.Show(mp, totalMp);
|
|
|
@@ -880,11 +903,11 @@ public class PlayerController : MoveCharacter
|
|
|
ani.Play("rush_loop", 0, 0);
|
|
|
if (bodyTrans.localScale.x > 0)
|
|
|
{
|
|
|
- rb.velocity = Vector3.left * rushSpeed;
|
|
|
+ velocity = Vector3.left * rushSpeed;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- rb.velocity = Vector3.right * rushSpeed;
|
|
|
+ velocity = Vector3.right * rushSpeed;
|
|
|
}
|
|
|
break;
|
|
|
case CharacterState.Die:
|
|
|
@@ -896,6 +919,7 @@ public class PlayerController : MoveCharacter
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+ rb.velocity = velocity;
|
|
|
}
|
|
|
|
|
|
public void CheckTurn()
|
|
|
@@ -910,21 +934,22 @@ public class PlayerController : MoveCharacter
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void AirMove()
|
|
|
+ public Vector3 AirMove(Vector3 velocity)
|
|
|
{
|
|
|
CheckTurn();
|
|
|
if (leftDir.x > 0.3f)
|
|
|
{
|
|
|
- rb.velocity = new Vector3(moveSpeed, rb.velocity.y, rb.velocity.z);
|
|
|
+ velocity = new Vector3(moveSpeed, velocity.y, velocity.z);
|
|
|
}
|
|
|
else if (leftDir.x < -0.3f)
|
|
|
{
|
|
|
- rb.velocity = new Vector3(-moveSpeed, rb.velocity.y, rb.velocity.z);
|
|
|
+ velocity = new Vector3(-moveSpeed, velocity.y, velocity.z);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- rb.velocity = new Vector3(0, rb.velocity.y, rb.velocity.z);
|
|
|
+ velocity = new Vector3(0, velocity.y, velocity.z);
|
|
|
}
|
|
|
+ return velocity;
|
|
|
}
|
|
|
|
|
|
public void Summon(int id)
|