Exemple #1
0
        /// <summary>
        /// Convierte el objeto System.String actual en un objeto UnityEngine.Color, atendiendo a su representación en
        /// hexadecimal. La respresentación hexadecimal deberá tener al menos una longitud de 6, en cuyo caso se
        /// interpretarán los valores de los componentes R, G, y B del color. Si tiene dos caracteres más se intentará
        /// además obtener el componente alfa del color. La cadena de texto podrá empezar opcionalmente por "0x" o por
        /// "#" (estos prefijos serán simplemente ignorados). Si no se puede realizar la conversión, se devuelve el
        /// color especificado como alternativa.
        /// </summary>
        public static Color ToColorFromHex(this string s, Color fallback)
        {
            // Eliminación de prefijos comunes de definición de colores en hexadecimal
            s = s.Replace("0x", string.Empty);
            s = s.Replace("#", string.Empty);

            #if (UNITY_5 || UNITY_4)
            // Convertir color de respaldo a bytes
            global::UnityEngine.Color32 fallback32 = (global::UnityEngine.Color32)fallback;

            // Intentar conversión
            if (s.Length >= 6)
            {
                byte a = byte.MaxValue;
                byte r = ColorExtensions.TryParseByte(s.Substring(0, 2), fallback32.r);
                byte g = ColorExtensions.TryParseByte(s.Substring(2, 2), fallback32.g);
                byte b = ColorExtensions.TryParseByte(s.Substring(4, 2), fallback32.b);

                if (s.Length > 7)
                {
                    a = ColorExtensions.TryParseByte(s.Substring(6, 2), byte.MaxValue);
                }

                return(new global::UnityEngine.Color32(r, g, b, a));
            }
            else
            {
                return(fallback);
            }
            #else
            // Intentar conversión
            if (s.Length >= 6)
            {
                byte a = byte.MaxValue;
                byte r = ColorExtensions.TryParseByte(s.Substring(0, 2), fallback.R);
                byte g = ColorExtensions.TryParseByte(s.Substring(2, 2), fallback.G);
                byte b = ColorExtensions.TryParseByte(s.Substring(4, 2), fallback.B);

                if (s.Length > 7)
                {
                    a = ColorExtensions.TryParseByte(s.Substring(6, 2), byte.MaxValue);
                }

                return(Color.FromArgb(a, r, g, b));
            }
            else
            {
                return(fallback);
            }
            #endif
        }
Exemple #2
0
    // Token: 0x060000C9 RID: 201 RVA: 0x00008D80 File Offset: 0x00006F80
    private global::SteamVR_RenderModel.RenderModel LoadRenderModel(global::Valve.VR.CVRRenderModels renderModels, string renderModelName, string baseName)
    {
        global::System.IntPtr zero = global::System.IntPtr.Zero;
        global::Valve.VR.EVRRenderModelError evrrenderModelError;
        for (;;)
        {
            evrrenderModelError = renderModels.LoadRenderModel_Async(renderModelName, ref zero);
            bool flag = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
            if (flag)
            {
                break;
            }
            global::System.Threading.Thread.Sleep(1);
        }
        bool flag2 = evrrenderModelError > global::Valve.VR.EVRRenderModelError.None;

        global::SteamVR_RenderModel.RenderModel result;
        if (flag2)
        {
            global::UnityEngine.Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, evrrenderModelError.ToString()));
            result = null;
        }
        else
        {
            global::Valve.VR.RenderModel_t renderModel_t  = (global::Valve.VR.RenderModel_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(zero, typeof(global::Valve.VR.RenderModel_t));
            global::UnityEngine.Vector3[]  array          = new global::UnityEngine.Vector3[renderModel_t.unVertexCount];
            global::UnityEngine.Vector3[]  array2         = new global::UnityEngine.Vector3[renderModel_t.unVertexCount];
            global::UnityEngine.Vector2[]  array3         = new global::UnityEngine.Vector2[renderModel_t.unVertexCount];
            global::System.Type            typeFromHandle = typeof(global::Valve.VR.RenderModel_Vertex_t);
            int num = 0;
            while ((long)num < (long)((ulong)renderModel_t.unVertexCount))
            {
                global::System.IntPtr intPtr;
                intPtr..ctor(renderModel_t.rVertexData.ToInt64() + (long)(num * global::System.Runtime.InteropServices.Marshal.SizeOf(typeFromHandle)));
                global::Valve.VR.RenderModel_Vertex_t renderModel_Vertex_t = (global::Valve.VR.RenderModel_Vertex_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(intPtr, typeFromHandle);
                array[num]  = new global::UnityEngine.Vector3(renderModel_Vertex_t.vPosition.v0, renderModel_Vertex_t.vPosition.v1, -renderModel_Vertex_t.vPosition.v2);
                array2[num] = new global::UnityEngine.Vector3(renderModel_Vertex_t.vNormal.v0, renderModel_Vertex_t.vNormal.v1, -renderModel_Vertex_t.vNormal.v2);
                array3[num] = new global::UnityEngine.Vector2(renderModel_Vertex_t.rfTextureCoord0, renderModel_Vertex_t.rfTextureCoord1);
                num++;
            }
            int     num2   = (int)(renderModel_t.unTriangleCount * 3U);
            short[] array4 = new short[num2];
            global::System.Runtime.InteropServices.Marshal.Copy(renderModel_t.rIndexData, array4, 0, array4.Length);
            int[] array5 = new int[num2];
            int   num3   = 0;
            while ((long)num3 < (long)((ulong)renderModel_t.unTriangleCount))
            {
                array5[num3 * 3]     = (int)array4[num3 * 3 + 2];
                array5[num3 * 3 + 1] = (int)array4[num3 * 3 + 1];
                array5[num3 * 3 + 2] = (int)array4[num3 * 3];
                num3++;
            }
            global::UnityEngine.Mesh mesh = new global::UnityEngine.Mesh();
            mesh.vertices  = array;
            mesh.normals   = array2;
            mesh.uv        = array3;
            mesh.triangles = array5;
            mesh.Optimize();
            global::UnityEngine.Material material = global::SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] as global::UnityEngine.Material;
            bool flag3 = material == null || material.mainTexture == null;
            if (flag3)
            {
                global::System.IntPtr zero2 = global::System.IntPtr.Zero;
                for (;;)
                {
                    evrrenderModelError = renderModels.LoadTexture_Async(renderModel_t.diffuseTextureId, ref zero2);
                    bool flag4 = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
                    if (flag4)
                    {
                        break;
                    }
                    global::System.Threading.Thread.Sleep(1);
                }
                bool flag5 = evrrenderModelError == global::Valve.VR.EVRRenderModelError.None;
                if (flag5)
                {
                    global::Valve.VR.RenderModel_TextureMap_t renderModel_TextureMap_t = (global::Valve.VR.RenderModel_TextureMap_t)global::System.Runtime.InteropServices.Marshal.PtrToStructure(zero2, typeof(global::Valve.VR.RenderModel_TextureMap_t));
                    global::UnityEngine.Texture2D             texture2D = new global::UnityEngine.Texture2D((int)renderModel_TextureMap_t.unWidth, (int)renderModel_TextureMap_t.unHeight, 5, false);
                    bool flag6 = global::UnityEngine.SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL");
                    if (flag6)
                    {
                        byte[] array6 = new byte[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight * '\u0004')];
                        global::System.Runtime.InteropServices.Marshal.Copy(renderModel_TextureMap_t.rubTextureMapData, array6, 0, array6.Length);
                        global::UnityEngine.Color32[] array7 = new global::UnityEngine.Color32[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight)];
                        int num4 = 0;
                        for (int i = 0; i < (int)renderModel_TextureMap_t.unHeight; i++)
                        {
                            for (int j = 0; j < (int)renderModel_TextureMap_t.unWidth; j++)
                            {
                                byte b  = array6[num4++];
                                byte b2 = array6[num4++];
                                byte b3 = array6[num4++];
                                byte b4 = array6[num4++];
                                array7[i * (int)renderModel_TextureMap_t.unWidth + j] = new global::UnityEngine.Color32(b, b2, b3, b4);
                            }
                        }
                        texture2D.SetPixels32(array7);
                        texture2D.Apply();
                    }
                    else
                    {
                        texture2D.Apply();
                        for (;;)
                        {
                            evrrenderModelError = renderModels.LoadIntoTextureD3D11_Async(renderModel_t.diffuseTextureId, texture2D.GetNativeTexturePtr());
                            bool flag7 = evrrenderModelError != global::Valve.VR.EVRRenderModelError.Loading;
                            if (flag7)
                            {
                                break;
                            }
                            global::System.Threading.Thread.Sleep(1);
                        }
                    }
                    material             = new global::UnityEngine.Material((this.shader != null) ? this.shader : global::EscalationVR.UnityHelper.GetShader("Standard"));
                    material.mainTexture = texture2D;
                    global::SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] = material;
                    renderModels.FreeTexture(zero2);
                }
                else
                {
                    global::UnityEngine.Debug.Log("Failed to load render model texture for render model " + renderModelName);
                }
            }
            base.StartCoroutine(this.FreeRenderModel(zero));
            result = new global::SteamVR_RenderModel.RenderModel(mesh, material);
        }
        return(result);
    }