Skip to content

Commit e1d43df

Browse files
author
Roberto De Ioris
authored
Create extenders_example.py
1 parent a899b95 commit e1d43df

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎examples/extenders_example.py‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import unreal_engine as ue
2+
from unreal_engine import FSlateIcon, FSlateStyleSet, FLinearColor
3+
from unreal_engine.structs import SlateBrush, SlateColor, Vector2D
4+
5+
# this code must be in ue_site.py, extenders must be registered during editor startup phase !!!
6+
7+
# we create a new StyleSet to register a new Icon
8+
9+
# create a new styleset
10+
style = FSlateStyleSet('PyStyle')
11+
# allocate a solid color brush (check here https://docs.unrealengine.com/latest/INT/API/Runtime/SlateCore/Styling/FSlateBrush/index.html)
12+
brush = SlateBrush(TintColor=SlateColor(SpecifiedColor=FLinearColor(1, 0, 0, 1)))
13+
# register the brush in the 'PyStyle' StyleSet
14+
style.set('SolidBrush001', brush)
15+
# allocate a brush image (best image size for toolbar is 64x64)
16+
# Note: pass a path to a valid image file
17+
brush2 = SlateBrush(ResourceName='C:/Users/Roberto/Desktop/chessboard.png', ImageSize=Vector2D(X=128, Y=128))
18+
# register the brush
19+
style.set('ImageBrush001', brush2)
20+
# register the new style
21+
style.register()
22+
23+
# this is called whenever you select the SimpleMenuExtension entry
24+
def dumb():
25+
ue.log('HELLO WORLD')
26+
27+
# this generates the menu entries
28+
def open_menu(menu):
29+
menu.begin_section('test1', 'test2')
30+
menu.add_menu_entry('one', 'two', lambda: ue.log('ciao 1'))
31+
menu.add_menu_entry('three', 'four', lambda: ue.log('ciao 2'))
32+
menu.end_section()
33+
34+
# this fills the toolbar
35+
def fill_toolbar(toolbar):
36+
icon1 = FSlateIcon('PyStyle', 'SolidBrush001')
37+
icon2 = FSlateIcon('PyStyle', 'ImageBrush001')
38+
toolbar.add_tool_bar_button('button001', 'Button001', 'Button001 tooltip', icon1, lambda: ue.log('Button001'))
39+
toolbar.add_tool_bar_button('button002', 'Button002', 'Button002 tooltip', icon2, lambda: ue.log('Button002'))
40+
41+
ue.add_menu_extension('SimpleMenuExtension', dumb)
42+
43+
ue.add_menu_bar_extension('SimpleMenuBarExtension', open_menu)
44+
45+
ue.add_tool_bar_extension('SimpleToolBarExtension', fill_toolbar)

0 commit comments

Comments
 (0)