BsEditorScriptLibrary.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. mQuitRequestedEvent = gEditorApplication().onQuitRequested.connect([]()
  22. {
  23. EditorScriptManager::instance().quitRequested();
  24. });
  25. }
  26. void EditorScriptLibrary::update()
  27. {
  28. EditorScriptManager::instance().update();
  29. }
  30. void EditorScriptLibrary::reload()
  31. {
  32. Path engineAssemblyPath = getEngineAssemblyPath();
  33. Path gameAssemblyPath = getGameAssemblyPath();
  34. Path editorAssemblyPath = getEditorAssemblyPath();
  35. Path editorScriptAssemblyPath = getEditorScriptAssemblyPath();
  36. #if BS_DEBUG_MODE
  37. mScriptAssembliesLoaded = true; // Force assembly refresh as an ad hoc unit test in debug mode
  38. #endif
  39. // Do a full refresh if we have already loaded script assemblies
  40. if (mScriptAssembliesLoaded)
  41. {
  42. Vector<std::pair<String, Path>> assemblies;
  43. assemblies.push_back({ ENGINE_ASSEMBLY, engineAssemblyPath });
  44. if (gEditorApplication().isProjectLoaded())
  45. {
  46. if (FileSystem::exists(gameAssemblyPath))
  47. assemblies.push_back({ SCRIPT_GAME_ASSEMBLY, gameAssemblyPath });
  48. }
  49. assemblies.push_back({ EDITOR_ASSEMBLY, editorAssemblyPath });
  50. if (gEditorApplication().isProjectLoaded())
  51. {
  52. if (FileSystem::exists(editorScriptAssemblyPath))
  53. assemblies.push_back({ SCRIPT_EDITOR_ASSEMBLY, editorScriptAssemblyPath });
  54. }
  55. ScriptObjectManager::instance().refreshAssemblies(assemblies);
  56. }
  57. else // Otherwise just additively load them
  58. {
  59. MonoManager::instance().loadAssembly(engineAssemblyPath.toString(), ENGINE_ASSEMBLY);
  60. ScriptAssemblyManager::instance().loadAssemblyInfo(ENGINE_ASSEMBLY);
  61. if (FileSystem::exists(gameAssemblyPath))
  62. {
  63. MonoManager::instance().loadAssembly(gameAssemblyPath.toString(), SCRIPT_GAME_ASSEMBLY);
  64. ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_GAME_ASSEMBLY);
  65. }
  66. MonoManager::instance().loadAssembly(editorAssemblyPath.toString(), EDITOR_ASSEMBLY);
  67. ScriptAssemblyManager::instance().loadAssemblyInfo(EDITOR_ASSEMBLY);
  68. if (FileSystem::exists(editorScriptAssemblyPath))
  69. {
  70. MonoManager::instance().loadAssembly(editorScriptAssemblyPath.toString(), SCRIPT_EDITOR_ASSEMBLY);
  71. ScriptAssemblyManager::instance().loadAssemblyInfo(SCRIPT_EDITOR_ASSEMBLY);
  72. }
  73. mScriptAssembliesLoaded = true;
  74. }
  75. }
  76. void EditorScriptLibrary::destroy()
  77. {
  78. mQuitRequestedEvent.disconnect();
  79. GameObjectManager::instance().destroyQueuedObjects();
  80. unloadAssemblies();
  81. EditorScriptManager::shutDown();
  82. shutdownModules();
  83. }
  84. Path EditorScriptLibrary::getEditorAssemblyPath() const
  85. {
  86. Path assemblyPath = getBuiltinAssemblyFolder();
  87. assemblyPath.append(String(EDITOR_ASSEMBLY) + ".dll");
  88. return assemblyPath;
  89. }
  90. Path EditorScriptLibrary::getEditorScriptAssemblyPath() const
  91. {
  92. Path assemblyPath = getScriptAssemblyFolder();
  93. assemblyPath.append(String(SCRIPT_EDITOR_ASSEMBLY) + ".dll");
  94. return assemblyPath;
  95. }
  96. Path EditorScriptLibrary::getScriptAssemblyFolder() const
  97. {
  98. if (!gEditorApplication().isProjectLoaded())
  99. return Path::BLANK;
  100. Path assemblyFolder = gEditorApplication().getProjectPath();
  101. assemblyFolder.append(INTERNAL_ASSEMBLY_PATH);
  102. return assemblyFolder;
  103. }
  104. }