| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
- //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
- #include "BsEditorScriptLibrary.h"
- #include "BsEditorScriptManager.h"
- #include "BsEditorApplication.h"
- #include "BsScriptObjectManager.h"
- #include "FileSystem/BsFileSystem.h"
- #include "BsMonoManager.h"
- #include "Serialization/BsScriptAssemblyManager.h"
- #include "BsMonoAssembly.h"
- #include "Scene/BsGameObjectManager.h"
- #include "Generated/BsEditorBuiltinReflectableTypesLookup.generated.h"
- namespace bs
- {
- EditorScriptLibrary::EditorScriptLibrary()
- :mScriptAssembliesLoaded(false)
- { }
- void EditorScriptLibrary::initialize()
- {
- EngineScriptLibrary::initialize();
- mEditorTypeMappings.reflectableObjects = EditorBuiltinReflectableTypes::getEntries();
- MonoManager::instance().loadAssembly(getEditorAssemblyPath(), EDITOR_ASSEMBLY);
- ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY, mEditorTypeMappings);
- EditorScriptManager::startUp();
-
- mQuitRequestedEvent = gEditorApplication().onQuitRequested.connect([]()
- {
- EditorScriptManager::instance().quitRequested();
- });
- }
- void EditorScriptLibrary::update()
- {
- EngineScriptLibrary::update();
- EditorScriptManager::instance().update();
- }
- void EditorScriptLibrary::reload()
- {
- Path engineAssemblyPath = getEngineAssemblyPath();
- Path gameAssemblyPath = getGameAssemblyPath();
- Path editorAssemblyPath = getEditorAssemblyPath();
- Path editorScriptAssemblyPath = getEditorScriptAssemblyPath();
- #if BS_DEBUG_MODE
- mScriptAssembliesLoaded = true; // Force assembly refresh as an ad hoc unit test in debug mode
- #endif
- // Do a full refresh if we have already loaded script assemblies
- if (mScriptAssembliesLoaded)
- {
- Vector<AssemblyRefreshInfo> assemblies;
- assemblies.push_back(AssemblyRefreshInfo(ENGINE_ASSEMBLY, &engineAssemblyPath, &mEngineTypeMappings));
- if (gEditorApplication().isProjectLoaded())
- {
- if (FileSystem::exists(gameAssemblyPath))
- assemblies.push_back(AssemblyRefreshInfo(SCRIPT_GAME_ASSEMBLY, &gameAssemblyPath, &BuiltinTypeMappings::EMPTY));
- }
- assemblies.push_back(AssemblyRefreshInfo(EDITOR_ASSEMBLY, &editorAssemblyPath, &mEditorTypeMappings));
- if (gEditorApplication().isProjectLoaded())
- {
- if (FileSystem::exists(editorScriptAssemblyPath))
- assemblies.push_back(AssemblyRefreshInfo(SCRIPT_EDITOR_ASSEMBLY, &editorScriptAssemblyPath, &BuiltinTypeMappings::EMPTY));
- }
- ScriptObjectManager::instance().refreshAssemblies(assemblies);
- }
- else // Otherwise just additively load them
- {
- ScriptAssemblyManager::instance().clearAssemblyInfo();
- MonoManager::instance().loadAssembly(engineAssemblyPath.toString(), ENGINE_ASSEMBLY);
- ScriptAssemblyManager::instance().loadAssemblyInfo(ENGINE_ASSEMBLY, mEngineTypeMappings);
- if (FileSystem::exists(gameAssemblyPath))
- {
- MonoManager::instance().loadAssembly(gameAssemblyPath.toString(), SCRIPT_GAME_ASSEMBLY);
- ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_GAME_ASSEMBLY, BuiltinTypeMappings());
- }
- MonoManager::instance().loadAssembly(editorAssemblyPath.toString(), EDITOR_ASSEMBLY);
- ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY, mEditorTypeMappings);
- if (FileSystem::exists(editorScriptAssemblyPath))
- {
- MonoManager::instance().loadAssembly(editorScriptAssemblyPath.toString(), SCRIPT_EDITOR_ASSEMBLY);
- ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_EDITOR_ASSEMBLY, BuiltinTypeMappings());
- }
- mScriptAssembliesLoaded = true;
- }
- }
- void EditorScriptLibrary::destroy()
- {
- mQuitRequestedEvent.disconnect();
- GameObjectManager::instance().destroyQueuedObjects();
- unloadAssemblies();
- EditorScriptManager::shutDown();
- shutdownModules();
- }
- Path EditorScriptLibrary::getEditorAssemblyPath() const
- {
- Path assemblyPath = getBuiltinAssemblyFolder();
- assemblyPath.append(String(EDITOR_ASSEMBLY) + ".dll");
- return assemblyPath;
- }
- Path EditorScriptLibrary::getEditorScriptAssemblyPath() const
- {
- Path assemblyPath = getScriptAssemblyFolder();
- assemblyPath.append(String(SCRIPT_EDITOR_ASSEMBLY) + ".dll");
- return assemblyPath;
- }
- Path EditorScriptLibrary::getScriptAssemblyFolder() const
- {
- if (!gEditorApplication().isProjectLoaded())
- return Path::BLANK;
- Path assemblyFolder = gEditorApplication().getProjectPath();
- assemblyFolder.append(INTERNAL_ASSEMBLY_PATH);
- return assemblyFolder;
- }
- }
|