コード例 #1
0
    void CreateSphere(Cubemap _texture, Vector3 pos)
    {
        GameObject go   = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        GameObject temp = new GameObject(_texture.ToString());

        spheres.Add(go.transform);
        go.transform.SetParent(temp.transform);
        Transform t = temp.GetComponent <Transform> ();

        t.localScale = Vector3.one * scale;
        MeshRenderer mr  = go.GetComponent <MeshRenderer> ();
        Material     mat = new Material(_shader);

        Cubemap tex = null;

        tex = new Cubemap(_texture.width, TextureFormat.ARGB32, false);
        Color[][] pixels = new Color[6][];
        if (!getPixel)
        {
            for (int i = 0; i < 6; i++)
            {
                pixels [i] = new Color[_texture.width * _texture.width];
                pixels [i] = _texture.GetPixels(cubemapFaces [i]);
                tex.SetPixels(pixels [i], cubemapFaces [i]);
            }
        }
        else
        {
            for (int ii = 0; ii < 6; ii++)
            {
                pixels [ii] = new Color[_texture.width * _texture.width];
                int i = 0;
                for (int y = 0; y < _texture.width; y++)
                {
                    for (int x = 0; x < _texture.width; x++)
                    {
                        pixels [ii] [i] = _texture.GetPixel(cubemapFaces [ii], x, y);
                        i++;
                    }
                }
                tex.SetPixels(pixels [ii], cubemapFaces [ii]);
            }
        }
        //tex.SetPixels (pixels);
        tex.Apply();
        LabelMaker.MakeLabel(_texture.name.ToString().Remove(0, 5), Color.white, t);
        tex.filterMode  = FilterMode.Point;
        mat.mainTexture = tex;
        mat.name        = _texture.name;
        go.name         = _texture.name;
        mr.material     = mat;
        tex.wrapMode    = TextureWrapMode.Clamp;
        tex.Apply();
        t.SetParent(transform);
        t.position = pos;
    }