纹理skybox团结的颜色

时间:2016-11-25 09:34:07

标签: unity3d colors textures unity5 google-cardboard

我正在使用谷歌纸板。 在我的主场景中,我有一个天空盒,图像为纹理。 如何获得我正在寻找的像素的颜色? 天空盒是mainCamera的元素,是“Head”的孩子。 我还把GvrReticle作为头的孩子;它对我的目的有用吗? 感谢

1 个答案:

答案 0 :(得分:0)

基本上你等待帧的结束,以便相机渲染。然后,您将渲染的数据读入纹理并获得中心像素。

编辑请注意,如果您在中心呈现UI元素,则会显示UI元素颜色而不是背后的颜色。

private Texture2D tex;
public Color center;

void Awake()
{
    StartCoroutine(GetCenterPixel());
}


private void CreateTexture()
{
    tex = new Texture2D(1, 1, TextureFormat.RGB24, false);
}

private IEnumerator GetCenterPixel()
{
    CreateTexture();
    while (true)
    {
        yield return new WaitForEndOfFrame();
        tex.ReadPixels(new Rect(Screen.width / 2f, Screen.height / 2f, 1, 1), 0, 0);
        tex.Apply();
        center = tex.GetPixel(0,0);
    }
}
相关问题