Skip to content

Commit d0396f8

Browse files
committed
重构:模板文件移到Template目录下,并使用统一命名
1 parent 2b4a1c9 commit d0396f8

6 files changed

Lines changed: 40 additions & 20 deletions

File tree

File renamed without changes.
File renamed without changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--
2+
-- DESCRIPTION
3+
--
4+
-- @COMPANY **
5+
-- @AUTHOR **
6+
-- @DATE ${date} ${time}
7+
--
8+
9+
require "UnLua"
10+
11+
---@class ClassName
12+
local M = Class()
13+
14+
-- function M:Received_NotifyBegin(MeshComp, Animation, TotalDuration)
15+
-- end
16+
17+
-- function M:Received_NotifyTick(MeshComp, Animation, FrameDeltaTime)
18+
-- end
19+
20+
-- function M:Received_NotifyEnd(MeshComp, Animation)
21+
-- end
22+
23+
return M
File renamed without changes.

Plugins/UnLua/Source/UnLuaEditor/Private/Toolbars/UnLuaEditorToolbar.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ToolMenus.h"
1919
#include "UnLuaSettings.h"
2020
#include "UnLuaIntelliSense.h"
21+
#include "Animation/AnimNotifies/AnimNotifyState.h"
2122

2223
#define LOCTEXT_NAMESPACE "FUnLuaEditorModule"
2324

@@ -281,31 +282,27 @@ void FUnLuaEditorToolbar::CreateLuaTemplate_Executed()
281282
}
282283

283284
static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("UnLua"))->GetContentDir();
284-
285-
FString TemplateName;
286-
if (Class->IsChildOf(AActor::StaticClass()))
287-
{
288-
// default BlueprintEvents for Actor
289-
TemplateName = ContentDir + TEXT("/ActorTemplate.lua");
290-
}
291-
else if (Class->IsChildOf(UUserWidget::StaticClass()))
292-
{
293-
// default BlueprintEvents for UserWidget (UMG)
294-
TemplateName = ContentDir + TEXT("/UserWidgetTemplate.lua");
295-
}
296-
else if (Class->IsChildOf(UAnimInstance::StaticClass()))
285+
static TArray<UClass*> TemplateClasses =
297286
{
298-
// default BlueprintEvents for AnimInstance (animation blueprint)
299-
TemplateName = ContentDir + TEXT("/AnimInstanceTemplate.lua");
300-
}
301-
else if (Class->IsChildOf(UActorComponent::StaticClass()))
287+
AActor::StaticClass(),
288+
UActorComponent::StaticClass(),
289+
UAnimInstance::StaticClass(),
290+
UAnimNotifyState::StaticClass(),
291+
UUserWidget::StaticClass()
292+
};
293+
294+
FString TemplateFilePath;
295+
for (const auto& TemplateClass : TemplateClasses)
302296
{
303-
// default BlueprintEvents for ActorComponent
304-
TemplateName = ContentDir + TEXT("/ActorComponentTemplate.lua");
297+
if (Class->IsChildOf(TemplateClass))
298+
{
299+
TemplateFilePath = FString::Printf(TEXT("%s/Template/%s.lua"), *ContentDir, *TemplateClass->GetName());
300+
break;
301+
}
305302
}
306303

307304
FString Content;
308-
FFileHelper::LoadFileToString(Content, *TemplateName);
305+
FFileHelper::LoadFileToString(Content, *TemplateFilePath);
309306
Content = Content.Replace(TEXT("TemplateName"), *ClassName)
310307
.Replace(TEXT("ClassName"), *UnLua::IntelliSense::GetTypeName(Class));
311308

0 commit comments

Comments
 (0)