Lua向C#逻辑迁移 一期

创建了若干C#文件,替代对应lua文件
This commit is contained in:
2025-10-25 05:53:20 +08:00
parent fc1078f20c
commit dab9990b44
25 changed files with 336 additions and 5411 deletions

View File

@ -0,0 +1 @@
// 角色移动

View File

@ -0,0 +1,196 @@
// local GameplayStatics = import("GameplayStatics")
// local AbilitySystemBlueprintLibrary = import("AbilitySystemBlueprintLibrary")
// local BusyGameplayLibrary = import("BusyGameplayLibrary")
// --- @class FoxUltimate
// --- @field RecastWindow number
// local FoxUltimate = {}
// function FoxUltimate:ctor()
// self.ultimate_phase = 1 -- 大招阶段
// self.active_recast_handle = nil
// self.active_accelerate_handle = nil
// self.overlap_delegate_handle = nil
// self.tag_add_or_remove_delegate = nil
// end
// function FoxUltimate:K2_ActivateAbilityFromEvent(EventData)
// print("FoxUltimate:K2_ActivateAbilityFromEvent", self.ultimate_phase)
// if not self:K2_CommitAbilityCost(false) then
// return self:K2_EndAbility()
// end
// local owner = self:GetOwningActorFromActorInfo()
// self.movement = owner.MovementComponent
// self.animation = owner.SpineAnimationComponent
// self.asc = AbilitySystemBlueprintLibrary.GetAbilitySystemComponent(owner)
// self.recast_tag = BusyGameplayLibrary.RequestGameplayTag("Ability.Flags.Recast")
// self.owner = owner
// local asc = self.asc
// if self.tag_add_or_remove_delegate == nil then
// self.tag_add_or_remove_delegate = slua.createDelegate(function(tag, is_add)
// if is_add == 0 and not self.bIsActive then
// self.ultimate_phase = 1
// self:K2_CommitAbilityCooldown(false, false)
// end
// end)
// owner:BindGameplayTagAddOrRemove(self.recast_tag, self.tag_add_or_remove_delegate)
// end
// if self.ultimate_phase == 1 or asc:HasMatchingGameplayTag(self.recast_tag) then
// self:TriggerUltimate(asc)
// else
// self:K2_EndAbility()
// end
// end
// function FoxUltimate:TriggerUltimate(asc)
// if self.ultimate_phase == 1 then
// -- 第一次释放大招添加一个可以再次释放的Tag
// local _, recast_effect = self:GetAbilityEffectSpecHandle("Recast", asc, 1, nil)
// self.active_recast_handle = asc:BP_ApplyGameplayEffectSpecToSelf(recast_effect)
// elseif self.ultimate_phase == 2 then
// -- 第二次激活移除可重复释放的tag
// self.asc:RemoveActiveGameplayEffect(self.active_recast_handle, -1)
// elseif self.ultimate_phase == 3 then
// self.asc:RemoveActiveGameplayEffect(self.active_recast_handle, -1)
// end
// -- 播放动画,并监听动画完成的事件
// self:PlayAnimation()
// end
// function FoxUltimate:GetAnimationName(direction)
// local animation_name_prefix
// if direction.X >= 0 then
// animation_name_prefix = "Ultimate/Right/"
// else
// animation_name_prefix = "Ultimate/Left/"
// end
// if self.ultimate_phase == 1 then
// return animation_name_prefix .. "UltimateStage1"
// elseif self.ultimate_phase == 2 then
// return animation_name_prefix .. "UltimateStage2"
// elseif self.ultimate_phase == 3 then
// return animation_name_prefix .. "UltimateStage3"
// end
// return nil
// end
// function FoxUltimate:K2_OnEndAbility(bWasCancelled)
// print("FoxUltimate:K2_OnEndAbility")
// end
// function FoxUltimate:GetSprintSpeedFactor()
// if self.ultimate_phase == 1 then
// return 2.5
// elseif self.ultimate_phase == 2 then
// return 2.8
// elseif self.ultimate_phase == 3 then
// return 3.0
// end
// end
// function FoxUltimate:PlayAnimation()
// local animation = self.animation
// local PC = GameplayStatics.GetPlayerController(self, 0)
// local result, ability_direction = PC:GetCursorDirection(nil) -- 获取技能的朝向
// if not result then
// print("FoxUltimate:TriggerPrimaryPhase can't find direction")
// return
// end
// local anim_name = self:GetAnimationName(ability_direction) -- 获取技能动画名称
// if not anim_name then
// print("FoxUltimate:TriggerPrimaryPhase can't get animation", self.ultimate_phase)
// return
// end
// local anim_entry = animation:SetAnimation(0, anim_name, false)
// anim_entry.AnimationComplete:Add(function(entry) self:OnAnimationComplete(entry) end)
// anim_entry.AnimationEvent:Add(function(entry, event) self:OnAnimationEvent(entry, event) end)
// local anim_total_time = anim_entry:GetAnimationEnd() -- 获取技能动画时长
// -- 附加加速buff
// self:MakeAccelerate(self:GetSprintSpeedFactor(), anim_total_time)
// self.movement:ActivateSprint(ability_direction, anim_total_time)
// end
// function FoxUltimate:MakeAccelerate(speed_factor, total_time)
// local _, accelerate_effect = self:GetAbilityEffectSpecHandle("Accelerate", self.asc, 1, nil)
// AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude(
// accelerate_effect,
// BusyGameplayLibrary.RequestGameplayTag("Effect.Factor"),
// speed_factor
// )
// AbilitySystemBlueprintLibrary.AssignTagSetByCallerMagnitude(
// accelerate_effect,
// BusyGameplayLibrary.RequestGameplayTag("Effect.Duration"),
// total_time
// )
// return self.asc:BP_ApplyGameplayEffectSpecToSelf(accelerate_effect)
// end
// function FoxUltimate:OnAnimationComplete(entry)
// local new_phase = self.ultimate_phase + 1
// if new_phase > 3 then
// self.ultimate_phase = 1
// else
// self.ultimate_phase = new_phase
// end
// print("FoxUltimate:OnAnimationComplete", self.ultimate_phase)
// if not self.asc:HasMatchingGameplayTag(self.recast_tag) then
// self.ultimate_phase = 1
// self:K2_CommitAbilityCooldown(false, false)
// end
// entry.AnimationComplete:Clear()
// entry.AnimationEvent:Clear()
// self:K2_EndAbility()
// end
// function FoxUltimate:OnAnimationEvent(entry, event)
// if event.Name == "OnSpeedChange" then
// self.active_accelerate_handle = self:MakeAccelerate(8.0, 0.5)
// elseif event.Name == "OnSpeedReset" then
// self.asc:RemoveActiveGameplayEffect(self.active_accelerate_handle, -1)
// elseif event.Name == "OnDamageBegin" then
// local collision = self.owner["TailCollision"]
// collision:SetCollisionEnabled(1)
// self.overlap_delegate_handle = collision.OnComponentBeginOverlap:Add(function()
// if not self.asc:HasMatchingGameplayTag(self.recast_tag) then
// local _, recast_effect = self:GetAbilityEffectSpecHandle("Recast", self.asc, 1, nil)
// self.active_recast_handle = self.asc:BP_ApplyGameplayEffectSpecToSelf(recast_effect)
// end
// end)
// elseif event.Name == "OnDamageEnd" then
// self.owner["TailCollision"]:SetCollisionEnabled(0)
// if self.overlap_delegate_handle ~= nil then
// self.owner["TailCollision"].OnComponentBeginOverlap:Remove(self.overlap_delegate_handle)
// self.overlap_delegate_handle = nil
// end
// end
// end
// return Class(nil, nil, FoxUltimate)

View File

@ -0,0 +1,32 @@
using UnrealSharp.Attributes;
using UnrealSharp.Engine;
namespace Level.GameSettings;
[UClass]
public class ABusyLevelGameMode : AGameMode
{
[UProperty(PropertyFlags.EditDefaultsOnly)]
public UnrealSharp.TSubclassOf<AActor> GameMapActorClass { get; set; }
protected override void BeginPlay()
{
base.BeginPlay();
if (GameMapActorClass.Valid)
{
SpawnActor(GameMapActorClass);
}
}
}
// -- function LevelGameMode:K2_PostLogin(new_player_controller)
// -- local new_player_state = new_player_controller.PlayerState
// -- local role = new_player_state:CreateRoleRoster(new_player_controller)
// -- local new_pos = FVector()
// -- new_pos.X = 500
// -- new_pos.Y = 500
// -- new_pos.Z = 50
// -- role:K2_SetActorLocation(new_pos, true, nil, false)
// -- new_player_controller:Possess(role)
// -- end

View File

@ -0,0 +1,17 @@
using UnrealSharp.Attributes;
using UnrealSharp.BusyRabbit;
using UnrealSharp.Engine;
namespace Level.GameSettings;
[UClass]
public class ABusyLevelPlayerState : ALevelPlayerState
{
protected override void BeginPlay()
{
base.BeginPlay();
APlayerController pc = UGameplayStatics.GetPlayerController(0);
var role = CreateRoleRoster(pc) as APawn;
pc.Possess(role);
}
}

View File

@ -0,0 +1,54 @@
// local LevelFoxRole = {}
// local Vector2D = require("Utils.Vector2D")
// function LevelFoxRole:ctor()
// end
// function LevelFoxRole:ReceiveBeginPlay()
// self["SpineAnimationComponent"]:SetAnimation(0, "Idle/Front", true)
// self.last_animation = "Idle/Front"
// self["SpineBoneFollower"].Target = self
// self["SpineBoneFollower"].BoneName = "tail"
// self["SpineBoneFollower"].UseComponentTransform = true
// self["SpineBoneFollower"].UseScale = true
// self["TailCollision"]:SetCollisionEnabled(0)
// end
// 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
// self["SpineAnimationComponent"]:SetTimeScale(1.0)
// end
// function LevelFoxRole:OnMove(location)
// -- 控制器移动相应函数
// self["MovementComponent"]:MoveTo(location)
// end
// return Class(nil, nil, LevelFoxRole)

View File

@ -0,0 +1,36 @@
// local LevelRabbitRole = {}
// function LevelRabbitRole:ctor()
// self.last_animation = "back/move"
// end
// function LevelRabbitRole:ReceiveBeginPlay()
// self["SpineAnimationComponent"]:SetSkin("back/move")
// self["SpineAnimationComponent"]:SetAnimation(0, "animation", true)
// end
// function LevelRabbitRole:OnMove(location)
// -- 控制器移动相应函数
// self["MovementComponent"]:MoveTo(location)
// end
// function LevelRabbitRole:OnMoveDirectionChanged(InDirection)
// -- 运动组件更新方向响应函数
// local cur_animation
// if(InDirection.Y >= 0) then
// cur_animation = "front/move"
// else
// cur_animation = "back/move"
// end
// print("LevelRabbitRole:OnMoveDirectionChanged", cur_animation)
// if cur_animation ~= self.last_animation then
// self["SpineAnimationComponent"]:SetSkin(cur_animation)
// self["SpineAnimationComponent"]:SetSlotsToSetupPose()
// self.last_animation = cur_animation
// end
// end
// return Class(nil, nil, LevelRabbitRole)