Unity API - C

废话不多说,一针见血,go!
一起来看 API

Caching 缓存

缓存类允许您管理缓存AssetBundles,下载使用 WWW.LoadFromCacheOrDownload

Caching.Authorize 授权
授权这个Unity内容使用缓存

Caching.CleanCache 清除缓存
删除这个内容相关的缓存文件夹

当你已经有一个缓存许可证时,这个函数才能激活

Caching.Authorize (name, domain, size, signature);
    if (GUILayout.Button("Uninstall Game"))
        Caching.CleanCache ();

Caching.compressionEnabled
控制缓存数据的压缩。 默认启用。

如果启用了缓存压缩,然后将所有数据存储在一个压缩的形式使用快速LZ4算法。 这个属性只影响进一步下载。 它不压缩或解压缩在缓存中现有内容。

缺省值为“true”

Caching.enabled 启用
缓存是否启用?

if (!Caching.enabled)
    GUILayout.Label ("Please turn on caching to run this game.");

Caching.expirationDelay 截止延迟
在缓存中没有被使用的AssetBundle的过期时间,单位为秒。

这个值默认为150天(12960000秒)。 较低的值会导致缓存清理更积极地为了最小化磁盘存储使用。 不能设置大于12960000秒延迟

Caching.IsVersionCached 是否缓存的版本
检查,如果一个资源包被缓存

if (Caching.IsVersionCached("http://myserver.com/bla.unity3d", 3))
    GUILayout.Button("Load Level");

Caching.MarkAsUsed
标记缓存文件的时间戳为当前时间

这允许你保持文件缓存即使你不是显式地加载它们
如果url缓存返回true

Caching.maximumAvailableDiskSpace
为缓存分配的总字节数

这个值可以设置为一个较小的数量,以限制缓存AssetBundles所使用的磁盘空间。 WebPlayer共享缓存允许缓存AssetBundles 50 MiB

Caching.ready 准备

Caching.spaceFree 剩余空间
可用的磁盘空间,以bytes(字节)为单位

Caching.spaceOccupied 占用空间
已经使用的磁盘空间,以bytes(字节)为单位

Camera 摄像机

Camera.AddCommandBuffer
添加一个命令执行缓冲区在指定的地方。

可以将多个命令缓冲区执行同一相机事件(甚至同一缓冲区可以多次添加)。

Camera.actualRenderingPath 实际渲染路径
实际使用的渲染路径(只读)

Camera.allCameras 所有相机
返回场景中所有启用的相机

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public int count = Camera.allCameras.Length;
    void Example() {
        print("We've got " + count + " cameras");
    }
}

Camera.allCamerasCount 所有相机数量
当前场景中相机数量

var count = Camera.allCamerasCount;
    print ("We've got " + count + " cameras");

Camera.aspect 宽长比
宽长比(宽度除以高度)

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {
    if (camera.aspect > 1.0F)
        print("Screen is more wide than tall!");
    else
        print("Screen is more tall than wide!");
    }
}

Camera.backgroundColor 背景颜色
屏幕将被清理为这个颜色

来回变化背景颜色

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public Color color1 = Color.red;
    public Color color2 = Color.blue;
    public float duration = 3.0F;
    void Update() 
    {   //设置消除标识到颜色
        float t = Mathf.PingPong(Time.time, duration) / duration;
        camera.backgroundColor = Color.Lerp(color1, color2, t);
    }
    public void Awake() 
    {
        camera.clearFlags = CameraClearFlags.SolidColor;
    }
}

Camera.CalculateObliqueMatrix 计算倾斜矩阵
计算并返回倾斜接近水平的投影矩阵

给定一个剪辑平面向量,该函数返回摄像机的投影矩阵,投影矩阵的这个剪辑平面设置为它的近平面

Camera.CameraCallback
委托类型的相机回调

使用这个 Camera.onPreCull , Camera.onPreRender 或 Camera.onPostRender 回调函数,当任何相机并呈现。

相机,调用回调将作为参数传递

Camera.cameraToWorldMatrix 相机转世界矩阵
从相机空间到世界空间的变换矩阵

在屏幕视图绘制一个黄色的球,以Distance单位,沿着相机所看方向

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public float distance = -1.0F;
    void OnDrawGizmosSelected() 
    {
        Matrix4x4 m = camera.cameraToWorldMatrix;
        Vector3 p = m.MultiplyPoint(new Vector3(0, 0, distance));
        Gizmos.color = Color.yellow;
        Gizmos.DrawSphere(p, 0.2F);
    }
}

Camera.cameraType
这是确定什么样的相机

Camera.clearFlags 清除标识
相机如何清除背景

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //用背景颜色清除(忽略天空盒)
        camera.clearFlags = CameraClearFlags.SolidColor;
    }
}

Camera.clearStencilAfterLightingPass
通常如果你使用延迟渲染相机和面具(见UI元素 面具 ),你会想要模板 缓冲区被清除

Camera.commandBufferCount
这架照相机上的命令缓冲区设置数量(只读)

Camera.CopyFrom 复制到
使这个相机的设置与其他相机相同

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        camera.CopyFrom(Camera.main);
    }
}

Camera.cullingMask 消隐遮罩
这个用来选择性的渲染部分场景

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //只渲染在第一层中的物体(默认层)
        camera.cullingMask = 1 << 0;// 1/1
    }
}

Camera.current 当前相机
当前用于渲染的相机,只用于低级的渲染控制

Camera.depth 深度
相机在渲染顺序上的深度

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //设置这个相机在主相机之后渲染
        camera.depth = Camera.main.depth + 1;
    }
}

Camera.depthTextureMode 深度纹理模式
相机生成怎样的一个深度纹理

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //生成一个深度+法线纹理
        camera.depthTextureMode = DepthTextureMode.DepthNormals;
    }
}

Camera.eventMask 事件遮挡
遮挡相机的触发事件图层

正如cullingMask确定相机是否能够看到游戏对象,事件掩遮挡决定游戏物体是否能够接收鼠标事件。只有相机可见的对象,并且该对象遮挡层与相机的 eventMask 重叠,能够接收 OnMouseXXX 事件

Camera.farClipPlane 远裁剪平面
远裁剪面的距离

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {
        camera.farClipPlane = 100.0F;
    }
}

Camera.fieldOfView 固定视野
相机的视野,以度为单位

例一

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //设置附加到同一个游戏物体上相机的视野为60
        camera.fieldOfView = 60;
    }
}

例二
使用专门主相机

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //设置主相机的视野为 80
        Camera.main.fieldOfView = 80;
    }
}

Camera.GetAllCameras 获取所有相机
用当前场景中的摄像机填补相机的数组,而不需要分配一个新的数组
数组的大小必须大于allCamerasCount的值

Camera.GetCommandBuffers
Get命令缓冲区执行在指定的地方

Camera.hdr
这款相机使用HDR渲染吗?

Camera.layerCullDistances 层消隐距离
每层的消隐距离

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void Start() 
    {
        float[] distances = new float[32];
        //设置层10的消隐为15米距离,其他所有层使用远剪裁屏幕距离
        distances[10] = 15;
        camera.layerCullDistances = distances;
    }
}

Camera.layerCullSpherical 球面层消隐
通常这种类型的消隐是通过移动相机的远平面接近眼睛执行。通过将该值设置为true,基于球面距离消隐。好处是,在原地旋转不影响可见对象

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    void Example() {
        camera.layerCullSpherical = true;
    }
}

Camera.main 主相机
第一个启用的被标记为“MainCanmera”的相机

Camera.nearClipPlane 近裁剪平面
近裁剪面的距离

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {
        camera.nearClipPlane = 0.1F;
    }
}

Camera.OnPostRender 在渲染之后
在相机渲染场景之后调用

这个脚本让你在每个相机开启/禁用雾效
在检视面板开启或禁用这个脚本
在每个相机可以开启/禁用雾效

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    private bool revertFogState = false;
    void OnPreRender() 
    {
        revertFogState = RenderSettings.fog;
        RenderSettings.fog = enabled;
    }
    void OnPostRender() 
    {
        RenderSettings.fog = revertFogState;
    }
}

Camera.OnPreCull 在消隐之前
OnPreCull在相机开始裁剪场景之前调用

附加这个到相机
反转相机中的物体,因此每个被渲染的物体是反的(**??)

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    void OnPreCull() 
    {
        camera.ResetWorldToCameraMatrix();
        camera.ResetProjectionMatrix();
        camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(new Vector3(1, -1, 1));
    }
    void OnPreRender() 
    {   //设置为true,因此可以看到翻转的物体
        GL.SetRevertBackfacing(true);
    }
    void OnPostRender() 
    {   //设置为false,因为不想影响所有其他相机
        GL.SetRevertBackfacing(false);
    }
}

Camera.OnPreRender 在渲染之前
OnPreRender在相机开始渲染场景之前调用

这个脚本让你在每个相机开启/禁用雾效
在检视面板开启或禁用这个脚本
在每个相机可以开启/禁用雾效

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    private bool revertFogState = false;
    void OnPreRender() 
    {
        revertFogState = RenderSettings.fog;
        RenderSettings.fog = enabled;
    }
    void OnPostRender() 
    {
        RenderSettings.fog = revertFogState;
    }
}

Camera.OnRenderImage 在渲染图像之后
OnRenderImage在所有渲染完成后被调用,来渲染图片的后期处理效果

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Material mat;
    void OnRenderImage(RenderTexture src, RenderTexture dest) {
        Graphics.Blit(src, dest, mat);
    }
}

Camera.OnRenderObject 在渲染物体之后
OnRenderObject 被用来渲染你自己的物体,使用或者其他函数

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour {
    public Mesh mainMesh;
    public Mesh miniMapMesh;
    void OnRenderObject() {
        if (Camera.current.name == "MiniMapcam")
            Graphics.DrawMeshNow(miniMapMesh, transform.position, transform.rotation);
        else
            Graphics.DrawMeshNow(mainMesh, transform.position, transform.rotation);
    }
}

Camera.OnWillRenderObject 在渲染物体之前
如果物体可见,每个相机都会调用OnWillRenderObject

增加otherObject的大小同时这个变换正在渲染
注意这个将被调用即使场景编辑器显示这个物体
因此,请确保在游戏视图看不到的物体,不在场景编辑器

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public GameObject otherObject;
    void OnWillRenderObject() 
    {
        otherObject.transform.localScale *= 1.0001F;
    }
}

Camera.opaqueSortMode
不透明的对象排序模式

不透明的对象是按不同的标准排序(排序层,材质队列, 材料、距离、以及材质等)最大化两个CPU效率(减少数量 状态改变和提高绘制调用批处理),和GPU最大化效率 (许多gpu喜欢粗糙前后呈现以便更快的拒绝不可见 表面)

Camera.orthographic 正交
相机是正交的(true),是透视的(false)?

例一

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
    public void Awake() 
    {   //设置相机为正交
        camera.orthographic = true;
    }
}<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值