| 185 | } |
| 186 | |
| 187 | void 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 | { |