架构大更
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
public class CharacterAnimation : MonoBehaviour
|
||||
{
|
||||
private Character _character;
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
_character = GetComponent<Character>();
|
||||
@@ -23,20 +23,14 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
|
||||
public void Ready()
|
||||
{
|
||||
if (GetState() == CharacterState.Run)
|
||||
{
|
||||
EffectManager.Instance.CreateSpriteEffect(_character, "Brake");
|
||||
}
|
||||
if (GetState() == CharacterState.Run) EffectManager.Instance.CreateSpriteEffect(_character, "Brake");
|
||||
|
||||
SetState(CharacterState.Ready);
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
if (GetState() != CharacterState.Run)
|
||||
{
|
||||
EffectManager.Instance.CreateSpriteEffect(_character, "Run");
|
||||
}
|
||||
if (GetState() != CharacterState.Run) EffectManager.Instance.CreateSpriteEffect(_character, "Run");
|
||||
|
||||
SetState(CharacterState.Run);
|
||||
}
|
||||
@@ -116,10 +110,11 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
|
||||
public void SetState(CharacterState state)
|
||||
{
|
||||
foreach (var variable in new[] { "Idle", "Ready", "Walk", "Run", "Crouch", "Crawl", "Jump", "Fall", "Land", "Block", "Climb", "Die" })
|
||||
{
|
||||
_character.Animator.SetBool(variable, false);
|
||||
}
|
||||
foreach (var variable in new[]
|
||||
{
|
||||
"Idle", "Ready", "Walk", "Run", "Crouch", "Crawl", "Jump", "Fall", "Land", "Block", "Climb",
|
||||
"Die"
|
||||
}) _character.Animator.SetBool(variable, false);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
|
||||
@@ -9,9 +9,11 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
[RequireComponent(typeof(CharacterAnimation))]
|
||||
public class CharacterControls : MonoBehaviour
|
||||
{
|
||||
private CharacterAnimation _animation;
|
||||
private Character _character;
|
||||
private CharacterController2D _controller;
|
||||
private CharacterAnimation _animation;
|
||||
|
||||
private float _fireTime;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
@@ -41,22 +43,12 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
_controller.Input = Vector2.zero;
|
||||
|
||||
if (Input.GetKey(KeyCode.LeftArrow))
|
||||
{
|
||||
_controller.Input.x = -1;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.RightArrow))
|
||||
{
|
||||
_controller.Input.x = 1;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.RightArrow)) _controller.Input.x = 1;
|
||||
|
||||
if (Input.GetKey(KeyCode.UpArrow))
|
||||
{
|
||||
_controller.Input.y = 1;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.DownArrow))
|
||||
{
|
||||
_controller.Input.y = -1;
|
||||
}
|
||||
else if (Input.GetKey(KeyCode.DownArrow)) _controller.Input.y = -1;
|
||||
}
|
||||
|
||||
private void Attack()
|
||||
@@ -66,19 +58,14 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
if (Input.GetKeyDown(KeyCode.P)) _animation.Push();
|
||||
if (Input.GetKeyDown(KeyCode.O)) _animation.Shot();
|
||||
if (Input.GetKey(KeyCode.F)) Fire();
|
||||
if (Input.GetKey(KeyCode.Q)) Fire(power: true);
|
||||
if (Input.GetKey(KeyCode.Q)) Fire(true);
|
||||
}
|
||||
|
||||
private float _fireTime;
|
||||
|
||||
public void Fire(bool power = false)
|
||||
{
|
||||
if (Time.time - _fireTime < 0.15f) return;
|
||||
|
||||
if (_animation.GetState() == CharacterState.Idle)
|
||||
{
|
||||
_animation.Ready();
|
||||
}
|
||||
if (_animation.GetState() == CharacterState.Idle) _animation.Ready();
|
||||
|
||||
_fireTime = Time.time;
|
||||
|
||||
@@ -94,7 +81,8 @@ namespace Assets.PixelFantasy.PixelHeroes.Common.Scripts.ExampleScripts
|
||||
|
||||
_character.AudioSource.pitch = Random.Range(0.9f, 1.1f);
|
||||
_character.AudioSource.PlayOneShot(EffectManager.Instance.FireAudioClip);
|
||||
EffectManager.Instance.CreateSpriteEffect(_character, power ? "FireMuzzleM" : "FireMuzzleS", direction: 1, parent: _character.Firearm.FireMuzzle);
|
||||
EffectManager.Instance.CreateSpriteEffect(_character, power ? "FireMuzzleM" : "FireMuzzleS", 1,
|
||||
_character.Firearm.FireMuzzle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user