-
Notifications
You must be signed in to change notification settings - Fork 2
/
81-C# Script-NewBehaviourScript.cs.txt
202 lines (146 loc) · 8.83 KB
/
81-C# Script-NewBehaviourScript.cs.txt
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
using UnityEngine;
using System.Collections;
public class #SCRIPTNAME# : MonoBehaviour {
// Awake is called:
// exactly once in the lifetime of the script (like Start).
// upon GO activation or if a fn in any script attached to it is called.
// even if the script is disabled
// before any Start functions
// after all GO's are initialized
// USAGE: initialize any references, variables, or game state before the game starts.
void Awake() {
}
// OnEnable is called:
// just after the Behaviour is enabled && GO active.
// when a MonoBehaviour instance is created.
// when a GO with the script component is instantiated.
// when scripts are reloaded after compilation (OnDisable->OnEnable).
// USAGE: restarting behaviours which are frequently disabled/deactivated.
void OnEnable() {
}
// OnDisable is called:
// when the Behaviour becomes disabled || GO inactive.
// when the GO is destroyed.
// when scripts are reloaded after compilation (OnDisable->OnEnable)
// USAGE: cleanup.
void OnDisable() {
}
// Start is called:
// exactly once in the lifetime of the script (like Awake).
// only if the script instance is enabled.
// after all GO's Awake functions have been called (except during gameplay, naturally).
// on the frame when a script is enabled just before any Update methods called.
// USAGE: initialization, using refs/vars initialized in Awake.
void Start() {
}
// Update is called:
// only if the MonoBehaviour is enabled.
// once per frame.
// USAGE: get Input, most game behaviour.
void Update() {
}
// FixedUpdate is called:
// only if the MonoBehaviour is enabled.
// on a reliable timer, independent of the frame rate.
// multiple times per frame if the frame rate is low.
// rarely between frames if the frame rate is high.
// USAGE: should be used instead of Update when dealing with Rigidbody.
void FixedUpdate() {
// All physics calculations and updates occur immediately after FixedUpdate.
// When applying movement calculations inside FixedUpdate, you do not need to multiply your values by Time.deltaTime.
}
// LateUpdate is called:
// once per frame, after Update has finished.
// to make use of newly updated data.
// USAGE: Camera movements based on updated GO positions.
void LateUpdate() {
}
// WHEN QUITTING: These functions get called on all the active objects in your scene.
// OnDestroy is called:
// when the MonoBehaviour will be destroyed.
// on game objects that have previously been active.
// after all frame updates for the last frame of the object’s existence.
// in response to Object.Destroy or at the closure of a scene.
void OnDestroy() {
}
// OnApplicationQuit is called:
// on all game objects before the application is quit.
// Editor: when the user stops playmode.
// Web player: when the web view is closed.
void OnApplicationQuit() {
}
// OnApplicationPause is called:
// when the player pauses.
// at the end of the frame where the pause is detected.
// between the normal frame updates.
// One extra frame will be issued after OnApplicationPause is called to allow the game to show graphics that indicate the paused state.
void OnApplicationPause(bool pauseStatus) {
// paused = pauseStatus;
}
} // end class
/*
/// DEBUG ///////////////////////////////////////////////////////////////////
Debug.Log() // Logs message to the Unity Console.
Debug.Assert() // Assert the condition.
Debug.DrawLine() // Draws a line between specified start and end points.
Debug.DrawRay() // Draws a line from start to start + dir in world coordinates.
Debug.Break() // Pauses the editor.
/// GIZMOS.XXX
Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
This allows you to quickly pick important objects in your scene.
Note that OnDrawGizmos will use a mouse position that is relative to the Scene View.
This function does not get called if the component is collapsed in the inspector. Use OnDrawGizmosSelected to draw gizmos when the game object is selected.
OnDrawGizmos() { }
OnDrawGizmosSelected() { }
GIZMO STATIC FUNCTIONS
DrawCube Draw a solid box with center and size.
DrawFrustum Draw a camera frustum using the currently set Gizmos.matrix for it's location and rotation.
DrawGUITexture Draw a texture in the scene.
DrawIcon Draw an icon at a position in the scene view.
DrawLine Draws a line starting at from towards to.
DrawMesh Draws a mesh.
DrawRay Draws a ray starting at from to from + direction.
DrawSphere Draws a solid sphere with center and radius.
DrawWireCube Draw a wireframe box with center and size.
DrawWireMesh Draws a wireframe mesh.
DrawWireSphere Draws a wireframe sphere with center and radius.
/// INPUT ///////////////////////////////////////////////////////////////////
/// MOUSE
Called every frame while the mouse is over the GUIElement or Collider.
These functions are not called on objects that belong to Ignore Raycast layer.
These functions are called on Colliders marked as Trigger if and only if Physics.queriesHitTriggers is true.
OnMouseXXX can be a co-routine, simply use the yield statement in the function. This event is sent to all scripts attached to the Collider or GUIElement.
void OnMouseEnter() { } // called when the mouse enters the GUIElement or Collider.
void OnMouseOver() { } // called every frame while the mouse is over the GUIElement or Collider.
void OnMouseDrag() { } // called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
void OnMouseExit() { } // called when the mouse is not any longer over the GUIElement or Collider.
void OnMouseDown() { } // called when the user has pressed the mouse button while over the GUIElement or Collider.
void OnMouseUp() { } // called when the user has released the mouse button
void OnMouseUpAsButton() { } // called when the mouse is released over the SAME GUIElement or Collider as it was pressed.
/// PHYSICS ///////////////////////////////////////////////////////////////////
OnCollisionEnter is passed the Collision class and not a Collider.
The Collision class contains information about contact points, impact velocity etc.
If you don't use collisionInfo in the function, leave out the collisionInfo parameter as this avoids unnecessary calculations.
Collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached.
Collision events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions.
void OnTriggerXXX() { } // Enter|Exit|Stay
void OnCollisionXXX() { }
/// COROUTINES ///////////////////////////////////////////////////////////////////
Normal coroutine updates are run after the Update function returns. A coroutine is a function that can suspend its execution (yield) until the given YieldInstruction finishes. Different uses of Coroutines:
yield The coroutine will continue after all Update functions have been called on the next frame.
yield WaitForSeconds Continue after a specified time delay, after all Update functions have been called for the frame
yield WaitForFixedUpdate Continue after all FixedUpdate has been called on all scripts
yield WaitForEndOfFrame Continue after all FixedUpdate has been called on all scripts
yield WWW Continue after a WWW download has completed.
yield StartCoroutine Chains the coroutine, and will wait for the MyFunc coroutine to complete first.
/// RENDERING ///////////////////////////////////////////////////////////////////
OnPreCull: Called before the camera culls the scene. Culling determines which objects are visible to the camera. OnPreCull is called just before culling takes place.
OnBecameVisible/OnBecameInvisible: Called when an object becomes visible/invisible to any camera.
OnWillRenderObject: Called once for each camera if the object is visible.
OnPreRender: Called before the camera starts rendering the scene.
OnRenderObject: Called after all regular scene rendering is done. You can use GL class or Graphics.DrawMeshNow to draw custom geometry at this point.
OnPostRender: Called after a camera finishes rendering the scene.
OnRenderImage: Called after scene rendering is complete to allow postprocessing of the screen image.
OnGUI: Called multiple times per frame in response to GUI events. The Layout and Repaint events are processed first, followed by a Layout and keyboard/mouse event for each input event.
OnDrawGizmos: Used for drawing Gizmos in the scene view for visualisation purposes.
*/