Skip to content

Commit 272ffa5

Browse files
committed
Update docs to reflect changes to Plugins
1 parent 7c8af3c commit 272ffa5

File tree

3 files changed

+78
-22
lines changed

3 files changed

+78
-22
lines changed

manual/release-notes/1_4/index.md

+7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
1010

1111
We refactored actors' `PostLoad`/`PostSpawn` methods into `Initialize` and changed the script `OnAwake` event to be called during this initialization phase - before any `OnStart`/`OnEnable` logic. This helps to create gameplay systems in a scheme of manager+objects where the manager can use `OnAwake` to initialize properly, and `OnEnable` can be used to register objects to the manager. This change has no performance impact but might be important to address in existing Flax projects.
1212

13+
### Plugins scripting changes
14+
15+
For this update, we've added support for implementing Game Plugins in C++ scripts - previously it was C#-only feature. For this change, both `GamePlugin` and `EditorPlugin` has been slightly modified:
16+
* `Description` getter is read-only and your plugin can fill `_description` field in the constructor to set up plugin info.
17+
* `OnCollectAssets` has been renamed to `GetReferences` and returns the list of Guids with referenced assets.
18+
We've updated docs and code examples to reflect those changes.
19+
1320
### Large Worlds
1421

1522
Adding 64-bit precision to the world coordinates to the Flax was a challenge. Both Engine and Editor have very complex and mature systems with tooling thus we wanted to make this transition seamless and stable. One of the goals was to don't bloat memory by just doubling every floating-point value but instead upgrade world-coordinates-related data to support very large worlds. For instance, 32-bit float gives us enough precision to represent object rotation and scale thus we upgraded only `Translation` (aka `Position`) of the `Transform` to a 64-bit double vector. Also, the UI system, mesh data, textures converter, and other engine features were changed to keep explicitly *Float* vectors for performance reasons.

manual/scripting/advanced/cert-store.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@ public sealed class CertStore : GamePlugin
4040
{
4141
// Reference: https://github.com/mono/mono/blob/main/mcs/tools/security/mozroots.cs
4242
43-
/// <inheritdoc />
44-
public override PluginDescription Description => new PluginDescription
43+
public CertStore()
4544
{
46-
Name = "Cert Store",
47-
Category = "Other",
48-
Description = "Trusted certificates store utility.",
49-
Author = "Flax",
50-
AuthorUrl = "https://flaxengine.com/",
51-
};
45+
// Initialize plugin description
46+
_description = new PluginDescription
47+
{
48+
Name = "Cert Store",
49+
Category = "Other",
50+
Description = "Trusted certificates store utility.",
51+
Author = "Flax",
52+
AuthorUrl = "https://flaxengine.com/",
53+
};
54+
}
5255

5356
/// <inheritdoc />
5457
public override void Initialize()
@@ -119,13 +122,11 @@ public sealed class CertStore : GamePlugin
119122

120123
#if FLAX_EDITOR
121124
/// <inheritdoc />
122-
public override void OnCollectAssets(System.Collections.Generic.List<Guid> assets)
125+
public override Guid[] GetReferences()
123126
{
124-
base.OnCollectAssets(assets);
125-
126127
// Reference cached certificates asset
127128
var asset = InitAsset();
128-
assets.Add(asset.ID);
129+
return new Guid[1] { asset.ID };
129130
}
130131
#endif
131132

manual/scripting/plugins/index.md

+58-10
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,21 @@ There are two types of plugins:
6060

6161
**Game Plugins** are type of plugin that can be used at runtime. Game plugins are deployed with the game and can extend the engine by adding new features. Plugins can contain custom scripts that can be used in a game. To create a simple game plugin use the following code example:
6262

63+
# [C#](#tab/code-csharp)
6364
```cs
6465
public class MyPlugin : GamePlugin
6566
{
66-
/// <inheritdoc />
67-
public override PluginDescription Description => new PluginDescription
67+
public MyPlugin()
6868
{
69-
Name = "My Plugin",
70-
Category = "Other",
71-
Description = "This is my custom plugin made for Flax.",
72-
Author = "Someone Inc.",
73-
};
69+
// Initialize plugin description
70+
_description = new PluginDescription
71+
{
72+
Name = "My Plugin",
73+
Category = "Other",
74+
Description = "This is my custom plugin made for Flax.",
75+
Author = "Someone Inc.",
76+
};
77+
}
7478

7579
/// <inheritdoc />
7680
public override void Initialize()
@@ -89,6 +93,47 @@ public class MyPlugin : GamePlugin
8993
}
9094
}
9195
```
96+
# [C++](#tab/code-cpp)
97+
```cpp
98+
// .h
99+
#pragma once
100+
101+
#include "Engine/Scripting/Plugins/GamePlugin.h"
102+
103+
API_CLASS() class GAME_API MyPlugin : public GamePlugin
104+
{
105+
DECLARE_SCRIPTING_TYPE(MyPlugin);
106+
107+
void Initialize() override;
108+
void Deinitialize() override;
109+
};
110+
111+
// .cpp
112+
#include "MyPlugin.h"
113+
#include "Engine/Core/Log.h"
114+
115+
MyPlugin::MyPlugin(const SpawnParams& params)
116+
: GamePlugin(params)
117+
{
118+
// Initialize plugin description
119+
_description.Name = TEXT("My Plugin");
120+
_description.Category = TEXT("Other");
121+
_description.Description = TEXT("This is my custom plugin made for Flax.");
122+
_description.Author = TEXT("Someone Inc.");
123+
}
124+
125+
void MyPlugin::Initialize()
126+
{
127+
LOG(Info, "Plugin initialization!");
128+
}
129+
130+
void MyPlugin::Deinitialize()
131+
{
132+
LOG(Info, "Plugin cleanup!");
133+
}
134+
135+
```
136+
***
92137
93138
Your game can also use a Game Plugins within a code to implement various gameplay features because plugins don't rely on loaded scenes or scene objects and are created before the scenes loading (compared to the normal scripts).
94139
@@ -98,14 +143,14 @@ If you need to include custom settings for your plugin see [this tutorial](../tu
98143
99144
### Game Plugin Assets
100145
101-
If you want to bundle custom assets used in code-only plugin (eg. shader or debug model) override `OnCollectAssets` method as follows and provide IDs of the assets to include:
146+
If you want to bundle custom assets used in code-only plugin (eg. shader or debug model) override `GetReferences` method as follows and provide IDs of the assets to include:
102147
103148
```cs
104149
#if FLAX_EDITOR
105150
/// <inheritdoc />
106-
public override void OnCollectAssets(System.Collections.Generic.List<Guid> assets)
151+
public override Guid[] GetReferences()
107152
{
108-
base.OnCollectAssets(assets);
153+
var assets = new System.Collections.Generic.List<Guid>();
109154
110155
// Add asset ID to the list
111156
assets.Add(ShaderId);
@@ -114,6 +159,9 @@ public override void OnCollectAssets(System.Collections.Generic.List<Guid> asset
114159
var path = Path.Combine(Globals.ProjectFolder, "Plugins/MyPlugin/Content/MyCustomDebugModel.flax");
115160
Content.GetAssetInfo(path, out var info);
116161
assets.Add(info.ID);
162+
163+
return assets.ToArray();
164+
}
117165
#endif
118166
```
119167

0 commit comments

Comments
 (0)