using UnrealSharp.Engine; using UnrealSharp.Attributes; using UnrealSharp.BusyRabbit; using UnrealSharp.CoreUObject; using System.Numerics; using UnrealSharp.SpinePlugin; namespace Level.Role; [UClass] public class ABusyFoxRole : ABusyPlayerRole { private string lastAnimation = ""; [UProperty(DefaultComponent = true, AttachmentComponent = "SpineRoot")] protected USpineBoneFollowerComponent SpineBoneFollower { set; get; } // 用于跟踪尾巴的运动 [UProperty(DefaultComponent = true, AttachmentComponent = "SpineBoneFollower")] public UBoxComponent FoxTailCollision { set; get; } // 尾巴碰撞体组件 [UFunction(FunctionFlags.BlueprintEvent)] public void SetTailCollisionEnabled(bool bIsEnable){} protected override void BeginPlay() { base.BeginPlay(); lastAnimation = "Idle/Front"; SpineAnimationComponent.SetAnimation(0, lastAnimation, true); MovementComponent.MoveDirectionChangedDelegate.Add(OnRoleMoveDirectionChanged); SpineBoneFollower.Target = this; SpineBoneFollower.BoneName = "tail"; SpineBoneFollower.UseComponentTransform = true; SpineBoneFollower.UseScale = true; SetTailCollisionEnabled(false); } protected override void EndPlay(EEndPlayReason endPlayReason) { base.EndPlay(endPlayReason); PrintString("haha1"); MovementComponent.MoveDirectionChangedDelegate.Remove(OnRoleMoveDirectionChanged); PrintString("haha2"); } [UFunction()] protected void OnRoleMoveDirectionChanged(FVector2D direction) { string currAnimation = ""; if (direction.Equals(Vector2.Zero)) // Idle的情况 { var forwardDirection = MovementComponent.ForwardDirection; if (forwardDirection.Y > 0) { currAnimation = "Idle/Front"; } else { currAnimation = "Idle/Back"; } } else { if (direction.Y >= 0) { currAnimation = "Move/Front"; } else currAnimation = "Move/Back"; } if (currAnimation != lastAnimation) { lastAnimation = currAnimation; SpineAnimationComponent.SetAnimation(0, currAnimation, true); } } }