BsEditorScriptLibrary.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "BsEditorScriptLibrary.h"
  2. #include "BsEditorScriptManager.h"
  3. #include "BsEditorApplication.h"
  4. #include "BsScriptObjectManager.h"
  5. #include "BsFileSystem.h"
  6. #include "BsMonoManager.h"
  7. #include "BsScriptAssemblyManager.h"
  8. #include "BsMonoAssembly.h"
  9. namespace BansheeEngine
  10. {
  11. EditorScriptLibrary::EditorScriptLibrary()
  12. :mScriptAssembliesLoaded(false)
  13. { }
  14. void EditorScriptLibrary::initialize()
  15. {
  16. EngineScriptLibrary::initialize();
  17. EditorScriptManager::startUp();
  18. }
  19. void EditorScriptLibrary::reload()
  20. {
  21. Path engineAssemblyPath = gApplication().getEngineAssemblyPath();
  22. Path gameAssemblyPath = gApplication().getGameAssemblyPath();
  23. Path editorAssemblyPath = gEditorApplication().getEditorAssemblyPath();
  24. Path editorScriptAssemblyPath = gEditorApplication().getEditorScriptAssemblyPath();
  25. #if BS_DEBUG_MODE
  26. mScriptAssembliesLoaded = true; // Force assembly refresh as an ad hoc unit test in debug mode
  27. #endif
  28. // Do a full refresh if we have already loaded script assemblies
  29. if (mScriptAssembliesLoaded)
  30. {
  31. Vector<std::pair<String, Path>> assemblies;
  32. assemblies.push_back({ ENGINE_ASSEMBLY, engineAssemblyPath });
  33. if (gEditorApplication().isProjectLoaded())
  34. {
  35. if (FileSystem::exists(gameAssemblyPath))
  36. assemblies.push_back({ SCRIPT_GAME_ASSEMBLY, gameAssemblyPath });
  37. }
  38. assemblies.push_back({ EDITOR_ASSEMBLY, editorAssemblyPath });
  39. if (gEditorApplication().isProjectLoaded())
  40. {
  41. if (FileSystem::exists(editorScriptAssemblyPath))
  42. assemblies.push_back({ SCRIPT_EDITOR_ASSEMBLY, editorScriptAssemblyPath });
  43. }
  44. ScriptObjectManager::instance().refreshAssemblies(assemblies);
  45. }
  46. else // Otherwise just additively load them
  47. {
  48. MonoManager::instance().loadAssembly(engineAssemblyPath.toString(), ENGINE_ASSEMBLY);
  49. ScriptAssemblyManager::instance().loadAssemblyInfo(ENGINE_ASSEMBLY);
  50. if (FileSystem::exists(gameAssemblyPath))
  51. {
  52. MonoManager::instance().loadAssembly(gameAssemblyPath.toString(), SCRIPT_GAME_ASSEMBLY);
  53. ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_GAME_ASSEMBLY);
  54. }
  55. MonoManager::instance().loadAssembly(editorAssemblyPath.toString(), EDITOR_ASSEMBLY);
  56. ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY);
  57. if (FileSystem::exists(editorScriptAssemblyPath))
  58. {
  59. MonoManager::instance().loadAssembly(editorScriptAssemblyPath.toString(), SCRIPT_EDITOR_ASSEMBLY);
  60. ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_EDITOR_ASSEMBLY);
  61. }
  62. mScriptAssembliesLoaded = true;
  63. }
  64. }
  65. void EditorScriptLibrary::destroy()
  66. {
  67. unloadAssemblies();
  68. EditorScriptManager::shutDown();
  69. shutdownModules();
  70. }
  71. }