Aspect Properties--camera viewport scale
Public float aspect {get; set;}
Used to get or set the width-height scale value of the camera palatability
The aspect only handles the attempted aspect ratio that the camera can see, and the hardware display only displays the contents of the camera, and the view will deform when the width and height ratio of the hardware display is not the same as the proportional value of the aspect.
Using unityengine;using system.collections;public class aspect_ts:monobehaviour{ void Start () { // The default value is the aspect value of the current hardware Debug.Log ("Camera.aspectμ??? È?? Μ£o "+ camera.aspect); } void Ongui () { if (GUI. button (new Rect (10.0f, 10.0f, 200.0f, 45.0f), "aspect=1.0f")) { camera. Resetaspect (); Camera.aspect = 1.0f; } if (GUI. button (new Rect (10.0f, 60.0f, 200.0f, 45.0f), "aspect=2.0f")) { camera. Resetaspect (); Camera.aspect = 2.0f; } if (GUI. button (new Rect (10.0f, 110.0f, 200.0f, 45.0f), "Aspect?1?-?? È?? μ ")) { camera. Resetaspect ();}}}
Cameratoworldmatrix transformation matrix
Public matrix4x4 Cameratoworldmatrix {get;}
Returns the transformation matrix from the camera's local coordinate system to the world coordinate system
Note that the forward direction in--camera is the z-axis direction of its own coordinate system, and generally other Gameobject objects forward the direction of their own coordinate system.
Using unityengine;using system.collections;public class cameratoworldmatrix_ts:monobehaviour{ void Start () { Debug.Log ("camera pre-rotation position" + transform.position); matrix4x4 m = Camera.cameratoworldmatrix; The value of V3 is the position of the position in the world coordinate system that moves forward 5 units in the z-axis direction of the camera local coordinate system Vector3 v3 = m.multiplypoint (Vector3.forward * 5.0f);//v4 The value is the position of the position in the world coordinate system that moves forward 5 units along the z-axis direction of the camera world coordinate system VECTOR3 v4 = m.multiplypoint (Transform.forward * 5.0f); ′òó?v3?¢v4 Debug.Log ("Before rotation, V3" + v3);D ebug. Log ("Before rotation, v4" + v4); Transform. Rotate (Vector3.up * 90.0f); Debug.Log ("Camera rotated" + transform.position);} }
Cullingmask Properties--camera is rendered by layer
Selectively render objects in the scene. Cullingmusk =-1 Renders any object in the scene, Cullingmusk = 0 does not render any layer in the scene, if the object is rendered 2,3,4 layer, you can use code Cullingmask = (1<<2) + (1<<3) + (1 <<4)
The object hierarchy in the scene needs to be set up now
Using unityengine;using system.collections;public class cullingmask_ts:monobehaviour{void Ongui () {//render any Layer if (GUI. button (new Rect (10.0f, 10.0f, 200.0f, 45.0f), "Cullingmask=-1")) {camera.cullingmask =-1; }//Do not render any layer if (GUI. button (new Rect (10.0f, 60.0f, 200.0f, 45.0f), "cullingmask=0")) {camera.cullingmask = 0; }//0 Layer if (GUI. button (new Rect (10.0f, 110.0f, 200.0f, 45.0f), "cullingmask=1<<0")) {Camera.cullingmask = 1 <& Lt 0; }//8 Layer if (GUI. button (new Rect (10.0f, 160.0f, 200.0f, 45.0f), "Cullingmask=1<<8")) {Camera.cullingmask = 1 <& Lt 8; }//0 layer and Layer 8 if (GUI. button (new Rect (10.0f, 210.0f, 200.0f, 45.0f), "Cullingmask=0&&8")) {//cannot be written as Camera.cullingmask = 1 << 8+1;//camera.cullingmask = 1+1<<8; equivalent to//camera.cullingmask, respectively, according to precedence order1 << (8+1) Oícamera.cullingmask = (+) <<8; Camera.cullingmask = (1 << 8) + 1; } }}
Evenmask Properties: Responding to events by layer
Select which layer of the object can respond to mouse events
The object must be within the camera's field of view
Using unityengine;using system.collections;public class eventmask_ts:monobehaviour{bool is_rotate = false;//Control Object rotation Public camera c;//points to the Eventmask value of the camera//record camera in the scene, you can modify the size of its value in the Inspector panel while the program is running public int eventmask_now =-1; Record the current object's layer int layer_now; int tp;//record 2 of the value of the layer ad;//the result of the record and operation (&) string str = NULL; void Update () {//records the layer of the current object, you can select a different layer in the Inspector panel when the program runs Layer_now = Gameobject.layer; 2 Layer_now value TP = (int) mathf.pow (2.0f, Layer_now); With arithmetic (&) AD = Eventmask_now & tp; C.eventmask = Eventmask_now; Rotates the object if (is_rotate) {transform when is_rotate is true. Rotate (vector3.up * 15.0f * time.deltatime); }}//When the left mouse button is pressed, the object starts to rotate void OnMouseDown () {is_rotate = true; }//When the left mouse button is lifted, the object ends rotated void OnMouseUp () {is_rotate = false; } void Ongui () {GUI. Label (New Rect (10.0f, 10.0f, 300.0f, 45.0f), "the current object's layer value is:" + Layer_now + ", 2 of the layer's value is" + TP); Gui. Label (New Rect (10.0f, 60.0f, 300.0f, 45.0f), "Current camera eventmask values are:" + eventmask_now); Gui. Label (New Rect (10.0f, 110.0f, 500.0f, 45.0f), "according to the algorithm, when the value of Eventmask with" + TP + "and operation (&), if the result is" + TP + ", then the object corresponding Onmousexxx method , otherwise not responding! "); if (AD = = TP) {str = ", so the object will onmousexxx the method accordingly! "; } else {str = ', so the object does not onmousexxx the method accordingly! "; } GUI. Label (New Rect (10.0f, 160.0f, 500.0f, 45.0f), "and the current eventmask with" + TP + "is performed with the result of the operation (&) as" + AD + str "; }}
Layerculldistances properties: distance of layer blanking
Sets the hidden distance of the camera based on the layer--must be less than or equal to the farclipplane of the camera to be valid
Using unityengine;using System.collections;public class layerculldistances_ts:monobehaviour{public Transform CB1; void Start () { ///defines a 321-D array to store the culling distance of all layers float[] distances = new FLOAT[32]; Set the culling distance of the 9th layer distances[8] = vector3.distance (transform.position, cb1.position); Assigns the array to the camera's layerculldistance camera.layerculldistances = distances; } void Update () { //camera away from Object transform. Translate (Transform.right * time.deltatime);} }
Layercullspherical Properties--based on spherical distance culling
The default value is false--is not suitable for spherical culling-at this point, the object is visible as long as the surface of the object does not exceed the far-agreeable plane of the object's layer.
When Layercullspherical is true, the object is invisible as long as the object's world coordinate point position the distance from the camera is greater than the rejection distance of the layer.
Declares 3 transform public variables for pointing to objects in a scene
Using unityengine;using System.collections;public class layercullspherical_ts:monobehaviour{public Transform CB1, CB 2, CB3; void Start () {//defines a one-dimensional array of size 32 to store the culling distance of all layers float[] distances = new FLOAT[32]; Set the culling distance of the 9th layer distances[8] = vector3.distance (transform.position, cb1.position); Assigns the array to the camera's layerculldistances camera.layerculldistances = distances; Print out the distance of three objects from the camera Debug.Log ("Cube1 distance from the camera:" + vector3.distance (transform.position, cb1.position)); Debug.Log ("Distance Cube2 distance from camera:" + vector3.distance (transform.position, cb2.position)); Debug.Log ("Distance Cube3 distance from camera:" + vector3.distance (transform.position, cb3.position)); } void Ongui () {//Use spherical distance to reject if (GUI. button (new Rect (10.0f, 10.0f, 180.0f, 45.0f), "use Layercullspherical")) {camera.layercullspherical = t Rue }//Cancel spherical distance culling if (GUI. button (new Rect (10.0f, 60.0f, 180.0f, 45.0f), "Unuse layercullspherical")) {camera.layercullspherical = false; } }}
Orthographic Properties--Camera projection mode
True for orthographic projection mode (orthographic) and false for perspective projection mode (Perspective)
In the orthogonal projection mode, the size of the object in the viewport is only related to the size of the orthogonal palatability, regardless of the distance from the camera to the object, and is mainly used to present the 2D effect--no near large or small effect.
Pixelrect Properties--Camera render interval
Set the coordinates where the camera is rendered to the screen
Pixelrect is similar to the property Rect feature, unlike the Pixelrect, which sets the position of the viewport at the actual pixel size
The value of the Camera.pixelrect (x,y,w,h)--x is the pixel size that the viewport moves right, the value of y is the pixel size shifted by the viewport, the value of W is camera.pixelwidth, and the value of H is camera.pixelheight
Using unityengine;using system.collections;public class pixelrect_ts:monobehaviour{int which_change =-1; float temp_x = 0.0f, temp_y = 0.0f; void Update () {//screen.widthoíscreen.height?a?£?aó2?t?á?? Μ?? Í??? μ,//?? Μ??? Μ2??? Camera.pixelwidthoícamera.pixelheightμ??? ±????? ±? Debug.Log ("Screen.width:" + screen.width); Debug.Log ("Screen.height:" + screen.height); Debug.Log ("Pixelwidth:" + camera.pixelwidth); Debug.Log ("Pixelheight:" + camera.pixelheight); Change the viewport's interval if (Which_change = = 0) {if (Camera.pixelwidth > 1.0f) {) By changing the camera's coordinate position { temp_x + = Time.deltatime * 20.0f; } camera.pixelrect = new Rect (temp_x, temp_y, Camera.pixelwidth, camera.pixelheight); }//Change the viewport's interval if (Which_change = 1) {if (Camera.pixelwidth > 1) by changing the camera's viewport width and height. 0f) {temp_x = Camera.pixelwidth-time.deltATime * 20.0F; } camera.pixelrect = new Rect (0, 0, temp_x, temp_y); }} void Ongui () {if (GUI. button (new rect (10.0f, 10.0f, 200.0f, 45.0f), viewport change mode one)) {camera.rect = new rect (0.0f, 0.0f, 1.0f, 1.0 f); Which_change = 0; temp_x = 0.0f; temp_y = 0.0f; } if (GUI. button (new rect (10.0f, 60.0f, 200.0f, 45.0f), "Viewport change Mode II")) {camera.rect = new rect (0.0f, 0.0f, 1.0f, 1.0 f); Which_change = 1; temp_x = 0.0f; temp_y = Camera.pixelheight; } if (GUI. button (new rect (10.0f, 110.0f, 200.0f, 45.0f), viewport Restore)) {camera.rect = new rect (0.0f, 0.0f, 1.0f, 1.0f) ; Which_change =-1; } }}
ProjectionMatrix Property--Custom projection matrix
To implement some special effects scenarios, it is often necessary to use the camera first when switching the transformation matrix. Resetprojectionmatrix () Resetting the camera's transformation matrix
Using unityengine;using System.collections;public class projectionmatrix_ts:monobehaviour{public Transform sp, CB; Public matrix4x4 originalprojection; float q=0.1f;//sloshing amplitude float p=1.5f;//shaking frequency int which_change = 1; void Start () {//record original projection matrix originalprojection = Camera.projectionmatrix; } void Update () {sp. Rotatearound (Cb.position, Cb.up, 45.0f * time.deltatime); matrix4x4 PR = originalprojection; Switch (which_change) {case-1: break; Case 0://around camera x-axis shaking Pr.m11 + = Mathf.sin (Time.time * p) * q; Break Case 1://Around camera y-axis shaking pr.m01 + = Mathf.sin (Time.time * p) * q; Break Case 2://Around camera z-axis shaking pr.m10 + = Mathf.sin (Time.time * p) * q; Break Case 3://Around camera move around pr.m02 + = Mathf.sin (time.tiMe * p) * q; Break Case 4://Camera Viewport Zoom motion pr.m00 + = Mathf.sin (Time.time * p) * q; Break }//Set the transformation matrix of the camera Camera.projectionmatrix = PR; } void Ongui () {if (GUI. button (new Rect (10.0f, 10.0f, 200.0f, 45.0f), "Wobble around camera x axis") {camera. Resetprojectionmatrix (); Which_change = 0; }if (GUI. button (new Rect (10.0f, 60.0f, 200.0f, 45.0f), "shaking around the camera y-axis") {camera. Resetprojectionmatrix (); Which_change = 1; }if (GUI. button (new Rect (10.0f, 110.0f, 200.0f, 45.0f), "shaking around the camera Z axis") {camera. Resetprojectionmatrix (); Which_change = 2; }if (GUI. button (new Rect (10.0f, 160.0f, 200.0f, 45.0f), "Move around Camera") {camera. Resetprojectionmatrix (); Which_change = 3; }if (GUI. button (new Rect (10.0f, 210.0f, 200.0f, 45.0f), Camera viewport zoom motion)) {camera. Resetprojectionmatrix (); Which_change = 4; } }}
Rect Properties--location and size of camera view
Use the unit coordinate system to set the view position and size of the current camera, scale
Renderingpath
Gets or sets the render path of the camera
There are four ways to set the render path:
useplayersettings--using the settings in the project
vertexlit--use vertex illumination, lowest consumed render path, real-time shading not supported, for mobile and honest devices
forward--using forward illumination, shader-based render path
deferredlighting--uses delayed illumination, supports real-time shading, and calculates large consumption
Using unityengine;using system.collections;public class renderingpath_ts:monobehaviour{ void Ongui () { if (GUI. button (new Rect (10.0f, 10.0f, 120.0f, 45.0f), "Useplayersettings")) { Camera.renderingpath = renderingpath.useplayersettings; } if (GUI. button (new Rect (10.0f, 60.0f, 120.0f, 45.0f), "Vertexlit")) {//No bump texture, no projection Camera.renderingpath = renderingpath.vertexlit; } if (GUI. button (new Rect (10.0f, 110.0f, 120.0f, 45.0f), "Forward")) {//has a bump texture, can only display one projection Camera.renderingpath = Renderingpath.forward; } if (GUI. button (new Rect (10.0f, 160.0f, 120.0f, 45.0f), "deferredlighting")) {//has a bump texture, can display multiple projections Camera.renderingpath = renderingpath.deferredlighting;}} }
Targettexture Property--Target render texture
Call this property to generate a target render texture, available only for professional editions
The function of this property is that a view of a camera a can be renderer Texture, then added to a material object to form a new material, and then assign this material to a Gameobject object of renderer component
Worldtocameramatrix attribute--Transformation matrix
Returns or sets the transformation matrix from the world coordinate system to the current camera's own coordinate system
When resetting the camera's conversion matrix with Camera.worldtocameramatrix, the camera's corresponding transform component data will not be updated synchronously, and if you want to return to transform's controllable state, you need to call the Resetwoldtocameramatrix method to reset the camera's turn Change matrix
Unity API Parsing (2)--camera class properties