179 lines
6.9 KiB
Lua
179 lines
6.9 KiB
Lua
|
ParticleConfig = ParticleConfig or {}
|
||
|
ParticleConfig.EParticleType = {
|
||
|
AddBuff = 1;
|
||
|
GodOfWar = 2;
|
||
|
GodOfWarSelf = 3;
|
||
|
Ice = 4;
|
||
|
Explosion = 5;
|
||
|
StarAttach = 6;
|
||
|
}
|
||
|
ParticleConfig.ParticleInfoList = {
|
||
|
[ParticleConfig.EParticleType.AddBuff] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/BuffFx/P_AddBuff2.P_AddBuff2');
|
||
|
Position = { X = 0, Y = 0, Z = -85 };
|
||
|
AttachName = "";
|
||
|
};
|
||
|
[ParticleConfig.EParticleType.GodOfWar] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/GodOfWar/P_GodOfWar.P_GodOfWar');
|
||
|
Position = { X = 0, Y = 0, Z = -85 };
|
||
|
AttachName = "";
|
||
|
Rot = {Roll = 0., Pitch = 0., Yaw = -90};
|
||
|
Scale = 2;
|
||
|
IsFaseToLocalPlayer = true;
|
||
|
IsZeroYaw = true;
|
||
|
};
|
||
|
[ParticleConfig.EParticleType.GodOfWarSelf] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/GodOfWar/P_GodOfWar_Self.P_GodOfWar_Self');
|
||
|
Position = { X = 0, Y = 0, Z = -85 };
|
||
|
AttachName = "";
|
||
|
Scale = 2;
|
||
|
IsZeroYaw = true;
|
||
|
};
|
||
|
[ParticleConfig.EParticleType.Ice] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/GodOfWar/P_Ice.P_Ice');
|
||
|
Position = { X = 0, Y = 0, Z = 110 };
|
||
|
AttachName = "";
|
||
|
Scale = 1.5;
|
||
|
IsZeroYaw = true;
|
||
|
AttachLocation = EAttachLocation.SnapToTarget;
|
||
|
};
|
||
|
-- 爆炸
|
||
|
[ParticleConfig.EParticleType.Explosion] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/BuffFx/P_Explosion.P_Explosion');
|
||
|
Scale = 2;
|
||
|
};
|
||
|
[ParticleConfig.EParticleType.StarAttach] = {
|
||
|
Path = UGCGameSystem.GetUGCResourcesFullPath('Asset/FX/Star/P_StarAttach.P_StarAttach');
|
||
|
Scale = 1;
|
||
|
Position = { X = 0, Y = 0, Z = 110 };
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
ParticleConfig.ParticleInst = {}
|
||
|
|
||
|
ParticleConfig.ClientPlayParticleFuncName = "ClientPlayParticle"
|
||
|
ParticleConfig.AddParticleAttachPlayerFuncName = "ClientFXAttachPlayer"
|
||
|
|
||
|
|
||
|
---@param InAttachActor AActor* 传入进行网络同步的Actor 最好是GameState比较快而且时序上不会出现差错
|
||
|
function ParticleConfig.Init(InAttachActor)
|
||
|
ParticleConfig.AttachActor = InAttachActor
|
||
|
if UGCGameSystem.IsServer() then
|
||
|
else
|
||
|
InAttachActor[ParticleConfig.ClientPlayParticleFuncName] = function(AttachActor, InParticleType, Pos, Rot, Scale)
|
||
|
ParticleConfig.AddParticleFromPosAndRot(InParticleType, Pos, Rot, Scale)
|
||
|
end
|
||
|
InAttachActor[ParticleConfig.AddParticleAttachPlayerFuncName] = function(AttachActor, InPawn, ParticleType)
|
||
|
ParticleConfig.AddParticleAttachPlayer(InPawn, ParticleType)
|
||
|
end
|
||
|
-- 预加载
|
||
|
ParticleConfig.PreLoad()
|
||
|
end
|
||
|
end
|
||
|
|
||
|
---@param Scale float
|
||
|
function ParticleConfig.ClientPlayParticle(InPlayerKey, InParticleType, Pos, Rot, Scale)
|
||
|
if UGCGameSystem.IsServer() then
|
||
|
UGCSendRPCSystem.ActorRPCNotify(InPlayerKey, ParticleConfig.AttachActor, ParticleConfig.ClientPlayParticleFuncName, InParticleType, VectorHelper.ToLuaTable(Pos), VectorHelper.RotToLuaTable(Rot), Scale)
|
||
|
else
|
||
|
ParticleConfig.AddParticleFromPosAndRot(InParticleType, Pos, Rot, Scale)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
--- 用于服务器调用,发送RPC到客户端播放粒子
|
||
|
function ParticleConfig.ClientAddParticleAttachPlayer(InPlayerKey, InPawn, ParticleType)
|
||
|
if UGCGameSystem.IsServer() then
|
||
|
UGCSendRPCSystem.ActorRPCNotify(InPlayerKey, ParticleConfig.AttachActor, ParticleConfig.AddParticleAttachPlayerFuncName, InPawn, ParticleType)
|
||
|
else
|
||
|
ParticleConfig.AddParticleAttachPlayer(InPawn, ParticleType)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function ParticleConfig.PreLoad()
|
||
|
for ParticleType, ParticleInfo in pairs(ParticleConfig.ParticleInfoList) do
|
||
|
UGCSystemLibrary.AsyncLoadAsset(ParticleInfo.Path, nil,
|
||
|
function(Particle)
|
||
|
ParticleConfig.ParticleInst[ParticleType] = Particle
|
||
|
end, true
|
||
|
)
|
||
|
-- ParticleConfig.ParticleInst[ParticleType] = UGCSystemLibrary.LoadAsset(ParticleInfo.Path)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function ParticleConfig.GetParticleInst(InParticleType)
|
||
|
if ParticleConfig.ParticleInst[InParticleType] == nil then
|
||
|
ParticleConfig.ParticleInst[InParticleType] = UGCSystemLibrary.LoadAsset(ParticleConfig.ParticleInfoList[InParticleType].Path)
|
||
|
end
|
||
|
return ParticleConfig.ParticleInst[InParticleType]
|
||
|
end
|
||
|
|
||
|
--- 在玩家网格中心生成粒子
|
||
|
function ParticleConfig.AddParticleAttachPlayer(InPawn, ParticleType)
|
||
|
if UE.IsValid(InPawn) then
|
||
|
local Position = VectorHelper.VectorZero()
|
||
|
local ComposeRotators = VectorHelper.RotZero()
|
||
|
local Rot = InPawn:K2_GetActorRotation()
|
||
|
local Scale = 1
|
||
|
local AttachLocation = EAttachLocation.SnapToTarget
|
||
|
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].Position then
|
||
|
Position = ParticleConfig.ParticleInfoList[ParticleType].Position
|
||
|
end
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].Scale then
|
||
|
Scale = ParticleConfig.ParticleInfoList[ParticleType].Scale
|
||
|
end
|
||
|
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].Rot then
|
||
|
ComposeRotators = ParticleConfig.ParticleInfoList[ParticleType].Rot
|
||
|
end
|
||
|
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].AttachLocation then
|
||
|
AttachLocation = ParticleConfig.ParticleInfoList[ParticleType].AttachLocation
|
||
|
end
|
||
|
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].IsFaseToLocalPlayer then
|
||
|
local CameraManager = UGCSystemLibrary.GetLocalPlayerController().PlayerCameraManager
|
||
|
local CameraPos = CameraManager:K2_GetActorLocation()
|
||
|
Rot = KismetMathLibrary.MakeRotFromX(VectorHelper.Sub(CameraPos, InPawn:K2_GetActorLocation()))
|
||
|
if ParticleConfig.ParticleInfoList[ParticleType].IsZeroYaw then
|
||
|
Rot.Yaw = 0;
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
|
||
|
return GameplayStatics.SpawnEmitterAttached(
|
||
|
ParticleConfig.GetParticleInst(ParticleType),
|
||
|
InPawn.Mesh,
|
||
|
ParticleConfig.ParticleInfoList[ParticleType].AttachName,
|
||
|
Position,
|
||
|
KismetMathLibrary.ComposeRotators(InPawn:K2_GetActorRotation(), ComposeRotators),
|
||
|
{ X = Scale, Y = Scale, Z = Scale },
|
||
|
AttachLocation,
|
||
|
false
|
||
|
)
|
||
|
end
|
||
|
return nil
|
||
|
end
|
||
|
|
||
|
function ParticleConfig.AddParticleFromPosAndRot(InParticleType, Pos, Rot, Scale)
|
||
|
if Rot == nil then
|
||
|
Rot = Rotator.New(0, 0, 0)
|
||
|
end
|
||
|
if Scale == nil then
|
||
|
Scale = 1
|
||
|
end
|
||
|
if ParticleConfig.ParticleInfoList[InParticleType].Scale then
|
||
|
Scale = ParticleConfig.ParticleInfoList[InParticleType].Scale * Scale
|
||
|
end
|
||
|
GameplayStatics.SpawnEmitterAtLocation(UGCGameSystem.GameState, ParticleConfig.GetParticleInst(InParticleType), Pos, Rot, Vector.New(Scale, Scale, Scale), true)
|
||
|
end
|
||
|
|
||
|
function ParticleConfig.DestroyParticle(InParticleInst)
|
||
|
if UE.IsValid(InParticleInst) then
|
||
|
InParticleInst:K2_DestroyComponent()
|
||
|
end
|
||
|
end
|