string 改为 std::optional<string>
¶
这是C++17的一个新语法,可以让值存在也可以不存在
// These return empty strings if cancelled
static std::optional<std::string> OpenFile(const char* filter);
static std::optional<std::string> SaveFile(const char* filter);
...
return std::nullopt;
组件存在时再添加防止崩溃¶
if (ImGui::MenuItem("Camera"))
{
if (!m_SelectionContext.HasComponent<CameraComponent>())
m_SelectionContext.AddComponent<CameraComponent>();
else
CORE_DEBUG_WARN("This entity already has the Camera Component!");
ImGui::CloseCurrentPopup();
}
if (ImGui::MenuItem("Sprite Renderer"))
{
if (!m_SelectionContext.HasComponent<SpriteRendererComponent>())
m_SelectionContext.AddComponent<SpriteRendererComponent>();
else
CORE_DEBUG_WARN("This entity already has the Sprite Renderer Component!");
ImGui::CloseCurrentPopup();
}