BsEditorScriptLibrary.cpp 3.0 KB

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