UnityClasses

advertisement
 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.
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.
AccelerationEvent
AnimationCurve
AnimationEvent
AnimationState
Application
Array
AudioSettings
BitStream
BoneWeight
Bounds
ClothSkinningCoefficient
Collision
Color
CombineInstance
ContactPoint
ControllerColliderHit
Debug
DetailPrototype
Event
GL
GUIContent
GUILayoutOption
GUILayoutUtility
GUILayout
GUISettings
GUIStyleState
GUIStyle
GUIUtility
GUI
GeometryUtility
Gizmos
Graphics
Hashtable
HostData
Input
JointDrive
JointLimits
JointMotor
JointSpring
Keyframe
LayerMask
LightmapData
LightmapSettings
LocationInfo
MasterServer
MaterialPropertyBlock
Mathf
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.
Matrix4x4
NetworkMessageInfo
NetworkPlayer
NetworkViewID
Network
Object (has many, many subclasses)
Particle
Path
Physics
Ping
Plane
PlayerPrefsException
PlayerPrefs
Profiler
QualitySettings
Quaternion
Random
Ray
RaycastHit
RectOffset
Rect
RenderSettings
Resolution
Resources
Screen
Security
SoftJointLimit
SplatPrototype
StaticBatchingUtility
String
SystemInfo
Time
Touch
TreeInstance
TreePrototype
Vector2
Vector3
Vector4
WWWForm
WWW
WheelFrictionCurve
WheelHit
YieldInstruction (some additional subclasses)
iPhoneInput
iPhoneKeyboard
iPhoneSettings
iPhoneUtils
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
AnimationClipCurveData
AnimationUtility
AssetDatabase
AssetImporter
AssetPostprocessor
BuildPipeline
CustomEditor
DragAndDrop
DrawGizmo
EditorApplication
EditorGUILayout
EditorGUIUtility
EditorGUI
EditorPrefs
EditorStyles
EditorUtility
EditorWindow
Editor
FileUtil
HandleUtility
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
Handles
Help
LightmapEditorSettings
Lightmapping
MenuCommand
MenuItem
MeshUtility
ModelImporterClipAnimation
MonoScript
ObjectNames
PlayerSettings
Selection
SerializedObject
SerializedProperty
StaticOcclusionCullingVisualization
StaticOcclusionCulling
TextureImporterSettings
Undo
UnwrapParam
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
 This
to application run-time data
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,
•
•
•
•
•
•
•
•
•
•
Example of an
enum
(enumeration).
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.
 The
line renderer is used to draw freefloating 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
 Screen
to display information.
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.
Download