Menu

第一楼关于人物移动

2018年6月24日 - 游戏开发

PlayEntity  PlayerMove

 

using Attributes;
using Entity;
using Game.Path;
using Manager;
using Skill;
using Skill.Test;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace Player
{
internal class PlayerEntity : EntityBase
{
[ReadOnly]
public string StatusDebug;
[ReadOnly]
public string SkillDebug;

public static PlayerEntity Instance;
public AudioClip RunSoundClip;

private AudioSource m_source;

private void OnEnable()
{
if (Instance != null)
throw new UnityException(“PlayerEntity.Instance!=null”);
Instance = this;
}

private void OnDisable()
{
Instance = null;
}

//单例
private PlayerSkillManager m_playerSkillManager;

private static readonly string[] s_hurt_animations = new string[] { “hurt1”, “hurt2”, “hurt3”, “hurt4”, “hurt5”, “hurt6”, “hurt7”};
protected override string[] HurtAnimationNames
{
get
{
return s_hurt_animations;
}
}

protected override void Awake()
{
base.Awake();
m_source = GetComponent<AudioSource>();
}

// Use this for initialization
protected override void Start()
{
m_animator = GetComponent<Animator>();
m_playerSkillManager = new PlayerSkillManager(this, m_animator);
SkillManager = m_playerSkillManager;

PlayerSkillManager.Instance.BindSkill<AttFloatAttack>(“Touch”).UseCond=(s)=> s.Skill.Hit == 1 ? InputManager.GetButton(“FloatSkillTrigger”) : true;
PlayerSkillManager.Instance.BindSkill<AttAttack>(“Touch”);
PlayerSkillManager.Instance.BindSkill<AtkFloatAttack>(“Thump”).UseCond = (s) => s.Skill.Hit == 1 ? InputManager.GetButton(“FloatSkillTrigger”) : true;
PlayerSkillManager.Instance.BindSkill<AtkAttack>(“Thump”);
//PlayerSkillManager.Instance.BindHoldSkill<HoldTestSkill>(“Thump”);
PlayerSkillManager.Instance.BindComboSkill<ComboTestSkill>(new string[] { “Thump”, “Thump”,”Touch”, “Thump” },EntityStatus.SecondJump);
PlayerSkillManager.Instance.BindComboSkill<ComboTestSkill2>(new string[] { “Forward”, “Touch”, “Touch” },EntityStatus.Grounded);
//PlayerSkillManager.Instance.BindHoldSkill<RemoteNormalSkill>(“NormalShot”);
PlayerSkillManager.Instance.BindSkill<TransferSkillPart1>(“Touch”, EntityStatus.Movement|EntityStatus.Grounded,StatusMatchOp.One,true, “TransferShot”);
//PlayerSkillManager.Instance.BindSkill<TransferSkillPart2>(“Transfer”);
//PlayerSkillManager.Instance.BindHoldSkill<ProjectileSkill>(“ProjectileShot”);

base.OnHurt += (self, cur) =>
{
if (base.HasStatusFlag(EntityStatus.TakeHit))
{
if (self.Impact.y > 0.5f)//浮空控制(丑,但没办法了)
{
var info = m_animator.GetCurrentAnimatorStateInfo(0);
if (info.IsName(“hurt5”))
{
if (info.normalizedTime > 0.58f)
{
m_animator.SetTrigger(“hurt7”);
}
else
{
m_animator.SetTrigger(“hurt6”);
}
}
else if (!(info.IsName(“hurt5”) || info.IsName(“hurt6”) || info.IsName(“hurt7”)))
{
m_animator.SetTrigger(“hurt5”);
}
return;
}
else if (self.Impact.y < -0.5)
{
m_animator.SetTrigger(“hurt7”);
return;
}

if (!base.HasStatusFlag(EntityStatus.Grounded))
m_animator.SetTrigger(“hurt3”);
else
m_animator.SetTrigger(“hurt1”);
}
};

OnDead += (self) =>
{
m_animator.SetTrigger(“die”);
//InputManager.EnableAsix = false;
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
};

base.Start();
}

protected override void OnDestroy()
{
PlayerSkillManager.ResetInstance();
Instance = null;
base.OnDestroy();
}

protected override void Update()
{
base.Update();
StatusDebug = Status.ToString();

var k = PlayerSkillManager.Instance.GetActivateSkill();
if (k != null)
SkillDebug = k.ToString();
else
SkillDebug = “”;

if(k!=null || HasStatusFlag(EntityStatus.Hurting))
{
InputManager.EnableAsix = false;
}
else if(IsSurvival)
{
InputManager.EnableAsix = true;
}
}

public override void OnPassNode(PathNode node)
{
if (LastPassNode == null) return;

Vector3 t = transform.forward;
float angle = 0.0f;

var offset = new Vector3(0, InputManager.GetAxisRaw(“Vertical”), 0);
if (HasStatusFlag(EntityStatus.FirstJump) || HasStatusFlag(EntityStatus.SecondJump))
offset = base.Velocity;
offset.Normalize();

PathNode.PathLink next_link= null;

foreach (var next in LastPassNode.ConnectLinks)
{
if (next.NextNode == LastPassNode) continue;

var vec = next.NextNodeDir;
var dir = vec.normalized;

float a = Vector3.Dot(dir, (t + offset).normalized);

if (a > angle)
{
angle = a;
t = dir;
next_link = next;
}
}

if (next_link != null)
{
SelectLink = next_link;
}
else
{
foreach (var next in LastPassNode.ConnectLinks)
{
if (next.NextNode != LastPassNode)
{
SelectLink = next;
break;
}
}
}
}

private void PlayRunSound()
{
m_source.PlayOneShot(RunSoundClip,1.0f);
}
}
}

 

using Entity;
using Manager;
using UnityEngine;

namespace Player
{
public class PlayerMove : MonoBehaviour
{
private PlayerEntity m_player;

private Transform m_meshTransform;

public float Speed = 5.0f;
public float Gravity = 9.8F;
public float InputRecoverTime = 0.2f;
public Vector3 circlePoint;
public bool OnCircle = false;
public bool opposite = false;

private CharacterController m_controller;
private Animator m_animator;

private void Awake()
{
m_player = GetComponentInChildren<PlayerEntity>();
m_meshTransform = transform.GetChild(0);
m_controller = GetComponent<CharacterController>();
m_animator = GetComponentInChildren<Animator>();
///Lamada表达式
m_player.OnStatusChanged += (l, c) =>
{
if (!EntityBase.HasStatusFlag(l, EntityStatus.Grounded) &&
EntityBase.HasStatusFlag(c, EntityStatus.Grounded))
{
InputManager.Enable = false;
Invoke(“EnableInput”, InputRecoverTime);
}

if (!EntityBase.HasStatusFlag(l, EntityStatus.Grounded) && EntityBase.HasStatusFlag(c, EntityStatus.Grounded))
{
m_player.ResetStatusFlag(EntityStatus.FirstJump);
m_player.ResetStatusFlag(EntityStatus.SecondJump);

m_animator.SetBool(“jump02”, false);
m_animator.SetBool(“jump01”, false);
}

if (EntityBase.HasStatusFlag(c, EntityStatus.Forward | EntityStatus.Grounded))
m_animator.SetBool(“move”, true);
else
m_animator.SetBool(“move”, false);
};
}

private void EnableInput()
{
InputManager.Enable = true;
}

private void Update()
{
//
if (OnCircle)
{
Vector3 dir1 = Vector3.Normalize(transform.position – circlePoint);
Vector3 pos1 = transform.position + dir1 * 20;

float x = (pos1.x – transform.position.x) * Mathf.Cos(-Mathf.PI / 2) + (pos1.z – transform.position.z) * Mathf.Sin(-Mathf.PI / 2) + transform.position.x;
float z = -(pos1.x – transform.position.x) * Mathf.Sin(-Mathf.PI / 2) + (pos1.z – transform.position.z) * Mathf.Cos(-Mathf.PI / 2) + transform.position.z;
Vector3 dir2 = new Vector3(x, transform.position.y, z) – transform.position;
transform.LookAt(new Vector3(x, transform.position.y, z));
//m_moveVelocity = new Vector3(InputManager.GetAxisRaw(“Horizontal”) * Mathf.Cos(angle), 0, -InputManager.GetAxisRaw(“Horizontal”) * Mathf.Sin(angle));
}

//Apply Move
int i = 1;
if (opposite)
i = -1;

m_player.Move(InputManager.GetAxisRaw(“Horizontal”) * Speed*i);

if (m_player.HasStatusFlag(EntityStatus.Grounded))
{
if (InputManager.GetButtonDown(“Jump”))
{
m_player.SetStatusFlag(EntityStatus.FirstJump);
m_animator.SetBool(“jump01”, true);
}
}
else
{
///状态标志
if (m_player.HasStatusFlag(EntityStatus.FirstJump) && InputManager.GetButtonDown(“Jump”))
{
m_player.ResetStatusFlag(EntityStatus.FirstJump);
m_player.SetStatusFlag(EntityStatus.SecondJump);

m_animator.SetBool(“jump02”, true);
m_animator.SetBool(“jump01”, false);
}
}
}
}
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

%d 博主赞过: