breakpoint
before change animation type
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Animancer;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITFALL.Movement.MotionBased
|
||||
{
|
||||
[Serializable]
|
||||
public sealed class MotionBasedClipTransition : ClipTransition, IMotionBasedAnimationState
|
||||
{
|
||||
object ICloneable.Clone() => MemberwiseClone();
|
||||
}
|
||||
[Serializable]
|
||||
public sealed class MotionBasedMixTransition : LinearMixerTransition, IMotionBasedAnimationState
|
||||
{
|
||||
object ICloneable.Clone() => MemberwiseClone();
|
||||
}
|
||||
}
|
@@ -38,23 +38,25 @@ namespace BITFALL.Movement.MotionBased
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
_override.RemoveOverride(-1);
|
||||
//_override.RemoveOverride(-1);
|
||||
animancerComponent.Layers[8].Stop();
|
||||
}
|
||||
else if( allowDeathAnimation)
|
||||
{
|
||||
animancerComponent.Layers[1].Stop();
|
||||
_override.AddOverride(-1);
|
||||
if (animationClips.TryGetValue("Death", out var clips) is false) return;
|
||||
var state = animancerComponent.Layers[8].Play(clips.Random());
|
||||
state.Events.OnEnd += OnEnd;
|
||||
return;
|
||||
void OnEnd()
|
||||
{
|
||||
_override.RemoveOverride(-1);
|
||||
state.Events.OnEnd = null;
|
||||
animancerComponent.Layers[8].Stop();
|
||||
}
|
||||
//animancerComponent.Layers[1].Stop();
|
||||
Play("Death",false,8);
|
||||
|
||||
// _override.AddOverride(-1);
|
||||
// if (animationClips.TryGetValue("Death", out var clips) is false) return;
|
||||
// var state = animancerComponent.Layers[8].Play(clips.Random());
|
||||
// state.Events.OnEnd += OnEnd;
|
||||
// return;
|
||||
// void OnEnd()
|
||||
// {
|
||||
// _override.RemoveOverride(-1);
|
||||
// state.Events.OnEnd = null;
|
||||
// animancerComponent.Layers[8].Stop();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,10 +71,11 @@ namespace BITFALL.Movement.MotionBased
|
||||
// }
|
||||
}
|
||||
public void Play(string animationName)=>Play(animationName,false);
|
||||
public void Play(string animationName, bool isAdditive)
|
||||
public void Play(string animationName, bool isAdditive,int layer = -1)
|
||||
{
|
||||
if (animationClips.TryGetValue(animationName, out var clip) is false) return;
|
||||
var layer = isAdditive ? 2 : 1;
|
||||
layer = layer is -1 ? isAdditive ? 2 : 1 : layer;
|
||||
|
||||
if (string.IsNullOrEmpty(lastAnimationName) is false)
|
||||
{
|
||||
_override.RemoveOverride(lastAnimationName);
|
||||
@@ -90,6 +93,7 @@ namespace BITFALL.Movement.MotionBased
|
||||
{
|
||||
state.Events.OnEnd = null;
|
||||
animancerComponent.Layers[layer].Stop();
|
||||
UnityEntity.Invoke(Constant.Animation.OnPlayEnd,animationName);
|
||||
if (isAdditive is false)
|
||||
_override.RemoveOverride(animationName);
|
||||
}
|
||||
|
@@ -16,6 +16,14 @@ namespace BITFALL.Movement.MotionBased
|
||||
public interface IMotionBasedState : IEntityMovementState
|
||||
{
|
||||
void OnAnimatorMove();
|
||||
}
|
||||
public interface IMotionBasedAnimationState:ICloneable
|
||||
{
|
||||
}
|
||||
public interface IMotionBasedAnimationClip{}
|
||||
public abstract class MotionBasedAnimationState
|
||||
{
|
||||
|
||||
}
|
||||
[CustomType(typeof(MotionBasedMovement))]
|
||||
public sealed class MotionBasedMovement : StateBasedBehavior<IMotionBasedState>,IEntityMovement
|
||||
@@ -151,8 +159,7 @@ namespace BITFALL.Movement.MotionBased
|
||||
get => Transform.rotation;
|
||||
set => Transform.rotation = value;
|
||||
}
|
||||
|
||||
Vector3 IEntityMovement.Forward => Transform.forward;
|
||||
public Vector3 Forward => Rotation * Vector3.forward;
|
||||
|
||||
Vector3 IEntityMovement.ViewForward => Transform.forward;
|
||||
|
||||
|
@@ -7,6 +7,7 @@ using AYellowpaper.SerializedCollections;
|
||||
using BITKit;
|
||||
using BITKit.Entities;
|
||||
using BITKit.StateMachine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.Splines;
|
||||
@@ -21,6 +22,8 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
[Inject] protected IHealth health;
|
||||
|
||||
protected Vector3 MotionVelocity { get; private set; }
|
||||
protected Vector3 MotionAngularVelocity { get; private set; }
|
||||
protected Quaternion MotionDeltaRotation { get; private set; }
|
||||
public virtual bool Enabled { get; set; }
|
||||
public virtual void Initialize()
|
||||
{
|
||||
@@ -63,6 +66,8 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
public virtual void OnAnimatorMove()
|
||||
{
|
||||
MotionVelocity = animancerComponent.Animator.velocity;
|
||||
MotionAngularVelocity = animancerComponent.Animator.angularVelocity;
|
||||
MotionDeltaRotation = animancerComponent.Animator.deltaRotation;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,11 +166,21 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
[Serializable]
|
||||
public sealed class Walk : MotionBasedState
|
||||
{
|
||||
[SerializeField] private AnimationClip clip;
|
||||
[SerializeField] private LinearMixerTransition _state;
|
||||
|
||||
private AnimancerState _playingState;
|
||||
|
||||
private float rot = 0;
|
||||
public override void OnStateEntry(IState old)
|
||||
{
|
||||
base.OnStateEntry(old);
|
||||
animancerComponent.Play(clip,0.1f);
|
||||
_playingState = animancerComponent.Play(_state);
|
||||
}
|
||||
|
||||
public override void OnStateExit(IState old, IState newState)
|
||||
{
|
||||
base.OnStateExit(old, newState);
|
||||
_playingState = null;
|
||||
}
|
||||
|
||||
public override void OnStateUpdate(float deltaTime)
|
||||
@@ -198,18 +213,44 @@ namespace BITFALL.Movement.MotionBased.States
|
||||
public override void UpdateRotation(ref Quaternion currentRotation, float deltaTime)
|
||||
{
|
||||
base.UpdateRotation(ref currentRotation, deltaTime);
|
||||
|
||||
var pathRotation = currentRotation;
|
||||
var lerpRotation = currentRotation;
|
||||
|
||||
var direction = agent.steeringTarget - agent.transform.position;
|
||||
if(direction.sqrMagnitude>0.1f)
|
||||
{
|
||||
direction = Vector3.ProjectOnPlane(direction, Vector3.up);
|
||||
currentRotation =
|
||||
pathRotation = Quaternion.LookRotation(direction);
|
||||
lerpRotation =
|
||||
Quaternion.RotateTowards(
|
||||
currentRotation,
|
||||
Quaternion.LookRotation(direction),
|
||||
pathRotation,
|
||||
360 * deltaTime
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
if (_playingState is not null)
|
||||
{
|
||||
var dir = pathRotation * Vector3.forward; //位置差,方向
|
||||
var dot = Vector3.Dot(movement.Forward, dir.normalized);//点乘判断前后:dot >0在前,<0在后
|
||||
var dot1 = Vector3.Dot(movement.transform.right, dir.normalized);//点乘判断左右: dot1>0在右,<0在左
|
||||
var angle = Mathf.Acos(Vector3.Dot(movement.Forward.normalized, dir.normalized)) * Mathf.Rad2Deg;//通过点乘求出
|
||||
|
||||
angle = dot1 > 0 ? angle : -angle;
|
||||
|
||||
var clamp = Mathf.Clamp(angle/45, -1, 1);
|
||||
|
||||
rot = Mathf.MoveTowards(rot, clamp, 8 * deltaTime);
|
||||
|
||||
_state.State.Parameter =rot ;
|
||||
|
||||
//Debug.Log($"angle:{angle} dot:{dot} dot1:{dot1} clamp:{clamp}");
|
||||
|
||||
}
|
||||
currentRotation = lerpRotation;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user