修改字符模块
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6636b9d6db0317e43a61b41ac2b2297d
|
||||
guid: 5714b692b8275aa4cb37f8f22344174e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作动画控制器
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class KinesisAnimator : MonoBehaviour {
|
||||
protected int layerIndex;
|
||||
protected string current;
|
||||
protected Animator animator;
|
||||
protected IKinesis kinesis;
|
||||
|
||||
public virtual void Awake() => animator = GetComponent<Animator>();
|
||||
|
||||
/// <summary> 设置动作 </summary>
|
||||
public virtual void SetKinesis(IKinesis kinesis) => this.kinesis = kinesis;
|
||||
/// <summary> 动画过渡 </summary>
|
||||
public virtual void Transition(int layerIndex, string name, float normalizedTransitionDuration = 0.1f) {
|
||||
animator.SetLayerWeight(this.layerIndex, 0);
|
||||
animator.SetLayerWeight(layerIndex, 1);
|
||||
this.layerIndex = layerIndex;
|
||||
Transition(name, normalizedTransitionDuration);
|
||||
}
|
||||
/// <summary> 动画过渡 </summary>
|
||||
public virtual void Transition(string name, float normalizedTransitionDuration = 0.1f) {
|
||||
if (current == name) { animator.Play(name); }
|
||||
else { animator.CrossFade(name, normalizedTransitionDuration); }
|
||||
current = name;
|
||||
}
|
||||
|
||||
/// <summary> 设置参数 </summary>
|
||||
public virtual void SetBool(string name, bool value) => animator.SetBool(name, value);
|
||||
/// <summary> 设置参数 </summary>
|
||||
public virtual void SetFloat(string name, float value) => animator.SetFloat(name, value);
|
||||
|
||||
/// <summary> 触发动画特效 </summary>
|
||||
public virtual void AnimationEffects() => kinesis?.AnimationEffects();
|
||||
/// <summary> 动画结束(有后摇) </summary>
|
||||
public virtual void AnimationEnd() => kinesis?.AnimationEnd();
|
||||
/// <summary> 动画退出(无后摇) </summary>
|
||||
public virtual void AnimationExit() => kinesis?.AnimationExit();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作控制器
|
||||
/// </summary>
|
||||
public class KinesisController : MonoBehaviour {
|
||||
public KinesisAnimator animator;
|
||||
public KinesisMovement movement;
|
||||
|
||||
private IKinesis currentKinesis;
|
||||
|
||||
public virtual void Awake() => TransitionKinesis(new KinesisIdle());
|
||||
|
||||
public virtual void Update() => currentKinesis?.UpdateKinesis();
|
||||
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public virtual void TransitionKinesis(IKinesis kinesis) {
|
||||
//不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return; }
|
||||
//进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
|
||||
animator?.SetKinesis(currentKinesis);
|
||||
movement?.SetKinesis(currentKinesis);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 动作运动控制器
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(CharacterController))]
|
||||
public class KinesisMovement : MonoBehaviour {
|
||||
public float moveSpeed = 5;// 移动速度
|
||||
public float acceleration = 10.0f;// 加速度
|
||||
[Range(0.0f, 0.3f)]
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑
|
||||
|
||||
protected float currentSpeed;// 当前速度
|
||||
protected Vector2 moveDirection;// 移动方向
|
||||
protected float animationBlend;// 动画混合速度
|
||||
protected float targetRotation = 0.0f;// 旋转目标
|
||||
protected float rotationVelocity;// 旋转速度
|
||||
protected float verticalVelocity;// 垂直速度
|
||||
protected IKinesis kinesis;// 当前动作
|
||||
protected KinesisAnimator animator;// 动作动画控制器
|
||||
protected CharacterController controller;// 角色控制器
|
||||
|
||||
public virtual bool IsStop => currentSpeed == 0;
|
||||
|
||||
public virtual void Awake() {
|
||||
animator = GetComponent<KinesisAnimator>();
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
public virtual void Update() {
|
||||
PlanarMovement();
|
||||
}
|
||||
|
||||
/// <summary> 设置动作 </summary>
|
||||
public virtual void SetKinesis(IKinesis kinesis) => this.kinesis = kinesis;
|
||||
/// <summary> 设置方向 </summary>
|
||||
public virtual void SetDirection(Vector2 moveDirection) => this.moveDirection = moveDirection;
|
||||
/// <summary> 停止移动 </summary>
|
||||
public virtual void StopMovement() {
|
||||
currentSpeed = 0;
|
||||
moveDirection = Vector2.zero;
|
||||
animationBlend = 0;
|
||||
animator?.SetFloat("MoveSpeed", animationBlend);
|
||||
}
|
||||
|
||||
/// <summary> 平面移动 </summary>
|
||||
public virtual void PlanarMovement() {
|
||||
// 设定目标速度
|
||||
float targetSpeed = moveSpeed;
|
||||
|
||||
// 一种简单的加速和减速设计,易于拆卸、更换或迭代
|
||||
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero && currentSpeed == 0) { return; }
|
||||
if (moveDirection == Vector2.zero) targetSpeed = 0.0f;
|
||||
|
||||
// 当前水平速度的参考
|
||||
// float currentHorizontalSpeed = new Vector3(controller.velocity.x, 0.0f, controller.velocity.z).magnitude;
|
||||
|
||||
// float speedOffset = 0.1f;
|
||||
|
||||
// 加速或减速至目标速度
|
||||
// if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset) {
|
||||
// 产生弯曲的结果,而不是线性的结果,从而产生更有机的速度变化
|
||||
// 注意Lerp中的T是夹紧的,所以我们不需要夹紧我们的速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// round speed to 3 decimal places
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
// }
|
||||
// else { currentSpeed = targetSpeed; }
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, targetSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
|
||||
// 移动
|
||||
controller.Move(targetDirection.normalized * (currentSpeed * Time.deltaTime) + new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime);
|
||||
|
||||
// 如果使用角色,请更新动画师
|
||||
animator?.SetFloat("MoveSpeed", animationBlend);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 运动器
|
||||
/// </summary>
|
||||
public abstract class Movement {
|
||||
/// <summary> 当前速度 </summary>
|
||||
public abstract float Speed { get; }
|
||||
/// <summary> 是否接地 </summary>
|
||||
public abstract bool Grounded { get; }
|
||||
/// <summary> 移动 </summary>
|
||||
public abstract void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation);
|
||||
/// <summary> 跳跃 </summary>
|
||||
public abstract void Jump(float jumpHeight);
|
||||
/// <summary> 更新 </summary>
|
||||
public abstract void Update();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61ef13b926e462442920d0ba932e8e27
|
||||
guid: c48241a855a542e41b23b017edcab454
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,109 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 碰撞 - 运动器
|
||||
/// </summary>
|
||||
public class MovementCollision : Movement {
|
||||
/// <summary> 地面图层 </summary>
|
||||
public readonly LayerMask groundLayers;
|
||||
/// <summary> 角色控制器 </summary>
|
||||
public readonly CharacterController controller;
|
||||
|
||||
public float moveSpeed;// 移动速度
|
||||
public float currentSpeed;// 当前速度
|
||||
public float acceleration;// 加速度
|
||||
public float animationBlend;// 动画混合速度
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
|
||||
public bool isRotation;// 是否旋转
|
||||
public float targetRotation;// 目标旋转
|
||||
public float rotationVelocity;// 旋转速度
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑 Range(0.0f, 0.3f)
|
||||
|
||||
public bool grounded = true;// 是否接地
|
||||
public float verticalVelocity;// 垂直速度
|
||||
public float groundedRadius = 0.14f;// 地面检测半径
|
||||
|
||||
/// <summary> 垂直重力 </summary>
|
||||
public float Gravity => Physics.gravity.y;
|
||||
|
||||
public override float Speed => currentSpeed;
|
||||
|
||||
public override bool Grounded => grounded;
|
||||
|
||||
public MovementCollision(CharacterController controller, LayerMask groundLayers) {
|
||||
this.controller = controller;
|
||||
this.groundLayers = groundLayers;
|
||||
}
|
||||
|
||||
/// <summary> 移动 </summary>
|
||||
public override void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
/// <summary> H*-2*G的平方根=达到所需高度所需的速度 </summary>
|
||||
public override void Jump(float jumpHeight) {
|
||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * Gravity);
|
||||
}
|
||||
/// <summary> 更新 </summary>
|
||||
public override void Update() {
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero) moveSpeed = 0.0f;
|
||||
|
||||
// 当前速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, moveSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// 四舍五入到小数点后3位
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, moveSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
if (isRotation) {
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(controller.transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
controller.transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
// 移动
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
Vector3 horizontal = targetDirection.normalized * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
controller.Move(horizontal + vertical);
|
||||
}
|
||||
else {
|
||||
// 移动
|
||||
Vector3 horizontal = inputDirection * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
controller.Move(horizontal + vertical);
|
||||
}
|
||||
|
||||
// 地面检测
|
||||
Vector3 position = controller.transform.position;
|
||||
Vector3 rayOrigin = new Vector3(position.x, position.y + groundedRadius, position.z);
|
||||
// 射线长度稍微大于检测半径
|
||||
float rayLength = groundedRadius * 2 + 0.1f;
|
||||
// 使用射线检测地面
|
||||
grounded = Physics.Raycast(rayOrigin, Vector3.down, rayLength, groundLayers, QueryTriggerInteraction.Ignore);
|
||||
// 可选:调试显示射线
|
||||
Debug.DrawRay(rayOrigin, Vector3.down * rayLength, grounded ? Color.green : Color.red);
|
||||
|
||||
// 引力
|
||||
verticalVelocity += Gravity * Time.deltaTime;
|
||||
// 站在地面上时,限制最大下落速度
|
||||
if (grounded && verticalVelocity < 0.0f) { verticalVelocity = -2f; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3ceef7224b9b094aadaa9b3a0238648
|
||||
guid: 06f3697338f20ac459ed126fc05a9694
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,101 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 标准 - 运动器
|
||||
/// </summary>
|
||||
public class MovementStandard : Movement {
|
||||
/// <summary> 地面图层 </summary>
|
||||
public readonly LayerMask groundLayers;
|
||||
/// <summary> 变换 </summary>
|
||||
public readonly Transform transform;
|
||||
|
||||
public float moveSpeed;// 移动速度
|
||||
public float currentSpeed;// 当前速度
|
||||
public float acceleration;// 加速度
|
||||
public float animationBlend;// 动画混合速度
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
|
||||
public bool isRotation;// 是否旋转
|
||||
public float targetRotation;// 目标旋转
|
||||
public float rotationVelocity;// 旋转速度
|
||||
public float rotationSmoothTime = 0.12f;// 旋转平滑 Range(0.0f, 0.3f)
|
||||
|
||||
public bool grounded = true;// 是否接地
|
||||
public float verticalVelocity;// 垂直速度
|
||||
public float groundedRadius = 0.14f;// 地面检测半径
|
||||
|
||||
/// <summary> 垂直重力 </summary>
|
||||
public float Gravity => Physics.gravity.y;
|
||||
|
||||
public override float Speed => currentSpeed;
|
||||
|
||||
public override bool Grounded => grounded;
|
||||
|
||||
public MovementStandard(Transform transform, LayerMask groundLayers) {
|
||||
this.transform = transform;
|
||||
this.groundLayers = groundLayers;
|
||||
}
|
||||
|
||||
/// <summary> 移动 </summary>
|
||||
public override void Move(Vector2 moveDirection, float moveSpeed, float acceleration, bool isRotation) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
/// <summary> 跳跃 </summary>
|
||||
public override void Jump(float jumpHeight) {
|
||||
verticalVelocity = Mathf.Sqrt(jumpHeight * -2f * Gravity);
|
||||
}
|
||||
/// <summary> 更新 </summary>
|
||||
public override void Update() {
|
||||
// 如果没有输入,将目标速度设置为0
|
||||
if (moveDirection == Vector2.zero) moveSpeed = 0.0f;
|
||||
|
||||
// 当前速度
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, moveSpeed, Time.deltaTime * acceleration);
|
||||
|
||||
// 四舍五入到小数点后3位
|
||||
currentSpeed = Mathf.Round(currentSpeed * 1000f) / 1000f;
|
||||
|
||||
animationBlend = Mathf.Lerp(animationBlend, moveSpeed, Time.deltaTime * acceleration);
|
||||
if (animationBlend < 0.01f) animationBlend = 0f;
|
||||
|
||||
// 使输入方向标准化
|
||||
Vector3 inputDirection = new Vector3(moveDirection.x, 0.0f, moveDirection.y).normalized;
|
||||
|
||||
// 如果有移动输入,则在玩家移动时旋转玩家
|
||||
if (moveDirection != Vector2.zero && isRotation) {
|
||||
targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg;
|
||||
float rotation = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetRotation, ref rotationVelocity, rotationSmoothTime);
|
||||
|
||||
// 相对于相机位置旋转到面向输入方向
|
||||
transform.rotation = Quaternion.Euler(0.0f, rotation, 0.0f);
|
||||
}
|
||||
|
||||
// 移动
|
||||
Vector3 targetDirection = Quaternion.Euler(0.0f, targetRotation, 0.0f) * Vector3.forward;
|
||||
Vector3 horizontal = targetDirection.normalized * (currentSpeed * Time.deltaTime);
|
||||
Vector3 vertical = new Vector3(0.0f, verticalVelocity, 0.0f) * Time.deltaTime;
|
||||
transform.position += horizontal + vertical;
|
||||
|
||||
// 地面检测
|
||||
Vector3 position = transform.position;
|
||||
Vector3 rayOrigin = new Vector3(position.x, position.y + groundedRadius, position.z);
|
||||
// 射线长度稍微大于检测半径
|
||||
float rayLength = groundedRadius * 2 + 0.1f;
|
||||
// 使用射线检测地面
|
||||
grounded = Physics.Raycast(rayOrigin, Vector3.down, rayLength, groundLayers, QueryTriggerInteraction.Ignore);
|
||||
// 可选:调试显示射线
|
||||
Debug.DrawRay(rayOrigin, Vector3.down * rayLength, grounded ? Color.green : Color.red);
|
||||
|
||||
// 引力
|
||||
verticalVelocity += Gravity * Time.deltaTime;
|
||||
// 站在地面上时,限制最大下落速度
|
||||
if (grounded && verticalVelocity < 0.0f) { verticalVelocity = -2f; }
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99fdb0fe5f05b3b44bf010af88ab1f8f
|
||||
guid: cf671b0b45929dc4c970eadb97df3ec8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a373c751fa5625249af75654ab69aec4
|
||||
guid: 197992f6020004c44a74153f43c5f7d1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
|
||||
@@ -4,23 +4,18 @@ using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 角色动作
|
||||
/// 运动
|
||||
/// </summary>
|
||||
public interface IKinesis {
|
||||
public abstract class IKinesis {
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public bool Transition(IKinesis kinesis);
|
||||
public abstract bool Transition(IKinesis kinesis);
|
||||
/// <summary> 开始动作 </summary>
|
||||
public void StartKinesis();
|
||||
public abstract void StartKinesis();
|
||||
/// <summary> 更新动作 </summary>
|
||||
public void UpdateKinesis();
|
||||
public abstract void UpdateKinesis();
|
||||
/// <summary> 完成动作 </summary>
|
||||
public void FinishKinesis();
|
||||
|
||||
/// <summary> 触发动画特效 </summary>
|
||||
public void AnimationEffects();
|
||||
/// <summary> 动画结束(有后摇) </summary>
|
||||
public void AnimationEnd();
|
||||
/// <summary> 动画退出(无后摇) </summary>
|
||||
public void AnimationExit();
|
||||
public abstract void FinishKinesis();
|
||||
/// <summary> 动画结束 </summary>
|
||||
public abstract void AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e096ab8673cda9e42be867d97aae83eb
|
||||
guid: 1490d224da1fe674cb366599e7603d66
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c36f49b360d4c048aef47715ebb0616
|
||||
guid: 338d1e647d487fe43aee258fbf63dfd4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 空闲 - 运动
|
||||
/// </summary>
|
||||
public class KIdle : IKinesis {
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return true;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c1979e13b26c7b48a7a4690da154535
|
||||
guid: 29150243edc07d0429fea37464e830a7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 跳跃 - 运动
|
||||
/// </summary>
|
||||
public class KJump : IKinesis {
|
||||
/// <summary> 基础角色 </summary>
|
||||
public readonly MCharacter character;
|
||||
|
||||
/// <summary> 结束跳跃 </summary>
|
||||
public bool isEndJump;
|
||||
/// <summary> 是否接地 </summary>
|
||||
public bool isGrounded;
|
||||
/// <summary> 允许转换 </summary>
|
||||
public bool isTransition;
|
||||
/// <summary> 跳跃高度 </summary>
|
||||
public float jumpHeight;
|
||||
/// <summary> 衰退速度 </summary>
|
||||
public float decaySpeed;
|
||||
/// <summary> 移动速度 </summary>
|
||||
public float moveSpeed = 2;
|
||||
/// <summary> 加速度 </summary>
|
||||
public float acceleration = 15;
|
||||
/// <summary> 移动方向 </summary>
|
||||
public Vector2 moveDirection;
|
||||
/// <summary> 初始位置 </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 初始角度 </summary>
|
||||
public Vector3 eulerAngles;
|
||||
/// <summary> 是否旋转 </summary>
|
||||
public bool isRotation;
|
||||
/// <summary> 初始设置 </summary>
|
||||
public bool isInitial = false;
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform => character.transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator => character.animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement => character.movement;
|
||||
|
||||
public KJump(MCharacter character, Vector2 moveDirection, float jumpHeight, bool isRotation) {
|
||||
this.character = character;
|
||||
this.moveDirection = moveDirection;
|
||||
this.jumpHeight = jumpHeight;
|
||||
}
|
||||
|
||||
public void Settings(float moveSpeed, float acceleration) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
public void Settings(Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
isInitial = true;
|
||||
}
|
||||
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return isTransition;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
if (isInitial) {
|
||||
character.transform.position = position;
|
||||
character.transform.eulerAngles = eulerAngles;
|
||||
}
|
||||
isEndJump = false;
|
||||
isTransition = false;
|
||||
isGrounded = movement.Grounded;
|
||||
decaySpeed = movement.Speed;
|
||||
movement.Jump(jumpHeight);
|
||||
animator.SetTrigger("JumpStart");
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
if (isEndJump) { return; }
|
||||
// 衰退速度
|
||||
decaySpeed = Mathf.Lerp(decaySpeed, 0, Time.deltaTime * 0.8f);
|
||||
movement.Move(moveDirection, decaySpeed, acceleration, isRotation);
|
||||
// 跳跃状态判断
|
||||
if (isGrounded == movement.Grounded) { return; }
|
||||
isGrounded = movement.Grounded;
|
||||
// 起跳
|
||||
if (!isGrounded) { return; }
|
||||
// 落地
|
||||
isEndJump = true;
|
||||
animator.SetTrigger("JumpLand");
|
||||
movement.Move(Vector2.zero, decaySpeed, acceleration, isRotation);
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
isTransition = true;
|
||||
// 转换到移动
|
||||
KMove kMove = new KMove(character, moveDirection, isRotation);
|
||||
kMove.Settings(moveSpeed, acceleration);
|
||||
character.Transition(kMove);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d61c404e3dc615b4eb590448b876863c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 移动 - 运动
|
||||
/// </summary>
|
||||
public class KMove : IKinesis {
|
||||
/// <summary> 基础角色 </summary>
|
||||
public readonly MCharacter character;
|
||||
|
||||
/// <summary> 移动速度 </summary>
|
||||
public float moveSpeed = 2;
|
||||
/// <summary> 加速度 </summary>
|
||||
public float acceleration = 15;
|
||||
/// <summary> 移动方向 </summary>
|
||||
public Vector2 moveDirection;
|
||||
/// <summary> 初始位置 </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 初始角度 </summary>
|
||||
public Vector3 eulerAngles;
|
||||
/// <summary> 是否旋转 </summary>
|
||||
public bool isRotation;
|
||||
/// <summary> 初始设置 </summary>
|
||||
public bool isInitial = false;
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform => character.transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator => character.animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement => character.movement;
|
||||
|
||||
public KMove(MCharacter character, Vector2 moveDirection, bool isRotation) {
|
||||
this.character = character;
|
||||
this.moveDirection = moveDirection;
|
||||
this.isRotation = isRotation;
|
||||
}
|
||||
|
||||
public void Settings(float moveSpeed, float acceleration) {
|
||||
this.moveSpeed = moveSpeed;
|
||||
this.acceleration = acceleration;
|
||||
}
|
||||
public void Settings(Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
isInitial = true;
|
||||
}
|
||||
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
return true;
|
||||
}
|
||||
public override void StartKinesis() {
|
||||
movement.Move(moveDirection, moveSpeed, acceleration, isRotation);
|
||||
if (!isInitial) { return; }
|
||||
transform.position = position;
|
||||
transform.eulerAngles = eulerAngles;
|
||||
}
|
||||
public override void UpdateKinesis() {
|
||||
// 更新动画器
|
||||
animator.SetFloat("MoveSpeed", movement.Speed);
|
||||
// 移动结束
|
||||
if (movement.Speed == 0) { character.Transition(new KIdle()); }
|
||||
}
|
||||
public override void FinishKinesis() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
// throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2b41872ba018e447a649cb6bb35059f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 角色 - 模块
|
||||
/// </summary>
|
||||
public abstract class MCharacter {
|
||||
|
||||
/// <summary> 变换器 </summary>
|
||||
public Transform transform;
|
||||
/// <summary> 动画器 </summary>
|
||||
public Animator animator;
|
||||
/// <summary> 运动器 </summary>
|
||||
public Movement movement;
|
||||
|
||||
public MCharacter(Animator animator) => this.animator = animator;
|
||||
|
||||
/// <summary> 更新 </summary>
|
||||
public abstract void Update();
|
||||
/// <summary> 动作过渡 </summary>
|
||||
public abstract bool Transition(IKinesis kinesis);
|
||||
/// <summary> 动画结束 </summary>
|
||||
public abstract void AnimationExit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f75543aff254f1c4899eb3d332ba5de9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 碰撞角色 - 模块
|
||||
/// </summary>
|
||||
public class MCharacterCollision : MCharacter {
|
||||
|
||||
/// <summary> 当前动作 </summary>
|
||||
public IKinesis currentKinesis;
|
||||
|
||||
public MCharacterCollision(Animator animator, CharacterController controller, LayerMask ground) : base(animator) {
|
||||
movement = new MovementCollision(controller, ground);
|
||||
|
||||
Transition(new KIdle());
|
||||
}
|
||||
|
||||
public override void Update() {
|
||||
movement.Update();
|
||||
currentKinesis.UpdateKinesis();
|
||||
}
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
// 不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return false; }
|
||||
// 进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
return true;
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
currentKinesis.AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa752d6843dd06146b699b3588a59ea1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MCharacterRigidbody : MonoBehaviour
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c073d7ddd6e118746b2709e22bcf7ea6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 标准角色 - 模块
|
||||
/// </summary>
|
||||
public class MCharacterStandard : MCharacter {
|
||||
|
||||
/// <summary> 当前动作 </summary>
|
||||
public IKinesis currentKinesis;
|
||||
|
||||
public MCharacterStandard(Animator animator, LayerMask ground) : base(animator) {
|
||||
movement = new MovementStandard(transform, ground);
|
||||
|
||||
Transition(new KIdle());
|
||||
}
|
||||
|
||||
public override void Update() {
|
||||
movement.Update();
|
||||
currentKinesis.UpdateKinesis();
|
||||
}
|
||||
public override bool Transition(IKinesis kinesis) {
|
||||
// 不可以转换
|
||||
if (currentKinesis != null && !currentKinesis.Transition(kinesis)) { return false; }
|
||||
// 进行转换
|
||||
currentKinesis?.FinishKinesis();
|
||||
currentKinesis = kinesis;
|
||||
currentKinesis?.StartKinesis();
|
||||
return true;
|
||||
}
|
||||
public override void AnimationExit() {
|
||||
currentKinesis.AnimationExit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7eb8fc105ff36704499c0a954daa9c5c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,20 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 空闲动作
|
||||
/// </summary>
|
||||
public class KinesisIdle : IKinesis {
|
||||
|
||||
public bool Transition(IKinesis kinesis) => true;
|
||||
public void StartKinesis() { }
|
||||
public void UpdateKinesis() { }
|
||||
public void FinishKinesis() { }
|
||||
|
||||
public void AnimationEffects() { }
|
||||
public void AnimationEnd() { }
|
||||
public void AnimationExit() { }
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MuHua {
|
||||
/// <summary>
|
||||
/// 移动动作
|
||||
/// </summary>
|
||||
public class KinesisMove : IKinesis {
|
||||
|
||||
public Vector3 position;
|
||||
public Vector3 eulerAngles;
|
||||
public Vector2 moveDirection;// 移动方向
|
||||
public KinesisMovement movement;
|
||||
public KinesisController controller;
|
||||
|
||||
public KinesisMove(KinesisController controller, Vector2 moveDirection) {
|
||||
this.controller = controller;
|
||||
this.moveDirection = moveDirection;
|
||||
movement = controller.movement;
|
||||
position = movement.transform.position;
|
||||
eulerAngles = movement.transform.eulerAngles;
|
||||
}
|
||||
public KinesisMove(KinesisController controller, Vector2 moveDirection, Vector3 position, Vector3 eulerAngles) {
|
||||
this.position = position;
|
||||
this.eulerAngles = eulerAngles;
|
||||
this.controller = controller;
|
||||
this.moveDirection = moveDirection;
|
||||
movement = controller.movement;
|
||||
}
|
||||
|
||||
public bool Transition(IKinesis kinesis) {
|
||||
KinesisMove move = kinesis as KinesisMove;
|
||||
if (move == null) { return true; }
|
||||
position = move.position;
|
||||
eulerAngles = move.eulerAngles;
|
||||
moveDirection = move.moveDirection;
|
||||
movement.transform.position = position;
|
||||
movement.transform.eulerAngles = eulerAngles;
|
||||
movement.SetDirection(moveDirection);
|
||||
return false;
|
||||
}
|
||||
public void StartKinesis() {
|
||||
movement.transform.position = position;
|
||||
movement.transform.eulerAngles = eulerAngles;
|
||||
movement.SetDirection(moveDirection);
|
||||
}
|
||||
public void UpdateKinesis() {
|
||||
if (!movement.IsStop) { return; }
|
||||
controller.TransitionKinesis(new KinesisIdle());
|
||||
}
|
||||
public void FinishKinesis() {
|
||||
movement.StopMovement();
|
||||
}
|
||||
|
||||
public void AnimationEffects() { }
|
||||
public void AnimationEnd() { }
|
||||
public void AnimationExit() { }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c1bd98cf0e078140ab99d637e398ed1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user