Introduction to Unity Classes

minedesertΛογισμικό & κατασκευή λογ/κού

31 Οκτ 2013 (πριν από 3 χρόνια και 5 μήνες)

69 εμφανίσεις


Two major categories:

1.
Runtime


see
http://unity3d.com/support/documentation/Script
Reference/20_class_hierarchy.html

2.
Editor


see
http://unity3d.com/support/documentation/Script
Reference/20_class_hierarchy.Editor_Classes.html

1.
AccelerationEvent

2.
AnimationCurve

3.
AnimationEvent

4.
AnimationState

5.
Application

6.
Array

7.
AudioSettings

8.
BitStream

9.
BoneWeight

10.
Bounds

11.
ClothSkinningCoefficient

12.
Collision

13.
Color

14.
CombineInstance

15.
ContactPoint

16.
ControllerColliderHit

17.
Debug

18.
DetailPrototype

19.
Event

20.
GL

21.
GUIContent

22.
GUILayoutOption

23.
GUILayoutUtility

24.
GUILayout

25.
GUISettings

26.
GUIStyleState

27.
GUIStyle

28.
GUIUtility

29.
GUI

30.
GeometryUtility

31.
Gizmos

32.
Graphics

33.
Hashtable

34.
HostData

35.
Input

36.
JointDrive

37.
JointLimits

38.
JointMotor

39.
JointSpring

40.
Keyframe

41.
LayerMask

42.
LightmapData

43.
LightmapSettings

44.
LocationInfo

45.
MasterServer

46.
MaterialPropertyBlock

47.
Mathf

1.
Matrix4x4

2.
NetworkMessageInfo

3.
NetworkPlayer

4.
NetworkViewID

5.
Network

6.
Object (has many, many subclasses)

7.
Particle

8.
Path

9.
Physics

10.
Ping

11.
Plane

12.
PlayerPrefsException

13.
PlayerPrefs

14.
Profiler

15.
QualitySettings

16.
Quaternion

17.
Random

18.
Ray

19.
RaycastHit

20.
RectOffset

21.
Rect

22.
RenderSettings

23.
Resolution

24.
Resources

25.
Screen

26.
Security

27.
SoftJointLimit

28.
SplatPrototype

29.
StaticBatchingUtility

30.
String

31.
SystemInfo

32.
Time

33.
Touch

34.
TreeInstance

35.
TreePrototype

36.
Vector2

37.
Vector3

38.
Vector4

39.
WWWForm

40.
WWW

41.
WheelFrictionCurve

42.
WheelHit

43.
YieldInstruction (some additional subclasses)

44.
iPhoneInput

45.
iPhoneKeyboard

46.
iPhoneSettings

47.
iPhoneUtils

1.
AnimationClipCurveData

2.
AnimationUtility

3.
AssetDatabase

4.
AssetImporter

5.
AssetPostprocessor

6.
BuildPipeline

7.
CustomEditor

8.
DragAndDrop

9.
DrawGizmo

10.
EditorApplication

11.
EditorGUILayout

12.
EditorGUIUtility

13.
EditorGUI

14.
EditorPrefs

15.
EditorStyles

16.
EditorUtility

17.
EditorWindow

18.
Editor

19.
FileUtil

20.
HandleUtility

1.
Handles

2.
Help

3.
LightmapEditorSettings

4.
Lightmapping

5.
MenuCommand

6.
MenuItem

7.
MeshUtility

8.
ModelImporterClipAnimation

9.
MonoScript

10.
ObjectNames

11.
PlayerSettings

12.
Selection

13.
SerializedObject

14.
SerializedProperty

15.
StaticOcclusionCullingVisualization

16.
StaticOcclusionCulling

17.
TextureImporterSettings

18.
Undo

19.
UnwrapParam

20.
Unwrapping


class A inherits from class B


Object is the base class for all objects Unity can
reference.

1.
variables (data members)

2.
constructors (
ctors
)

3.
functions (methods)

4.
class variables (static)

5.
class functions (static)

6.
inherited members


inherited variables


inherited functions


inherited class variables


inherited class functions


also:

1.
Enumerations


groups of constants

2.
Attributes


special (i.e., non C# language) command in scripts to
add items to development, tells compiler/interpreter
how code should be processed, etc.



notation:


static function Quit ( ) : void


static void Quit ( )


static function
LoadLevel

( index :
int

) : void


static void
LoadLevel

(
int

index )



access to application run
-
time data



This class contains static methods for
looking up information about and
controlling the run
-
time data.


static function Quit ( ) : void


Quits the player application. Quit is ignored in the
editor or the web player.


static function LoadLevel ( index : int ) :
void


Loads the level.


This function loads level by its index. You can see the
indices of all levels using the File
-
>Build Settings...
menu in Unity. Before you can load a level you have to
add it to the list of levels used in the game. Use File
-
>Build Settings... in Unity and add the levels you need to
the level list there.


A representation of audio sources in 3D.


An AudioSource is attached to a GameObject for
playing back sounds in a 3D environment.
Mono
sounds play back 3D.

In order to play 3D sounds you
also need to have a AudioListener. The audio listener is
normally attached to the camera you want to use.
Stereo sounds are always played back without distance
based attenuation.


You can play a single audio clip using Play, Pause and
Stop. You can also adjust its volume while playing using
volume property, or seek using time. Multiple sounds
can be played on one AudioSource using PlayOneShot.
You can play a clip at a static position in 3D space using
PlayClipAtPoint.


A Camera is a device through which the player
views the world.


A screen space point is defined in pixels. The
bottom
-
left of the screen is (0,0); the right
-
top is
(pixelWidth,pixelHeight). The z position is in
world units from the camera.


A viewport space point is normalized and
relative to the camera. The bottom
-
left of the
camera is (0,0); the top
-
right is (1,1). The z
position is in world units from the camera.


A world space point is defined in global
coordinates (eg. Transform.position).


Representation of RGBA colors.



This structure is used throughout Unity to pass
colors around. Each color component is a
floating point value with a range from 0 to 1.



Components (r,g,b) define a color in RGB color
space. Alpha component (a) defines
transparency
-

alpha of one is completely
opaque, alpha of zero is completely
transparent.


Class variables


red
-

Solid red. RGBA is (1, 0, 0, 1).


green
-

Solid green. RGBA is (0, 1, 0, 1).


blue
-

Solid blue. RGBA is (0, 0, 1, 1).


white
-

Solid white. RGBA is (1, 1, 1, 1).


black
-

Solid black. RGBA is (0, 0, 0, 1).


yellow
-

Yellow. RGBA is weird (1, 235/255, 4/255, 1), but the color
is nice to look at!


cyan
-

Cyan. RGBA is (0, 1, 1, 1).


magenta
-

Magenta. RGBA is (1, 0, 1, 1).


gray
-

Gray. RGBA is (0.5, 0.5, 0.5, 1).


grey
-

English spelling for gray. RGBA is the same (0.5, 0.5, 0.5, 1).


clear
-

Completely transparent. RGBA is (0, 0, 0, 0).


static function Color ( r : float, g : float, b :
float, a : float ) : Color


Constructs a new Color with given r,g,b,a
components.


Base class for all entities in Unity scenes.


Variables


transform
-

The Transform attached to this GameObject. (null if none)


rigidbody
-

The Rigidbody attached to this GameObject. (null if none)


camera
-

The Camera attached to this GameObject. (null if none)


light
-

The Light attached to this GameObject. (null if none)


renderer
-

The Renderer attached to this GameObject. (null if none)


audio
-

The AudioSource attached to this GameObject. (null if none)


collider
-

The Collider attached to this GameObject. (null if none)


particleEmitter
-

The ParticleEmitter attached to this GameObject.
(null none)


layer
-

The layer the game object is in. A layer is in the range [0...32].


tag
-

The tag of this game object.


Class functions


FindWithTag
-

Returns one active GameObject
tagged tag. Returns null if no GameObject was
found.



FindGameObjectsWithTag
-

Returns a list of
active GameObjects tagged tag. Returns null if
no GameObject was found.



Find
-

Finds a game object by name and returns
it.


Constructor(s)



static function GameObject ( name : string ) :
GameObject


Creates a new game object, named name.


Functions


GetComponent
-

Returns the component of Type type if the
game object has one attached, null if it doesn't.


GetComponentInChildren
-

Returns the component of Type
type in the GameObject or any of its children using depth first
search.


GetComponents
-

Returns all components of Type type in the
GameObject.


GetComponentsInChildren
-

Returns all components of Type
type in the GameObject or any of its children.


AddComponent
-

Adds a component class named className to
the game object.


Gizmos are used to give visual debugging or
setup aids in the scene view.



All gizmo drawing has to be done in either
OnDrawGizmos or OnDrawGizmosSelected
functions of the script.



OnDrawGizmos is called every frame. All gizmos
rendered within OnDrawGizmos are pickable.



OnDrawGizmosSelected is called only if the
object the script is attached to is selected.


Class variable(s)


color
-

Sets the color for the gizmos that will be drawn next.



Class functions


DrawLine
-

Draws a line starting at
from

towards
to
.


DrawWireSphere
-

Draws a wireframe sphere with center and
radius.


DrawSphere
-

Draws a solid sphere with center and radius.


DrawWireCube
-

Draw a wireframe box with center and size.


DrawCube
-

Draw a solid box with center and size.


DrawIcon
-

Draw an icon at world position in the scene view.


DrawGUITexture
-

Draw a texture in screen coordinates. Useful for
GUI backgrounds.


Script interface for light components.



Use this to control all aspects of Unity's
lights. The properties are an exact match
for the values shown in the Inspector.



Usually lights are just created in the
editor but sometimes you want to create
a light from a script.


Variables


type
-

The type of the light (can be LightType.Spot,
LightType.Directional, LightType.Point).


color
-

The color of the light.


intensity
-

The Intensity of a light is multiplied with the Light color.


shadows
-

How this light casts shadows.


shadowStrength
-

Strength of light's shadows


range
-

The range of the light.


spotAngle
-

The light's spotlight angle in degrees.


cookie
-

The cookie texture projected by the light.


flare
-

The flare asset to use for this light.


renderMode
-

How to render the light.


cullingMask
-

This is used to lights parts of the scene selectively.

Example of an
enum

(enumeration).


The line renderer is used to draw free
-
floating lines in 3D space.



This class is a script interface for a line
renderer component.


A collection of common math functions.


Class variables


PI
-

The infamous 3.14159265358979... value.


Infinity
-

A representation of positive infinity.


NegativeInfinity
-

A representation of negative
infinity.


Deg2Rad
-

Degrees
-
to
-
radians conversion
constant.


Rad2Deg
-

Radians
-
to
-
degrees conversion
constant.


Epsilon
-

A tiny floating point value.


A collection of common math functions.


Class functions


familiar functions such as Sin, Cos, Tan, Asin,
Acos, Atan, Atan2, Sqrt, Abs, Min, Max, Pow, Exp,
Log, Log10, Ceil, Floor, Round, etc.


MonoBehaviour is the base class every
script derives from.


Using Javascript every script
automatically derives from
MonoBehaviour.


When using C# (or Boo) you have to
explicitly derive from MonoBehaviour.


MonoBehaviour inherits from Behaviour
which inherits from Component which
inherits from Object.


Methods typically overridden:


Update
-

called every frame, if the
MonoBehaviour is enabled


FixedUpdate
-

This function is called every fixed
framerate frame, if the MonoBehaviour is
enabled.


Awake
-

called when the script instance is being
loaded


Start
-

called just before any of the Update
methods are called the first time


Reset
-

Reset to default values.


Methods typically overridden in response to some event:


OnMouseEnter
-

called when the mouse entered the GUIElement or
Collider


OnMouseOver
-

called every frame while the mouse is over the
GUIElement or Collider


OnMouseExit
-

called when the mouse is not any longer over the
GUIElement or Collider


OnMouseDown
-

called when the user has pressed the mouse button
while over the GUIElement or Collider


OnMouseUp
-

called when the user has released the mouse button


OnMouseDrag
-

called when the user has clicked on a GUIElement or
Collider and is still holding down the mouse


Methods typically overridden in response to some event:


OnTriggerEnter
-

called when the Collider other enters the trigger


OnTriggerExit
-

called when the Collider other has stopped touching the
trigger


OnTriggerStay
-

called once per frame for every Collider other that is
touching the trigger



OnCollisionEnter
-

called when this collider/rigidbody has begun
touching another rigidbody/collider


OnCollisionExit
-

called when this collider/rigidbody has stopped
touching another rigidbody/collider


OnCollisionStay
-

called once per frame for every collider/rigidbody that
is touching rigidbody/collider


OnControllerColliderHit
-

called when the controller hits a collider while
performing a Move


OnParticleCollision
-

called when a particle hits a collider


Methods typically overridden in response to some event:


OnBecameVisible
-

called when the renderer became visible by any
camera



OnBecameInvisible
-

called when the renderer is no longer visible by
any camera



OnLevelWasLoaded
-

called after a new level was loaded



OnEnable
-

called when the object becomes enabled and active



OnDisable
-

called when the behaviour becomes disabled () or inactive


Methods typically overridden in response to some event:


OnGUI
-

called for rendering and handling GUI events



OnDrawGizmosSelected
-

Implement this if you want to draw gizmos only
if the object is selected.



OnDrawGizmos
-

Implement this if you want to draw gizmos that are also
pickable and always drawn.


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.


AnimationClip


AssetBundle


AudioClip


Component


Flare


Font


GameObject


Material


Mesh


PhysicMaterial


ScriptableObject


Shader


TerrainData


TextAsset


Texture


Physics material describes how to handle
colliding objects.


friction, bounciness


Class for generating random data.


Class variables


seed
-

the seed for the random number generator


value
-

a random number between 0.0 [inclusive] and 1.0
[inclusive]


insideUnitSphere
-

a random point inside a sphere with radius 1


insideUnitCircle
-

a random point inside a circle with radius 1


onUnitSphere
-

a random point on the surface of a sphere with
radius 1


rotation
-

a random rotation


Class functions


static function Range ( min : float, max : float ) : float


Returns a random float number between and min [inclusive] and
max [inclusive].


Access to display information.



Screen class can be used to get the list of
supported resolutions, switch the current
resolution, hide or show the system
mouse pointer.

Class variables


resolutions


All fullscreen resolutions supported by the monitor (Read Only).


currentResolution


The current screen resolution (Read Only).


showCursor


Should the cursor be visible?


lockCursor


Should the cursor be locked?


width


The current width of the screen window in pixels (Read Only).


height


The current height of the screen window in pixels (Read Only).


fullScreen


Is the game running fullscreen?

Class functions


SetResolution


Switches the screen resolution.


Access system information.


OS, amount of memory, # of processors, etc.


The interface to get time information
from Unity.


Class variable(s)


time
-

The time this frame has started (Read
Only). This is the time in seconds since the start
of the game.


Position (translation), rotation, and scale
of an object.


Every object in a scene has a Transform. It's
used to store and manipulate the position,
rotation and scale of the object. Every Transform
can have a parent, which allows you to apply
position, rotation and scale hierarchically. This is
the hierarchy seen in the Hierarchy pane. They
also support enumerators (iterators?) so you can
loop through children using C# foreach.


Variables:


position
-

The position of the transform in world
space.


eulerAngles
-

The rotation as Euler angles in
degrees.


rotation
-

The rotation of the transform in world space
stored as a Quaternion.


right
-

The red axis of the transform in world space.


up
-

The green axis of the transform in world space.


forward


-

The blue axis of the transform in world
space.


localScale
-

The scale of the transform relative to the
parent.


Functions


Translate
-

Moves the transform in the direction and distance of
translation.


Rotate
-

Applies a rotation of eulerAngles.z degrees around the z
axis, eulerAngles.x degrees around the x axis, and eulerAngles.y
degrees around the y axis (in that order).


RotateAround
-

Rotates the transform about axis passing through
point in world coordinates by angle degrees.


LookAt
-

Rotates the transform so the forward vector points at
target's current position.


TransformPoint
-

Transforms position from local space to world
space.