summaryrefslogtreecommitdiff
path: root/Runtime/Export/UnityEngineObject.txt
blob: 27001884eed53625061e154a4a968214805c8b4e (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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
C++RAW


#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/Misc/SaveAndLoadHelper.h"
#include "Runtime/GameCode/CloneObject.h"
#include "Runtime/Misc/Player.h"
#include "Runtime/Misc/GameObjectUtility.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Scripting/Scripting.h"


#if UNITY_WII
	#include "PlatformDependent/Wii/WiiUtility.h"
#endif
	
using namespace Unity;
using namespace std;

CSRAW
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Collections;
using UnityEngineInternal;


namespace UnityEngine
{




BEGIN DOC
Base class for all objects Unity can reference.
Any public variable you make that derives from Object gets shown in the inspector as a drop target, 
allowing you to set the value from the GUI.
END DOC

CSRAW
[StructLayout (LayoutKind.Sequential)]
NONSEALED_CLASS Object
	CSRAW
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
	private ReferenceData m_UnityRuntimeReferenceData;

	#if UNITY_EDITOR
	private string        m_UnityRuntimeErrorString;
	#endif
#else //UNITY_FLASH
	//*undocumented*
	[NotRenamed]
	public int		m_InstanceID;
	//*undocumented*
	[NotRenamed]
	public int		m_CachedPtr;
#endif
	
	public override bool Equals(object o) { return CompareBaseObjects (this, o as Object); } 
	public override int GetHashCode() 	{ return GetInstanceID();	}

	// Does the object exist?
	public static implicit operator bool (Object exists)
	{
		return !CompareBaseObjects (exists, null);
	}

	CSRAW private static bool CompareBaseObjects (Object lhs, Object rhs) 
	{
	#if UNITY_WINRT
		return UnityEngineInternal.ScriptingUtils.CompareBaseObjects(lhs, rhs);
	#else
		return CompareBaseObjectsInternal (lhs, rhs); 
	#endif
	}

	CONSTRUCTOR_SAFE
	CUSTOM private static bool CompareBaseObjectsInternal ([Writable]Object lhs, [Writable]Object rhs) 
	{
		return Scripting::CompareBaseObjects (lhs.GetScriptingObject(), rhs.GetScriptingObject()); 
	}
	
	// Returns the instance id of the object.
	CSRAW [NotRenamed]
	CSRAW public int GetInstanceID ()
	{
#if !UNITY_FLASH && !UNITY_WEBGL && !UNITY_WINRT
		return m_UnityRuntimeReferenceData.instanceID; 
#else
		return m_InstanceID;
#endif
	}

	CUSTOM private static Object Internal_CloneSingle (Object data)
	{
		DISALLOW_IN_CONSTRUCTOR
		return Scripting::ScriptingWrapperFor (&CloneObject (*data));
	}
	CUSTOM private static Object Internal_InstantiateSingle (Object data, Vector3 pos, Quaternion rot)
	{
		DISALLOW_IN_CONSTRUCTOR
		Object* obj = &InstantiateObject (*data, pos, rot);
		return Scripting::ScriptingWrapperFor(obj);
	}


	// Clones the object /original/ and returns the clone.

	
	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
	CSRAW public static Object Instantiate (Object original, Vector3 position, Quaternion rotation)
	{
		CheckNullArgument(original,"The prefab you want to instantiate is null.");
		return Internal_InstantiateSingle (original, position, rotation);
	}

	
	// Clones the object /original/ and returns the clone.
	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeOfFirstArgument)]
	public static Object Instantiate (Object original)
	{
        CheckNullArgument(original,"The thing you want to instantiate is null.");
		return Internal_CloneSingle (original);
	}
	#if ENABLE_GENERICS_BUT_CURRENTLY_DISABLED
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public static T Instantiate<T>(T original) where T : UnityEngine.Object
	{
		CheckNullArgument(original,"The thing you want to instantiate is null.");
		return (T)Internal_CloneSingle (original);
	}
	#endif
	
	static private void CheckNullArgument(object arg, string message)
	{
		if (arg==null)
			throw new ArgumentException(message);
	}

	// Removes a gameobject, component or asset.
	CSRAW
	CUSTOM static void Destroy (Object obj, float t = 0.0F) { DISALLOW_IN_CONSTRUCTOR Scripting::DestroyObjectFromScripting (obj, t); }


	// Destroys the object /obj/ immediately. It is strongly recommended to use Destroy instead.
	CSRAW
	CUSTOM static void DestroyImmediate (Object obj, bool allowDestroyingAssets = false) { Scripting::DestroyObjectFromScriptingImmediate (obj, allowDestroyingAssets); }

	// Returns a list of all active loaded objects of Type /type/.
	CSRAW [TypeInferenceRule(TypeInferenceRules.ArrayOfTypeReferencedByFirstArgument)]
	CUSTOM static Object[] FindObjectsOfType (Type type) { DISALLOW_IN_CONSTRUCTOR return Scripting::FindObjectsOfType (type, Scripting::kFindActiveSceneObjects); }

	CONDITIONAL (ENABLE_GENERICS && !UNITY_FLASH)
	CSRAW public static T[] FindObjectsOfType<T> () where T: Object
	{
		return Resources.ConvertObjects<T> (FindObjectsOfType (typeof (T)));
	}

	// Returns the first active loaded object of Type /type/.
	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
	CSRAW public static Object FindObjectOfType (Type type)
	{
		Object[] objects = FindObjectsOfType (type);
		if (objects.Length > 0)
			return objects[0];
		else
			return null;
	}

	CONDITIONAL (ENABLE_GENERICS && !UNITY_FLASH)
	CSRAW public static T FindObjectOfType<T> () where T: Object
	{
		return (T)FindObjectOfType (typeof (T));
	}

	// Compares if two objects refer to the same
	CSRAW public static bool operator == (Object x, Object y) { return CompareBaseObjects (x, y); }
	
	// Compares if two objects refer to a different object
	CSRAW public static bool operator != (Object x, Object y) { return !CompareBaseObjects (x, y); } 
	
	// The name of the object.
	CUSTOM_PROP string name { return scripting_string_new(self->GetName ()); } { self->SetName ( value.AsUTF8().c_str()); }
	
	// Makes the object /target/ not be destroyed automatically when loading a new scene.
	CUSTOM static void DontDestroyOnLoad (Object target)
	{
		Object* o = target;
		if (o)
			DontDestroyOnLoad (*o);
	}

	// Should the object be hidden, saved with the scene or modifiable by the user?
	CONSTRUCTOR_SAFE
	AUTO_PROP HideFlags hideFlags GetHideFlags SetHideFlags

	//*undocumented* deprecated
	// We cannot properly deprecate this in C# right now, since the optional parameter creates 
	// another method calling this, which creates compiler warnings when deprecated.
	// OBSOLETE warning use Object.Destroy instead.
	CUSTOM static void DestroyObject (Object obj, float t = 0.0F) { Scripting::DestroyObjectFromScripting (obj, t); }
	
	//*undocumented* DEPRECATED
	OBSOLETE warning use Object.FindObjectsOfType instead.
	CUSTOM static Object[] FindSceneObjectsOfType (Type type) { DISALLOW_IN_CONSTRUCTOR return Scripting::FindObjectsOfType (type, Scripting::kFindActiveSceneObjects); }
	
	//*undocumented*  DEPRECATED
	OBSOLETE warning use Resources.FindObjectsOfTypeAll instead.
	CUSTOM static Object[] FindObjectsOfTypeIncludingAssets (Type type) { DISALLOW_IN_CONSTRUCTOR return Scripting::FindObjectsOfType (type, Scripting::kFindAssets); }

	CONDITIONAL ENABLE_MONO
	OBSOLETE warning Please use Resources.FindObjectsOfTypeAll instead
	CSRAW public static Object[] FindObjectsOfTypeAll (Type type) { return Resources.FindObjectsOfTypeAll (type); }

	// Returns the name of the game object.
	CUSTOM public override string ToString() {
		return scripting_string_new(GetSafeString(BaseObject, UnityObjectToString (self)));
	}

END
CSRAW }