Unreal Custom Slate Style Sets

Source: Internet
Author: User

The most valuable piece of teaching that has been collected has encountered some problems in the way that the author tries. " thank the author! " 】

Website: https://wiki.unrealengine.com/Slate_Style_Sets_Part_2

Here, I will elaborate on my production process. This article original, reproduced please specify the source, offenders must investigate!

First create the Xxstyle, and I'll name the test here.

1 #pragmaOnce2#include"SlateStyle.h"3 4 classTeststyles5 {6  Public:7     Static voidInitialize ();8 9     Static voidShutdown ();Ten      One     Static Const classislatestyle&Get (); A  -     StaticFName getstylesetname (); -  the Private: -  -     Statictsharedref<classFslatestyleset>Create (); -  +     Statictsharedptr<classFslatestyleset>Instance; -};

This class is created by itself, without the Unrealeditor wizard. (You can also use the wizard, of course)

1#include"Test05.h"2#include"TestStyles.h"3#include"SlateGameResources.h"4 5 6Tsharedptr<fslatestyleset> teststyles::instance =nullptr;7 8 9 voidteststyles::initialize ()Ten { One     if(!instance.isvalid ()) A     { -Instance =Create (); -  theFslatestyleregistry::registerslatestyle (*Instance); -     } - } -  + voidTeststyles::shutdown () - { +Fslatestyleregistry::unregisterslatestyle (*Instance); A ensure (Instance.isunique ()); at Instance.reset (); - } -  - Const classislatestyle&Teststyles::get () - { -     return*Instance; in } -  to FName teststyles::getstylesetname () + { -     StaticFName Stylesetname (TEXT ("Teststyles")); the     returnStylesetname; * } $ Panax Notoginsengtsharedref<classFslatestyleset>teststyles::create () - { the     returnFslategameresources::new (Teststyles::getstylesetname (),"/game/ui","/game/ui"); +}

Note here: The relative location of the fslategameresources resource path. /game replaced the/context, the resources stored in the/context directory, unified in the address path renamed to/game.

this path is important! when encountering an error, be sure to return to the path and see if you can find the style resource.

Here, I did not create gamemodule in the way the author of the page. (In fact, I tried, but I failed, for the moment I don't want to spend time here, so change the way.) I put it in a custom gamemode).

I think it's not a problem if we can rationalize the initialization of teststyles, but I don't have to worry about the timing of the creation, of course.

1 Amygamemode::amygamemode () 2 {       3This    ->hudclass = amyhud::staticclass ();       4    Fslatestyleregistry::unregisterslatestyle (Teststyles::getstylesetname ()); // refer to the author of the Web page. Register only for anti-duplication.        5    teststyles::initialize (); 6 }

The following class, generated by the Unrealeditor Wizard, operates as follows:

Create a New class under the class directory.

1 #pragmaOnce2 3 4#include"styling/slatewidgetstyle.h"5#include"SlateWidgetStyleContainerBase.h"6 7#include"globaltestwidgetstyle.generated.h"8 9 /**Ten  *  One  */ A ustruct () - structTest05_api Fglobalteststyle: PublicFslatewidgetstyle - { the generated_ustruct_body () -  Public: -  - Fglobalteststyle (); +     Virtual~Fglobalteststyle (); -  +     //Fslatewidgetstyle A     Virtual voidGetresources (tarray<Constfslatebrush*>& outbrushes)Const Override; at     Static ConstFName TypeName; -     Virtual ConstFName Gettypename ()Const Override{returnTypeName;}; -     Static Constfglobalteststyle&Getdefault (); -  -Uproperty (editanywhere, Category =appearance) - Ftextblockstyle Textblockstyle; in }; -  to /** +  */ -Uclass (hidecategories=Object, Minimalapi) the classUglobaltestwidgetstyle: PublicUslatewidgetstylecontainerbase * { $ generated_body ()Panax Notoginseng  -  Public: the     /** The actual data describing the widget appearance.*/ +Uproperty (Category=appearance, Editanywhere, meta=(showonlyinnerproperties)) A Fglobalteststyle Widgetstyle; the  +     Virtual Const structfslatewidgetstyle*ConstGetStyle ()Const Override -     { $         returnstatic_cast<Const structfslatewidgetstyle* > (&widgetstyle); $     } - };
1#include"Test05.h"2#include"GlobalTestWidgetStyle.h"3 4 5 Fglobalteststyle::fglobalteststyle ()6 {7 8 }9 Tenfglobalteststyle::~Fglobalteststyle () One { A } -  - ConstFName Fglobalteststyle::typename (TEXT ("Fglobalteststyle")); the  - Constfglobalteststyle&Fglobalteststyle::getdefault () - { -     StaticFglobalteststyle Default; +     returnDefault; - } +  A voidFglobalteststyle::getresources (tarray<Constfslatebrush*>& outbrushes)Const at { -  -}

  

Here is the point, I myself in the author's web page did not understand, finally consulted colleagues after the test to find the right way.

Create a Style in the content directory. This address must be mentioned before the fslategameresources::new (used in the address, I currently use the address of the/game/ui location, (as explained above)/game/ui location should be replaced with/content/ui,

To get a resource, the name is also important, then the corresponding.

Now double-click on the contents of the changes.

This thing will exist because the custom Fslatewidgetstyle defines the

1  Uproperty (editanywhere, Category = appearance)23  

That's exactly what it is.

I modified the font and font size.

To the last step, the instantiation shows that the test code snippet is as follows, which I wrote in

voidAmyhud::beginplay () {//Note that the "TestButtonStyle01" here is the name of the resourceAuto SS = Teststyles::get (). Getwidgetstyle<fglobalteststyle> ("TestButtonStyle01"); TextBlock=snew (Stextblock). TextStyle (&Ss.textblockstyle). Text (Ftext::fromstring ("Hello World!")); Gengine->gameviewport->addviewportwidgetcontent (Snew (sweakwidget).            Possiblynullcontent (Textblock.tosharedref ())); }

All the steps are done. can be displayed. Effect

Where the Brush is required, the above code does not work and requires additional steps. After the test is successful, write another blog post.

Unreal Custom Slate Style Sets

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.