BsEditorScriptLibrary.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 = getEngineAssemblyPath();
  25. Path gameAssemblyPath = getGameAssemblyPath();
  26. Path editorAssemblyPath = getEditorAssemblyPath();
  27. Path editorScriptAssemblyPath = 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. Path EditorScriptLibrary::getEditorAssemblyPath() const
  76. {
  77. Path assemblyPath = getBuiltinAssemblyFolder();
  78. assemblyPath.append(String(EDITOR_ASSEMBLY) + ".dll");
  79. return assemblyPath;
  80. }
  81. Path EditorScriptLibrary::getEditorScriptAssemblyPath() const
  82. {
  83. Path assemblyPath = getScriptAssemblyFolder();
  84. assemblyPath.append(String(SCRIPT_EDITOR_ASSEMBLY) + ".dll");
  85. return assemblyPath;
  86. }
  87. Path EditorScriptLibrary::getScriptAssemblyFolder() const
  88. {
  89. if (!gEditorApplication().isProjectLoaded())
  90. return Path::BLANK;
  91. Path assemblyFolder = gEditorApplication().getProjectPath();
  92. assemblyFolder.append(INTERNAL_ASSEMBLY_PATH);
  93. return assemblyFolder;
  94. }
  95. }