本文將介紹自定義slate控制項的方法、向控制項傳遞引數的方法,以及sbutton事件響應背後的原理。
使用類嚮導新增乙個scompoundwidget型別的控制項,命名為「scustomwidget」,新增如下**:
scustomwidget.h:
#pragma once
#include
"coreminimal.h"
#include
"widgets/scompoundwidget.h"
#include
"declarativesyntaxsupport.h"
// 宣告乙個委託
declare_delegate_oneparam
(fonbuttondown, fstring)
class
helloslate_api scustomwidget :
public scompoundwidget
// 將要傳遞的引數放到反射系統,這樣就可以在snew之後為該變數賦值
slate_event
(fonbuttondown, onbuttondown)
slate_argument
(fstring, message)
slate_end_args()
/** constructs this widget with inargs */
void
construct
(const farguments& inargs)
;// 重寫onmousebuttondown函式,在這裡執行委託
virtual freply onmousebuttondown
(const fgeometry& mygeometry,
const fpointerevent& mouseevent) override;
// 宣告要傳遞的引數
fonbuttondown onbuttondown;
fstring message;
};
scustomwidget.cpp:
#include
"scustomwidget.h"
#include
"slateoptmacros.h"
begin_slate_function_build_optimization
void scustomwidget::
construct
(const farguments& inargs)
freply scustomwidget::
onmousebuttondown
(const fgeometry& mygeometry,
const fpointerevent& mouseevent)
end_slate_function_build_optimization
在sstandardslatewidget中構建該控制項並傳入引數:
sstandardslatewidget.h:
#pragma once
#include
"coreminimal.h"
#include
"widgets/scompoundwidget.h"
#include
"declarativesyntaxsupport.h"
class
helloslate_api sstandardslatewidget :
public scompoundwidget
slate_end_args()
/** constructs this widget with inargs */
void
construct
(const farguments& inargs)
;// 這個是用來繫結到委託上的函式
void
showmessage
(fstring inmessage);}
;
sstandardslatewidget.cpp:
#include
"sstandardslatewidget.h"
#include
"slateoptmacros.h"
#include
"scustomwidget.h"
#include
"messagedialog.h"
begin_slate_function_build_optimization
void sstandardslatewidget::
construct
(const farguments& inargs)
void sstandardslatewidget::
showmessage
(fstring inmessage)
end_slate_function_build_optimization
效果如下:
檢視sbutton的原始碼,可以看到如下:
/** called when the button is clicked */
slate_event
( fonclicked, onclicked )
/** called when the button is pressed */
slate_event
( f******delegate, onpressed )
/** called when the button is released */
slate_event
( f******delegate, onreleased )
slate_event
( f******delegate, onhovered )
slate_event
( f******delegate, onunhovered )
可以看出,slate預置的控制項均是採用這種方式傳遞事件。 UE4 Slate初步探索
slate begin args sxjs scrollbox 這個巨集在sxjs scrollbox類中構造了乙個farguments的結構體。slate style argument slate argument slate event slate attribute,都是給這個結構體增加變數。...
UE4 自定義DLC Pak載入
廢話不說,直接上乾貨 htsharedptr class fpakplatformfile pakplatform class iplatformfile oldplatform load void loadandmountpak const fstring inpath cpp void udlc...
UE4之自定義引擎類
可參考 新建umyengine類繼承自ugameengine class umyengine public ugameengine 在配置檔案defaultengine.ini中將引擎類修改為新的類 script engine.engine gameengine script mymodulenam...