summaryrefslogtreecommitdiff
path: root/Runtime/Profiler/ExtractLoadedObjectInfo.cpp
blob: aede649782782769cb3ef307b166f5ae335484ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "UnityPrefix.h"
#if ENABLE_PROFILER
#include "ExtractLoadedObjectInfo.h"
#include "Runtime/BaseClasses/GameObject.h"
#include "Runtime/Serialize/PersistentManager.h"
#include "Runtime/Misc/GarbageCollectSharedAssets.h"

LoadedObjectMemoryType GetLoadedObjectReason (Object* object)
{
	bool referencedOnlyByNativeData = false;

	if(!object->GetCachedScriptingObject ())
		referencedOnlyByNativeData = true;

	bool isPersistent = object->IsPersistent();

	// Builtin resource (Treated as root)
	if (isPersistent)
	{
		string path = GetPersistentManager().GetPathName(object->GetInstanceID());
		if (path == "library/unity editor resources" || path == "library/unity default resources")
		{
			return kBuiltinResource;
		}
	}

	// Objects marked DontSave (Treated as root)
	if (object->TestHideFlag(Object::kDontSave))
	{
		return kMarkedDontSave;
	}

	// Asset marked dirty in the editor (Treated as root)
#if UNITY_EDITOR
	if (isPersistent && object->IsPersistentDirty() && ShouldPersistentDirtyObjectBeKeptAlive(object->GetInstanceID()))
	{
		return kAssetMarkedDirtyInEditor;
	}
#endif		

	// gameobjects and components in the scene (treated as roots)
	if (!isPersistent)
	{
		int classID = object->GetClassID();
		if (classID == ClassID (GameObject))
		{
			return kSceneObject;
		}
		else if (Object::IsDerivedFromClassID(classID, ClassID(Component)))	
		{
			Unity::Component* com = static_cast<Unity::Component*> (object);
			if (com->GetGameObjectPtr())
				return kSceneObject;
		}
	}

	// Asset is being referenced from something, specify what
	if (!isPersistent)
	{
		if (referencedOnlyByNativeData)
			return kSceneAssetReferencedByNativeCodeOnly;
		else
			return kSceneAssetReferenced;
	}
	else
	{
		if (referencedOnlyByNativeData)
			return kAssetReferencedByNativeCodeOnly;
		else
			return kAssetReferenced;
	}

	return kNotApplicable;
}

#endif