1 / 42

Introduction to Unity Classes

Introduction to Unity Classes. Unity game engine classes. Two major categories: Runtime see http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.html Editor see http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.Editor_Classes.html.

mignon
Download Presentation

Introduction to Unity Classes

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Unity Classes

  2. Unity game engine classes • Two major categories: • Runtime • see http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.html • Editor • see http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.Editor_Classes.html

  3. Unity RuntimeClasses (94!) • 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 • 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

  4. Unity EditorClasses (40!) • AnimationClipCurveData • AnimationUtility • AssetDatabase • AssetImporter • AssetPostprocessor • BuildPipeline • CustomEditor • DragAndDrop • DrawGizmo • EditorApplication • EditorGUILayout • EditorGUIUtility • EditorGUI • EditorPrefs • EditorStyles • EditorUtility • EditorWindow • Editor • FileUtil • HandleUtility • Handles • Help • LightmapEditorSettings • Lightmapping • MenuCommand • MenuItem • MeshUtility • ModelImporterClipAnimation • MonoScript • ObjectNames • PlayerSettings • Selection • SerializedObject • SerializedProperty • StaticOcclusionCullingVisualization • StaticOcclusionCulling • TextureImporterSettings • Undo • UnwrapParam • Unwrapping

  5. Unity Class Overview • class A inherits from class B • Object is the base class for all objects Unity can reference. • variables (data members) • constructors (ctors) • functions (methods) • class variables (static) • class functions (static) • inherited members • inherited variables • inherited functions • inherited class variables • inherited class functions

  6. Unity Class Overview • also: • Enumerations • groups of constants • 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 )

  7. Important Unity Runtime Classes

  8. Application access to application run-time data This class contains static methods for looking up information about and controlling the run-time data.

  9. Application • 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.

  10. AudioSource 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.

  11. Camera 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).

  12. Color 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.

  13. Color • 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).

  14. Color • static function Color ( r : float, g : float, b : float, a : float ) : Color • Constructs a new Color with given r,g,b,a components.

  15. GameObject • 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.

  16. GameObject • 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.

  17. GameObject • Constructor(s) • static function GameObject ( name : string ) : GameObject • Creates a new game object, named name.

  18. GameObject • 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.

  19. Gizmos 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.

  20. Gizmos • 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.

  21. Light 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.

  22. Light Example of an enum (enumeration). • 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.

  23. LineRenderer The line renderer is used to draw free-floating lines in 3D space. This class is a script interface for a line renderer component.

  24. Mathf • 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.

  25. Mathf • 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.

  26. MonoBehaviour 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.

  27. MonoBehaviour • 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.

  28. MonoBehaviour • 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

  29. MonoBehaviour • 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

  30. MonoBehaviour • 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

  31. MonoBehaviour • 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.

  32. Object 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.

  33. Object subclasses AnimationClip AssetBundle AudioClip Component Flare Font GameObject Material Mesh PhysicMaterial ScriptableObject Shader TerrainData TextAsset Texture

  34. PhysicMaterial • Physics material describes how to handle colliding objects. • friction, bounciness

  35. Random • 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].

  36. Screen 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.

  37. Screen 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.

  38. SystemInfo • Access system information. • OS, amount of memory, # of processors, etc.

  39. Time • 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.

  40. Transform • 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.

  41. Transform • 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.

  42. Transform • 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.

More Related