• UnLua


    动态创建UMG

    local widget_class =UE.UClass.Load("/Game/MyApp/WBP_MainUI")
    local widget_root = NewObject(widget_class, self)
    widget_root:AddToViewport()

    UMG添加事件

    function WBP_MainUI:Construct()
    
        Screen.Print('-----WBP_MainUI-----');
        self.Btn.OnClicked:Add(self, self.OnButtonClicked)
         self.ClickMeButton.OnClicked:Add(self, self.OnButtonClicked)
          self.ClickMeCheckBox.OnCheckStateChanged:Add(self, self.OnCheckBoxToggled)
    end
    
    function WBP_MainUI:OnButtonClicked()
        Screen.Print('Click...sdfsdfdfd.');
    
    end

    输入事件:

    local function SetupKeyBindings()
        local key_names = {
            -- 字母
            "A", "B", "C", "D", "E","F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
            -- 数字
            "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine",
            -- 小键盘
            "NumPadOne", "NumPadTwo", "NumPadThree", "NumPadFour", "NumPadFive", "NumPadSix", "NumPadSeven", "NumPadEight", "NumPadNine",
            -- 方向键
            "Up", "Down", "Left", "Right",
            -- ProjectSettings -> Engine - Input -> Action Mappings
            "Fire", "Aim",
        }
        
        for _, key_name in ipairs(key_names) do
            M[key_name .. "_Pressed"] = function(self, key)
                Screen.Print(string.format("按下了%s", key.KeyName))
            end
        end
    end
    
    
    local function SetupAxisBindings()
        -- ProjectSettings -> Engine - Input -> Axis Mappings
        local axis_names = {
            "MoveForward", "MoveRight", "Turn", "LookUp", "LookUpRate", "TurnRate"
        }
        for _, axis_name in ipairs(axis_names) do
            M[axis_name] = function(self, value)
                if value ~= 0 then
                    Screen.Print(string.format("%s(%f)", axis_name, value))
                end
            end
        end
    end

    定时事件

    -- 相当于在蓝图中的 Set Timer by Event
        self.TimerHandle = UE.UKismetSystemLibrary.K2_SetTimerDelegate({ self, self.OnTimer }, 1, true)
    
    function M:OnTimer()
        local seconds = UE.UKismetSystemLibrary.GetGameTimeInSeconds(self)
        self.GameTimeTextBlock:SetText(string.format("游戏时长:%d 秒", math.floor(seconds)))
    end
    
    
    function M:Destruct()
        -- 在UMG被销毁时尽量清理已绑定的委托,不清理则会在切换Map时自动清理
        self.ClickMeButton.OnClicked:Remove(self, self.OnButtonClicked)
        self.ClickMeCheckBox.OnCheckStateChanged:Remove(self, self.OnCheckBoxToggled)
    
        -- 相当于在蓝图中的 Clear and Invalidate Timer by Handle
        UE.UKismetSystemLibrary.K2_ClearAndInvalidateTimerHandle(self, self.TimerHandle)
    end

    容器类

    Lua调用C++类

    --本示例C++源码:
    --Source\TPSProject\TutorialBlueprintFunctionLibrary.cpp
    
    Screen.Print(msg)
        UE.UTutorialBlueprintFunctionLibrary.CallLuaByGlobalTable()
        Screen.Print("=================")
        UE.UTutorialBlueprintFunctionLibrary.CallLuaByFLuaTable()
  • 相关阅读:
    2. 获取access_token
    1. 钉钉可以做什么
    3.5 创建模型-关系
    3.5 创建模型 其它
    3.3 创建模型 阴影属性
    3.4 创建模型-并发标记
    Spark运行CDH6.3.2碰到的由于hive驱动引起的问题解决方法
    Spark中碰到需要转义的|分隔符填坑方法
    Spark2 Can't write dataframe to parquet hive table : HiveFileFormat`. It doesn't match the specified format `ParquetFileFormat`.
    Spark连接CDH平台thriftserver和kerberos访问不一致错误排查
  • 原文地址:https://www.cnblogs.com/daidu/p/16184885.html
Copyright © 2020-2023  润新知