summaryrefslogtreecommitdiff
path: root/Runtime/Misc/BuildSettings.cpp
blob: 2c4ad74f5fa7761f174faeeea3544a0748e70c9a (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include "UnityPrefix.h"
#include "Configuration/UnityConfigureVersion.h"
#include "BuildSettings.h"
#include "Runtime/Utilities/PathNameUtility.h"
#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h"
#include "Runtime/BaseClasses/ManagerContext.h"
#include "Runtime/Utilities/Word.h"
#include "Runtime/Utilities/ErrorExit.h"

int kUnityVersion3_0_0a1 = GetNumericVersion("3.0.0.a1");
int kUnityVersion3_2_a1 = GetNumericVersion("3.2.0a1");
int kUnityVersion3_3_a1 = GetNumericVersion("3.3.0a1");
int kUnityVersion3_4_a1 = GetNumericVersion("3.4.0a1");
int kUnityVersion3_5_a1 = GetNumericVersion("3.5.0a1");
int kUnityVersion3_5_3_a1 = GetNumericVersion("3.5.3a1");
int kUnityVersion4_0_a1 = GetNumericVersion("4.0.0a1");
int kUnityVersion4_1_a1 = GetNumericVersion("4.1.0a1");
int kUnityVersion4_1_1_a1 = GetNumericVersion("4.1.1a1");
int kUnityVersion4_1_a3 = GetNumericVersion("4.1.0a3");
int kUnityVersion4_2_a1 = GetNumericVersion("4.2.0a1");
int kUnityVersion4_3_a1 = GetNumericVersion("4.3.0a1");
int kUnityVersion_OldWebResourcesAdded = GetNumericVersion("4.2.0a1");

BuildSettings::BuildSettings (MemLabelId label, ObjectCreationMode mode)
:	Super(label, mode)
{
	hasRenderTexture = true;
	hasPROVersion = true;
	hasAdvancedVersion = true;
	hasShadows = true;
	hasSoftShadows = true;
	hasLocalLightShadows = true;
	isNoWatermarkBuild = false;
	isPrototypingBuild = false;
	isEducationalBuild = false;
	isEmbedded = false;
	hasPublishingRights = true;
	isDebugBuild = true;
	usesOnMouseEvents = true;
	enableDynamicBatching = true;
	#if UNITY_EDITOR
	m_Version = UNITY_VERSION;
	#else
	m_Version = "1.6.0";
	#endif
	m_IntVersion = GetNumericVersion(m_Version);
}

BuildSettings::~BuildSettings ()
{
}

string BuildSettings::GetLevelPathName (int index)
{
	if (index < remappedLevels.size () && index >= 0)
		return remappedLevels[index];
	else
		return string ();
}

string BuildSettings::GetLevelPathName (const string& name)
{
	return GetLevelPathName (GetLevelIndex (name));
}

string BuildSettings::GetLevelName (int index)
{
	if (index < levels.size () && index >= 0)
		return DeletePathNameExtension (GetLastPathNameComponent(levels[index]));
	else
		return string ();
}

int BuildSettings::GetLevelIndex (const string& name)
{
	for (int i=0;i<levels.size ();i++)
	{
		string curName = levels[i];
		curName = DeletePathNameExtension (GetLastPathNameComponent(curName));
		if (StrICmp (name, curName) == 0)
			return i;
	}
	return -1;
}

int BuildSettings::GetLevelIndexChecked (const string& name)
{
	int index = GetLevelIndex (name);
	if (index == -1)
	{
		ErrorString (Format ("Level %s couldn't be found because it has not been added to the build settings.\nTo add a level to the build settings use the menu File->Build Settings...", name.c_str()));
	}
	return index;
}

UInt32 BuildSettings::GetHashOfClass (int classID) const
{
	ClassHashCont::const_iterator it = runtimeClassHashes.find (classID);
	if (it == runtimeClassHashes.end ())
		return 0;

	return it->second;
}

template<class TransferFunction>
void BuildSettings::Transfer (TransferFunction& transfer)
{
	Super::Transfer (transfer);
	transfer.SetVersion (2);
	TRANSFER (levels);
	TRANSFER (hasRenderTexture);
	TRANSFER (hasPROVersion);
	TRANSFER (isNoWatermarkBuild);
	TRANSFER (isPrototypingBuild);
	TRANSFER (isEducationalBuild);
	TRANSFER (isEmbedded);
	TRANSFER (hasPublishingRights);
	TRANSFER (hasShadows);
	TRANSFER (hasSoftShadows);
	TRANSFER (hasLocalLightShadows);
	TRANSFER (hasAdvancedVersion);
	TRANSFER (enableDynamicBatching);
	TRANSFER (isDebugBuild);
	TRANSFER (usesOnMouseEvents);
	transfer.Align();
	
	if (transfer.IsOldVersion(1))
	{
		hasPROVersion = hasRenderTexture;
	}
	
	// Only in game build mode we transfer the version,
	// in the editor it is always the latest one
	if (transfer.IsSerializingForGameRelease())
	{
		TRANSFER (m_Version);
		TRANSFER (m_AuthToken);
		
		if(transfer.IsReading()) {
			if(GetNumericVersion(m_Version) < kUnityVersion3_0_0a1) {
				// We're attempting to load a version of unity that we don't have
				// backwards compatibility for.
				ExitWithErrorCode(kErrorIncompatibleRuntimeVersion);
			}
		}
	}

	// We need hashed type trees only for the player 
	if (transfer.IsSerializingForGameRelease())
	{
		TRANSFER (runtimeClassHashes);
	}
}

void BuildSettings::AwakeFromLoad (AwakeFromLoadMode awakeMode)
{
	Super::AwakeFromLoad (awakeMode);
	remappedLevels = levels;
	#if GAMERELEASE
	if (remappedLevels.empty ())
	{
		remappedLevels.push_back ("mainData");
		levels.push_back ("");
	}
	else
	{
		remappedLevels[0] = "mainData";
		for (int i=1;i<remappedLevels.size ();i++)
			remappedLevels[i] = Format ("level%d", i - 1);
	}
	#endif
	
#if UNITY_WINRT
	// On Metro you switch between debug/release in VS solution,
	// so we need isDebugBuild to dependant on the player, not on the settings
#	if UNITY_DEVELOPER_BUILD
		isDebugBuild = true;
#	else
		isDebugBuild = false;
#	endif
#endif
	m_IntVersion = GetNumericVersion(m_Version);
}

GET_MANAGER(BuildSettings)
GET_MANAGER_PTR(BuildSettings)
IMPLEMENT_CLASS (BuildSettings)
IMPLEMENT_OBJECT_SERIALIZE (BuildSettings)