From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/BaseClasses/CleanupManager.cpp | 65 ++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Runtime/BaseClasses/CleanupManager.cpp (limited to 'Runtime/BaseClasses/CleanupManager.cpp') diff --git a/Runtime/BaseClasses/CleanupManager.cpp b/Runtime/BaseClasses/CleanupManager.cpp new file mode 100644 index 0000000..7adb1e7 --- /dev/null +++ b/Runtime/BaseClasses/CleanupManager.cpp @@ -0,0 +1,65 @@ +#include "UnityPrefix.h" +#if UNITY_EDITOR +#include "CleanupManager.h" +#include "Runtime/Misc/GameObjectUtility.h" +#include "Runtime/Graphics/Transform.h" +#include + +using namespace std; + +void CleanupManager::MarkForDeletion( PPtr comp, std::string const& reason ) +{ + // Ignore component that is already marked for deletion + list::iterator a = std::find(m_markedComponents.begin(), m_markedComponents.end(), static_cast(comp)); + if (a != m_markedComponents.end()) + return; + + struct MarkedComponent marker; + m_markedComponents.push_back (marker); + m_markedComponents.back ().component = comp; + m_markedComponents.back ().reason = reason; +} + +void CleanupManager::Flush() +{ + while (m_markedComponents.size() > 0) + { + struct MarkedComponent& marked_component = m_markedComponents.front (); + PPtr comp = marked_component.component; + + Unity::Component* compPtr = comp; + if (compPtr) + { + LogString(Format("%s component deleted: %s", comp->GetClassName ().c_str (), marked_component.reason.c_str())); + if (marked_component.component->GetGameObjectPtr () != NULL) + { + DestroyObjectHighLevel (comp); + } + else + { + // if the component is a transform remove the references + if (comp->GetClassID () == ClassID(Transform)) + { + DestroyTransformComponentAndChildHierarchy(static_cast(*comp)); + } + + DestroySingleObject (comp); + } + } + + m_markedComponents.pop_front (); + } +} + +static CleanupManager* singleton = NULL; +CleanupManager& GetCleanupManager () +{ + if (singleton == NULL) + { + singleton = new CleanupManager(); + } + + return *singleton; +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0