Lua向C#逻辑迁移 一期 #13

狐狸移动,技能迁移和完善
This commit is contained in:
2025-10-26 15:46:04 +08:00
parent dab9990b44
commit 8c0623b397
28 changed files with 605 additions and 323 deletions

View File

@ -1,54 +1,82 @@
// local LevelFoxRole = {}
// local Vector2D = require("Utils.Vector2D")
using UnrealSharp.Engine;
using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp.CoreUObject;
using System.Numerics;
using UnrealSharp.SpinePlugin;
// function LevelFoxRole:ctor()
namespace Level.Role;
// end
[UClass]
public class ABusyFoxRole : ABusyPlayerRole
{
private string lastAnimation = "";
// function LevelFoxRole:ReceiveBeginPlay()
// self["SpineAnimationComponent"]:SetAnimation(0, "Idle/Front", true)
// self.last_animation = "Idle/Front"
[UProperty(DefaultComponent = true, AttachmentComponent = "SpineRoot")]
protected USpineBoneFollowerComponent SpineBoneFollower { set; get; } // 用于跟踪尾巴的运动
// self["SpineBoneFollower"].Target = self
// self["SpineBoneFollower"].BoneName = "tail"
// self["SpineBoneFollower"].UseComponentTransform = true
// self["SpineBoneFollower"].UseScale = true
// self["TailCollision"]:SetCollisionEnabled(0)
// end
[UProperty(DefaultComponent = true, AttachmentComponent = "SpineBoneFollower")]
public UBoxComponent FoxTailCollision { set; get; } // 尾巴碰撞体组件
// function LevelFoxRole:OnMoveDirectionChanged(InDirection)
// -- 运动组件更新方向响应函数
// local cur_animation
// if Vector2D.Equals(InDirection, Vector2D.Zero) then -- Idle的情况
// local forward_direction = self["MovementComponent"]:GetForwardDirection()
// if(forward_direction.Y >= 0) then
// cur_animation = "Idle/Front"
// else
// cur_animation = "Idle/Back"
// end
// else
// if(InDirection.Y >= 0) then
// cur_animation = "Move/Front"
// else
// cur_animation = "Move/Back"
// end
// end
// if cur_animation ~= self.last_animation then
// self["SpineAnimationComponent"]:SetAnimation(0, cur_animation, true)
// self.last_animation = cur_animation
// end
[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);
// self["SpineAnimationComponent"]:SetTimeScale(1.0)
// end
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);
}
}
}
// function LevelFoxRole:OnMove(location)
// -- 控制器移动相应函数
// self["MovementComponent"]:MoveTo(location)
// end
// return Class(nil, nil, LevelFoxRole)