MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnAssemblyLoaded

Method OnAssemblyLoaded

Source/Engine/Scripting/Plugins/PluginManager.cpp:187–248  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void PluginManagerImpl::OnAssemblyLoaded(MAssembly* assembly)
188{
189 PROFILE_CPU_NAMED("Load Assembly Plugins");
190 PROFILE_MEM(Scripting);
191
192 const auto gamePluginClass = GamePlugin::GetStaticClass();
193 if (gamePluginClass == nullptr)
194 {
195 LOG(Warning, "Missing GamePlugin class.");
196 return;
197 }
198#if USE_EDITOR
199 const auto editorPluginClass = ((ManagedBinaryModule*)GetBinaryModuleFlaxEngine())->Assembly->GetClass("FlaxEditor.EditorPlugin");
200 if (editorPluginClass == nullptr)
201 {
202 LOG(Warning, "Missing EditorPlugin class.");
203 return;
204 }
205#endif
206
207 // Process all classes to find plugins
208 bool loadedAnyPlugin = false;
209 auto& classes = assembly->GetClasses();
210 for (auto i = classes.Begin(); i.IsNotEnd(); ++i)
211 {
212 auto mclass = i->Value;
213
214 // Skip invalid classes
215 if (mclass->IsGeneric() || mclass->IsStatic() || mclass->IsAbstract())
216 continue;
217
218 if (mclass->IsSubClassOf(gamePluginClass)
219#if USE_EDITOR
220 || mclass->IsSubClassOf(editorPluginClass)
221#endif
222 )
223 {
224 auto plugin = (Plugin*)Scripting::NewObject(mclass);
225 if (plugin)
226 {
227#if USE_EDITOR
228 if (mclass->IsSubClassOf(editorPluginClass))
229 {
230 EditorPlugins.Add(plugin);
231 }
232 else
233#endif
234 {
235 GamePlugins.Add((GamePlugin*)plugin);
236 }
237 loadedAnyPlugin = true;
238 }
239 }
240 }
241
242 // Send event and initialize newly added plugins (ignore during startup)
243 if (loadedAnyPlugin && Initialized)
244 {

Callers

nothing calls this directly

Calls 7

NewObjectFunction · 0.85
IsStaticMethod · 0.80
GetClassMethod · 0.45
BeginMethod · 0.45
IsNotEndMethod · 0.45
IsSubClassOfMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected