UnLua mejorar el historial

LUA conectado a una pluralidad de máquinas de estado de problema de proceso de nuevo no se pueden resolver máquina de estado temporalmente irreal correspondiente a una pluralidad de máquinas de estado de problema individual LUA, por lo que la primera retención, gire para ver diseño UnLua, mejorar su proceso de grabación en el presente documento.

UnLua que tiene una característica muy conveniente es la interfaz del editor de proyecto se puede generar directamente plantillas de código LUA, comenzó a pensar que se genera a partir de la reflexión, miró debajo descubierto que, de hecho, está copiada de la incorporada en el archivo LUA,
muy flexible, su base de el actor, UserWidget varios tipos comunes tales como, pero no soporta exactamente para algunos de sus propios proyectos en C ++ clases reflexión, sólo para ir mecánicamente la replicación Actor matriz o tabla UserWidget LUA.

El cambio es simple, de acuerdo con la descripción de una vuelta UClass relaciona directamente iteración UClass get UFunction sus parámetros. Código es el siguiente:

// Tencent is pleased to support the open source community by making UnLua available.
// 
// Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
//
// Licensed under the MIT License (the "License"); 
// you may not use this file except in compliance with the License. You may obtain a copy of the License at
//
// http://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, 
// software distributed under the License is distributed on an "AS IS" BASIS, 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
// See the License for the specific language governing permissions and limitations under the License.

#include "UnLuaPrivate.h"
#include "Misc/FileHelper.h"
#include "Engine/Blueprint.h"
#include "Blueprint/UserWidget.h"
#include "Animation/AnimInstance.h"
#include "GameFramework/Actor.h"
#include "Interfaces/IPluginManager.h"
#include "PlatformFilemanager.h"

bool CreateLuaTemplateFileEx(UBlueprint* Blueprint);

// create Lua template file for the selected blueprint
bool CreateLuaTemplateFile(UBlueprint *Blueprint)
{
    return CreateLuaTemplateFileEx(Blueprint);

    if (Blueprint)
    {
        UClass *Class = Blueprint->GeneratedClass;
        FString ClassName = Class->GetName();
        FString OuterPath = Class->GetPathName();
        int32 LastIndex;
        if (OuterPath.FindLastChar('/', LastIndex))
        {
            OuterPath = OuterPath.Left(LastIndex + 1);
        }
        OuterPath = OuterPath.RightChop(6);         // ignore "/Game/"
        FString FileName = FString::Printf(TEXT("%s%s%s.lua"), *GLuaSrcFullPath, *OuterPath, *ClassName);
        if (FPaths::FileExists(FileName))
        {
            UE_LOG(LogUnLua, Warning, TEXT("Lua file (%s) is already existed!"), *ClassName);
            return false;
        }

        static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("UnLua"))->GetContentDir();

        FString TemplateName;
        if (Class->IsChildOf(AActor::StaticClass()))
        {
            // default BlueprintEvents for Actor
            TemplateName = ContentDir + TEXT("/ActorTemplate.lua");
        }
        else if (Class->IsChildOf(UUserWidget::StaticClass()))
        {
            // default BlueprintEvents for UserWidget (UMG)
            TemplateName = ContentDir + TEXT("/UserWidgetTemplate.lua");
        }
        else if (Class->IsChildOf(UAnimInstance::StaticClass()))
        {
            // default BlueprintEvents for AnimInstance (animation blueprint)
            TemplateName = ContentDir + TEXT("/AnimInstanceTemplate.lua");
        }
        else if (Class->IsChildOf(UActorComponent::StaticClass()))
        {
            // default BlueprintEvents for ActorComponent
            TemplateName = ContentDir + TEXT("/ActorComponentTemplate.lua");
        }

        FString Content;
        FFileHelper::LoadFileToString(Content, *TemplateName);
        Content = Content.Replace(TEXT("TemplateName"), *ClassName);

        return FFileHelper::SaveStringToFile(Content, *FileName);
    }
    return false;
}


// create Lua template file for the selected blueprint
bool CreateLuaTemplateFileEx(UBlueprint* Blueprint)
{
	if (Blueprint)
	{
		UClass* Class = Blueprint->GeneratedClass;
		FString ClassName = Class->GetName();
		FString OuterPath = Class->GetPathName();
		int32 LastIndex;
		if (OuterPath.FindLastChar('/', LastIndex))
		{
			OuterPath = OuterPath.Left(LastIndex + 1);
		}
		OuterPath = OuterPath.RightChop(6);         // ignore "/Game/"
		FString FileName = FString::Printf(TEXT("%s%s%s.lua"), *GLuaSrcFullPath, *OuterPath, *ClassName);
		if (FPlatformFileManager::Get().GetPlatformFile().FileSize(*FileName) > 1)
		{
			UE_LOG(LogUnLua, Warning, TEXT("Lua file (%s) is already existed!"), *ClassName);
			return false;
		}

		static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("UnLua"))->GetContentDir();
		FString Content;
        FString HeaderStr = FString::Printf(TEXT("\r\nrequire('UnLua')\r\nlocal %s = Class()\r\n"), *ClassName);
        Content += HeaderStr;
        for (TFieldIterator<UFunction> Func(Class); Func; ++Func)
        {
            if (!Func->HasAnyFunctionFlags(FUNC_BlueprintEvent))
            {
                continue;
            }

            FString ReturnType = FString("void");
            if (Func->GetReturnProperty())
            {
                ReturnType = Func->GetReturnProperty()->GetCPPType();
            }
            FString FuncName = Func->GetName();
            FString ParamTypeList;
            FString ParamList;
#if ENGINE_MINOR_VERSION < 25
            for (TFieldIterator<UProperty> Prop(*Func); Prop; ++Prop)
#else
            for (TFieldIterator<FProperty> Prop(*Func); Prop; ++Prop)
#endif
            {
                if (!Prop->HasAnyPropertyFlags(CPF_OutParm))
                {
                    if (ParamList.Len() > 0)
                    {
                        ParamList = ParamList + FString(", ") + Prop->GetName();
                        ParamTypeList = ParamTypeList + FString(", ") + Prop->GetCPPType();
                    }
                    else
                    {
                        ParamList = ParamList + Prop->GetName();
                        ParamTypeList = ParamTypeList + Prop->GetCPPType();
                    }
                }
            }

            FString FuncStr = FString::Printf(TEXT("--%s(%s)\r\n--function %s:%s(%s)\r\n--end"),*ReturnType, *ParamTypeList, *ClassName, *FuncName, *ParamList);
            Content = Content + FString("\r\n") + FuncStr + FString("\r\n");
        }

        FString EndStr = FString::Printf(TEXT("\r\nreturn %s"), *ClassName);
        Content = Content + EndStr;

		return FFileHelper::SaveStringToFile(Content, *FileName);
	}
	return false;
}

puntos de repaso:
1. Añadir la bool CreateLuaTemplateFileEx (UBlueprint * Blueprint) archivo de función LUA generación automática, en lugar de fijar varios plantilla reproducción mecánica
2. Cuando juzgó que el archivo de destino ya existe, el tamaño del archivo se determina en cambio, VSCode convenientemente vaciado archivos de texto y reconstruir LUA
3 sólo es compatible con los marcadores de la función BlueprintEvent, incluyendo BlueprintImplementation / BlueprintNativeEvent
función 4. LUA para generar la función correspondiente firma c ++, y la función devuelve un tipo de parámetros de valor vistazo

Los resultados son los siguientes:



require('UnLua')
local BP_LuaCharacter_C = Class()

--void(float)
--function BP_LuaCharacter_C:OnWalkingOffLedge(TimeDelta)
--end

--void(FVector, bool, bool)
--function BP_LuaCharacter_C:OnLaunched(LaunchVelocity, bXYOverride, bZOverride)
--end

--void()
--function BP_LuaCharacter_C:OnLanded()
--end

--void()
--function BP_LuaCharacter_C:OnJumped()
--end

--void(float)
--function BP_LuaCharacter_C:K2_UpdateCustomMovement(DeltaTime)
--end

--void(float, float)
--function BP_LuaCharacter_C:K2_OnStartCrouch(HalfHeightAdjust, ScaledHalfHeightAdjust)
--end

--void(TEnumAsByte<EMovementMode>, TEnumAsByte<EMovementMode>, uint8, uint8)
--function BP_LuaCharacter_C:K2_OnMovementModeChanged(PrevMovementMode, NewMovementMode, PrevCustomMode, NewCustomMode)
--end

--void(float, float)
--function BP_LuaCharacter_C:K2_OnEndCrouch(HalfHeightAdjust, ScaledHalfHeightAdjust)
--end

--bool()
--function BP_LuaCharacter_C:CanJumpInternal()
--end

--void(AController*)
--function BP_LuaCharacter_C:ReceiveUnpossessed(OldController)
--end

--void(AController*)
--function BP_LuaCharacter_C:ReceivePossessed(NewController)
--end

--void()
--function BP_LuaCharacter_C:UserConstructionScript()
--end

--void(float)
--function BP_LuaCharacter_C:ReceiveTick(DeltaSeconds)
--end

--void(float, UDamageType*, FVector, AController*, AActor*)
--function BP_LuaCharacter_C:ReceiveRadialDamage(DamageReceived, DamageType, Origin, InstigatedBy, DamageCauser)
--end

--void(float, UDamageType*, FVector, FVector, UPrimitiveComponent*, FName, FVector, AController*, AActor*)
--function BP_LuaCharacter_C:ReceivePointDamage(Damage, DamageType, HitLocation, HitNormal, HitComponent, BoneName, ShotFromDirection, InstigatedBy, DamageCauser)
--end

--void(UPrimitiveComponent*, AActor*, UPrimitiveComponent*, bool, FVector, FVector, FVector)
--function BP_LuaCharacter_C:ReceiveHit(MyComp, Other, OtherComp, bSelfMoved, HitLocation, HitNormal, NormalImpulse)
--end

--void(TEnumAsByte<EEndPlayReason::Type>)
--function BP_LuaCharacter_C:ReceiveEndPlay(EndPlayReason)
--end

--void()
--function BP_LuaCharacter_C:ReceiveDestroyed()
--end

--void()
--function BP_LuaCharacter_C:ReceiveBeginPlay()
--end

--void(float, UDamageType*, AController*, AActor*)
--function BP_LuaCharacter_C:ReceiveAnyDamage(Damage, DamageType, InstigatedBy, DamageCauser)
--end

--void(FKey)
--function BP_LuaCharacter_C:ReceiveActorOnReleased(ButtonReleased)
--end

--void(TEnumAsByte<ETouchIndex::Type>)
--function BP_LuaCharacter_C:ReceiveActorOnInputTouchLeave(FingerIndex)
--end

--void(TEnumAsByte<ETouchIndex::Type>)
--function BP_LuaCharacter_C:ReceiveActorOnInputTouchEnter(FingerIndex)
--end

--void(TEnumAsByte<ETouchIndex::Type>)
--function BP_LuaCharacter_C:ReceiveActorOnInputTouchEnd(FingerIndex)
--end

--void(TEnumAsByte<ETouchIndex::Type>)
--function BP_LuaCharacter_C:ReceiveActorOnInputTouchBegin(FingerIndex)
--end

--void(FKey)
--function BP_LuaCharacter_C:ReceiveActorOnClicked(ButtonPressed)
--end

--void(AActor*)
--function BP_LuaCharacter_C:ReceiveActorEndOverlap(OtherActor)
--end

--void()
--function BP_LuaCharacter_C:ReceiveActorEndCursorOver()
--end

--void(AActor*)
--function BP_LuaCharacter_C:ReceiveActorBeginOverlap(OtherActor)
--end

--void()
--function BP_LuaCharacter_C:ReceiveActorBeginCursorOver()
--end

--void()
--function BP_LuaCharacter_C:K2_OnReset()
--end

--void(APlayerController*)
--function BP_LuaCharacter_C:K2_OnEndViewTarget(PC)
--end

--void(APlayerController*)
--function BP_LuaCharacter_C:K2_OnBecomeViewTarget(PC)
--end

--void(int32)
--function BP_LuaCharacter_C:ExecuteUbergraph(EntryPoint)
--end

return BP_LuaCharacter_C

Supongo que te gusta

Origin www.cnblogs.com/rpg3d/p/12666131.html
Recomendado
Clasificación