BsEditorScriptLibrary.cpp 2.9 KB

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