summaryrefslogtreecommitdiff
path: root/Runtime/Export/UnityEngineGameObject.txt
blob: 1915db09ddb71b53a8f183ebd52634d5a97d0a98 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
C++RAW


#include "UnityPrefix.h"
#include "Configuration/UnityConfigure.h"
#include "Runtime/Graphics/Transform.h"
#include "Runtime/Mono/MonoBehaviour.h"
#include "Runtime/BaseClasses/Tags.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Export/GameObjectExport.h"
#if ENABLE_AUDIO
#include "Runtime/Audio/AudioSource.h"
#endif

#include "Runtime/Animation/Animation.h"
#include "Runtime/Camera/Camera.h"

#if ENABLE_PHYSICS
#include "Runtime/Dynamics/RigidBody.h"
#include "Runtime/Dynamics/ConstantForce.h"
#include "Runtime/Dynamics/HingeJoint.h"
#include "Runtime/Dynamics/Collider.h"
#endif
#if ENABLE_2D_PHYSICS
#include "Runtime/Physics2D/RigidBody2D.h"
#include "Runtime/Physics2D/Collider2D.h"
#endif
#include "Runtime/Camera/Light.h"
#include "Runtime/Filters/Renderer.h"
#if ENABLE_NETWORK
#include "Runtime/Network/NetworkView.h"
#endif
#include "Runtime/Camera/RenderLayers/GUIText.h"
#include "Runtime/Camera/RenderLayers/GUITexture.h"
#include "Runtime/Filters/Particles/ParticleEmitter.h"
#include "Runtime/Graphics/ParticleSystem/ParticleSystem.h"
#include "Runtime/Misc/GameObjectUtility.h"
#include "Runtime/Misc/GOCreation.h"
#include "Runtime/Scripting/ScriptingExportUtility.h"
#include "Runtime/Scripting/GetComponent.h"
#include "Runtime/Scripting/Scripting.h"

	
using namespace Unity;

/*
   Mono defines a bool as either 1 or 2 bytes.
   On windows a bool on the C++ side needs to be 2 bytes.
   We use the typemap to map bool's to short's.
   When using the C++ keyword and you want to export a bool value 
   to mono you have to use a short on the C++ side.
*/

using namespace std;

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

namespace UnityEngine
{



// Base class for all entities in Unity scenes.
CSRAW
CLASS GameObject : Object

	// Creates a game object with a primitive mesh renderer and appropriate collider.
	CSRAW
	CUSTOM static GameObject CreatePrimitive (PrimitiveType type) 
	{ 
		return Scripting::ScriptingWrapperFor(CreatePrimitive(type)); 
	}



	// Returns the component of Type /type/ if the game object has one attached, null if it doesn't. You can access both builtin components or scripts with this function.

	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
	CUSTOM Component GetComponent (Type type) { return ScriptingGetComponentOfType (*self, type); }

	CSRAW
	#if ENABLE_GENERICS
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T GetComponent<T>() where T : Component { return GetComponent(typeof(T)) as T; }
	#endif


	// Returns the component with name /type/ if the game object has one attached, null if it doesn't.

	CSRAW 
	public Component GetComponent (string type) { return GetComponentByName(type); }
	CUSTOM private Component GetComponentByName (string type) { return Scripting::GetScriptingWrapperOfComponentOfGameObject (*self, type); }

	

		
	// Returns the component of Type /type/ in the GameObject or any of its children using depth first search.
	
	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
	CSRAW public Component GetComponentInChildren (Type type)
	{
		if( activeInHierarchy ) {
		
			Component attachedCom = GetComponent (type);
			if ( attachedCom != null )
				return attachedCom;
		}
			
		Transform transform = this.transform;
		if ( transform != null )
		{
			foreach (Transform child in transform)
			{
				Component childCom = child.gameObject.GetComponentInChildren (type);
				if (childCom != null)
					return childCom;
			}
		}
		
		return null;
	}

	CSRAW
	#if ENABLE_GENERICS
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T GetComponentInChildren<T>() where T : Component { return GetComponentInChildren(typeof(T)) as T; }
	#endif
	
	// Editor only API that specifies if a game object is static.
	AUTO_PROP bool isStatic GetIsStaticDeprecated SetIsStaticDeprecated

	CUSTOM_PROP internal bool isStaticBatchable { return self->IsStaticBatchable (); }

	// Returns all components of Type /type/ in the GameObject.

	CSRAW [CanConvertToFlash]
	CSRAW public Component[] GetComponents (Type type)  { return (Component[])GetComponentsInternal (type, false, false, true); }

	CSRAW
	#if ENABLE_GENERICS
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T[] GetComponents<T>() where T : Component
	{
		return (T[]) GetComponentsInternal(typeof(T), true, false, true);
	}
	#endif
	
	// Returns all components of Type /type/ in the GameObject or any of its children.
	
	CSRAW public Component[] GetComponentsInChildren (Type type, bool includeInactive = false)
	{
		return (Component[])GetComponentsInternal(type, false, true, includeInactive);
	}
	
	CSRAW
	#if ENABLE_GENERICS
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T[] GetComponentsInChildren<T>(bool includeInactive) where T : Component
	{
		return (T[])GetComponentsInternal(typeof(T), true, true, includeInactive);
	}
	#endif
	
	CSRAW
	#if ENABLE_GENERICS
	// Manually supplying the overload because lucas cannot figure out how to patch cspreprocess to add template support to the overload generation code.
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T[] GetComponentsInChildren<T>() where T : Component { return GetComponentsInChildren<T>(false); }
	#endif
	
	
	
	CUSTOM private Component[] GetComponentsInternal(Type type, bool isGenericTypeArray, bool recursive, bool includeInactive)
	{ 
		DISALLOW_IN_CONSTRUCTOR return ScriptingGetComponentsOfType (*self, type, isGenericTypeArray, recursive, includeInactive);
	}

	
	C++RAW
 #define FASTGO_QUERY_COMPONENT(x) GameObject& go = *self; return Scripting::GetComponentObjectToScriptingObject (go.QueryComponent (x), go, ClassID (x));


	// The [[Transform]] attached to this GameObject. (null if there is none attached)
	CSRAW
	CUSTOM_PROP Transform transform { FASTGO_QUERY_COMPONENT(Transform) }

	CONDITIONAL ENABLE_PHYSICS
	// The [[Rigidbody]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP Rigidbody rigidbody { FASTGO_QUERY_COMPONENT(Rigidbody) }

	CONDITIONAL ENABLE_2D_PHYSICS
	CUSTOM_PROP Rigidbody2D rigidbody2D { FASTGO_QUERY_COMPONENT(Rigidbody2D) }

	// The [[Camera]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP Camera camera { FASTGO_QUERY_COMPONENT(Camera) }

	// The [[Light]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP Light light { FASTGO_QUERY_COMPONENT(Light) }

	// The [[Animation]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP Animation animation { FASTGO_QUERY_COMPONENT(Animation) }

	// The [[ConstantForce]] attached to this GameObject (RO). (null if there is none attached)
	CONDITIONAL ENABLE_PHYSICS
	CUSTOM_PROP ConstantForce constantForce { FASTGO_QUERY_COMPONENT(ConstantForce) }

	// The [[Renderer]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP Renderer renderer { FASTGO_QUERY_COMPONENT(Renderer) }

	// The [[AudioSource]] attached to this GameObject (RO). (null if there is none attached)
	CONDITIONAL ENABLE_AUDIO
	CUSTOM_PROP AudioSource audio { FASTGO_QUERY_COMPONENT(AudioSource) }
	
	// The [[GUIText]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP GUIText guiText { FASTGO_QUERY_COMPONENT(GUIText) }
	
	CONDITIONAL ENABLE_NETWORK
	// The [[NetworkView]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP NetworkView networkView
	{
		#if ENABLE_NETWORK
		FASTGO_QUERY_COMPONENT(NetworkView)
		#else
		return SCRIPTING_NULL;
		#endif
	}
	
	FLUSHCONDITIONS

	CSRAW
#if ENABLE_NETWORK
	OBSOLETE warning Please use guiTexture instead
#endif
	CUSTOM_PROP GUIElement guiElement { FASTGO_QUERY_COMPONENT(GUIElement) }

	// The [[GUITexture]] attached to this GameObject (RO). (null if there is none attached)
	CUSTOM_PROP GUITexture guiTexture { FASTGO_QUERY_COMPONENT(GUITexture) }

	// The [[Collider]] attached to this GameObject (RO). (null if there is none attached)
	CONDITIONAL ENABLE_PHYSICS
	CUSTOM_PROP Collider collider { FASTGO_QUERY_COMPONENT(Collider) }

	CONDITIONAL ENABLE_2D_PHYSICS
	CUSTOM_PROP Collider2D collider2D { FASTGO_QUERY_COMPONENT(Collider2D) }

	// The [[HingeJoint]] attached to this GameObject (RO). (null if there is none attached)
	CONDITIONAL ENABLE_PHYSICS
	CUSTOM_PROP HingeJoint hingeJoint { FASTGO_QUERY_COMPONENT(HingeJoint) }

	// The [[ParticleEmitter]] attached to this GameObject (RO). (null if there is none attached) 
	CUSTOM_PROP ParticleEmitter particleEmitter { FASTGO_QUERY_COMPONENT(ParticleEmitter) }

	// The [[ParticleSystem]] attached to this GameObject (RO). (null if there is none attached) 
	CUSTOM_PROP ParticleSystem particleSystem { FASTGO_QUERY_COMPONENT(ParticleSystem) }

	// The layer the game object is in. A layer is in the range [0...31]
	AUTO_PROP int layer GetLayer SetLayer

	OBSOLETE warning GameObject.active is obsolete. Use GameObject.SetActive(), GameObject.activeSelf or GameObject.activeInHierarchy.
	CSRAW
	CUSTOM_PROP bool active { return self->IsActive (); } { self->SetSelfActive (value); }

	// Activates/Deactivates the GameObject.
	CUSTOM void SetActive (bool value) { self->SetSelfActive (value); }

	// The local active state of this GameObject.
	CUSTOM_PROP public bool activeSelf { return self->IsSelfActive (); }
	
	// Is the GameObject active in the scene?
	CUSTOM_PROP public bool activeInHierarchy { return self->IsActive (); }
	
	OBSOLETE warning gameObject.SetActiveRecursively() is obsolete. Use GameObject.SetActive(), which is now inherited by children.
	CUSTOM public void SetActiveRecursively (bool state)
	{
		self->SetActiveRecursivelyDeprecated (state);
	}
	
	// The tag of this game object.
	CUSTOM_PROP string tag
	{
		const string& tag = TagToString (self->GetTag ());
		if (!tag.empty ())
			return scripting_string_new(tag);
		else
		{
			Scripting::RaiseMonoException ("GameObject has undefined tag!");
			return SCRIPTING_NULL;
		}
	}
	{
		self->SetTag (ExtractTagThrowing (value));
	}

	// Is this game object tagged with /tag/?
	CUSTOM public bool CompareTag (string tag)
	{
		return ExtractTagThrowing (tag) == self->GetTag ();
	}
	
	//*undocumented*
	CUSTOM static GameObject FindGameObjectWithTag (string tag)
	{
		DISALLOW_IN_CONSTRUCTOR
		int tagInt = ExtractTagThrowing (tag);
		return Scripting::ScriptingWrapperFor(FindGameObjectWithTag (tagInt));
	}

	// Returns one active GameObject tagged /tag/. Returns null if no GameObject was found.
	CSRAW static public GameObject FindWithTag (string tag)
	{
		return FindGameObjectWithTag(tag);
	}

	// Returns a list of active GameObjects tagged /tag/. Returns null if no GameObject was found.
	CUSTOM static GameObject[] FindGameObjectsWithTag (string tag)
	{
		DISALLOW_IN_CONSTRUCTOR
		static vector<GameObject*> go; go.clear ();
		int tagInt = ExtractTagThrowing (tag);
		FindGameObjectsWithTag (tagInt, go);
		ScriptingClassPtr goClass = Scripting::ClassIDToScriptingType (ClassID (GameObject));
		return CreateScriptingArrayFromUnityObjects(go,goClass);
	}

	// Calls the method named /methodName/ on every [[MonoBehaviour]] in this game object and on every ancestor of the behaviour
	CUSTOM void SendMessageUpwards (string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver)
	{
		Scripting::SendScriptingMessageUpwards(*self, methodName, value, options);
	}

	//*undocumented* Function is for convenience and avoid coming mistakes.
	CSRAW public void SendMessageUpwards (string methodName, SendMessageOptions options)
	{
		SendMessageUpwards (methodName, null, options);
	}

	// Calls the method named /methodName/ on every [[MonoBehaviour]] in this game object.
	CUSTOM void SendMessage (string methodName, object value = null, SendMessageOptions options = SendMessageOptions.RequireReceiver)
	{
		Scripting::SendScriptingMessage(*self, methodName, value, options);
	}

	//*undocumented* Function is for convenience and avoid coming mistakes.
	CSRAW public void SendMessage (string methodName, SendMessageOptions options)
	{
		SendMessage (methodName, null, options);
	}

	// Calls the method named /methodName/ on every [[MonoBehaviour]] in this game object or any of its children.
	CUSTOM void BroadcastMessage (string methodName, object parameter = null, SendMessageOptions options = SendMessageOptions.RequireReceiver)
	{
		Scripting::BroadcastScriptingMessage(*self, methodName, parameter, options);
	}
	
	//*undocumented* Function is for convenience and avoid coming mistakes.
	CSRAW public void BroadcastMessage (string methodName, SendMessageOptions options)
	{
		BroadcastMessage (methodName, null, options);
	}
		
	// Adds a component class named /className/ to the game object.

	CUSTOM Component AddComponent (string className) { return MonoAddComponent (*self, className.AsUTF8().c_str()); }

	// Adds a component class of type /componentType/ to the game object. C# Users can use a generic version
	CSRAW
	[TypeInferenceRule(TypeInferenceRules.TypeReferencedByFirstArgument)]
	CSRAW public Component AddComponent (Type componentType)
	{
		return Internal_AddComponentWithType(componentType);
	}

	CSRAW
	CUSTOM private Component Internal_AddComponentWithType (Type componentType)
	{
		return MonoAddComponentWithType(*self, componentType);
	}
	
	CSRAW
	#if ENABLE_GENERICS
	// Generic version. See the [[wiki:Generic Functions|Generic Functions]] page for more details.
	public T AddComponent<T>() where T : Component 
	{
		return AddComponent(typeof(T)) as T;
	}
	#endif
	
	CUSTOM private static void Internal_CreateGameObject ([Writable]GameObject mono, string name)
	{
		DISALLOW_IN_CONSTRUCTOR
		GameObject* go = MonoCreateGameObject (name.IsNull() ? NULL : name.AsUTF8().c_str() ); 
		Scripting::ConnectScriptingWrapperToObject (mono.GetScriptingObject(), go); 
	}

	// Creates a new game object, named __name__.
	CSRAW public GameObject (string name) { Internal_CreateGameObject (this, name); }
	
	// Creates a new game object.
	CSRAW public GameObject () { Internal_CreateGameObject (this, null); }

	// Creates a game object and attaches the specified components.
	CSRAW public GameObject (string name, params Type[] components)
	{
		Internal_CreateGameObject (this, name);
		foreach (Type t in components)
			AddComponent (t);
	}

	OBSOLETE warning gameObject.PlayAnimation is not supported anymore. Use animation.Play
	CUSTOM void PlayAnimation (AnimationClip animation) { ErrorString("gameObject.PlayAnimation(); is not supported anymore. Use animation.Stop();"); }
	
	OBSOLETE warning gameObject.StopAnimation is not supported anymore. Use animation.Stop
	CUSTOM void StopAnimation () { ErrorString("gameObject.StopAnimation(); is not supported anymore. Use animation.Stop();"); }

	// Finds a game object by /name/ and returns it.
	CSRAW
	CUSTOM static GameObject Find (string name)
	{
		DISALLOW_IN_CONSTRUCTOR
		Transform* transform = FindActiveTransformWithPath (name.AsUTF8().c_str ());
		GameObject* go = NULL;
		if (transform)
			go = transform->GetGameObjectPtr ();
		return Scripting::ScriptingWrapperFor (go);
	}

	//*undocumented - just for convenience
	CSRAW public GameObject gameObject { get { return this; } }
}
END