コード例 #1
0
    void Start()
    {
        _fontImage = new Texture2D(128, 128);
        _fontImage.LoadImage(_fontImageData);
        _fontImage.filterMode = 0;
        _fontImage.wrapMode   = (TextureWrapMode)1;
        _fontImage.hideFlags  = (HideFlags)13;
        var material = new Material("Shader \"hDebug/Text\"\r\n                {\r\n                      Properties\r\n                      {\r\n                          _MainTex (\"Main\", 2D) = \"white\" {}\r\n                      }\r\n                      \r\n                      Category\r\n                      {\r\n                        Tags\r\n                        {\r\n                            \"Queue\" = \"Transparent\"\r\n                        }\r\n                        \r\n                        Blend SrcAlpha OneMinusSrcAlpha\r\n                        AlphaTest Greater .01\r\n                        ColorMask RGB\r\n                        Cull Off\r\n                        Lighting Off\r\n                        ZWrite On\r\n                        \r\n                        Fog\r\n                        {\r\n                            Color(0, 0, 0, 0)\r\n                        }\r\n                        \r\n                        BindChannels\r\n                        {\r\n                            Bind \"Color\", color\r\n                            Bind \"Vertex\", vertex\r\n                            Bind \"TexCoord\", texcoord\r\n                        }\r\n                        \r\n                        SubShader\r\n                        {\r\n                            Pass\r\n                            {\r\n                                SetTexture [_MainTex]\r\n                                {\r\n                                    combine texture * primary\r\n                                }\r\n                            }\r\n                        }\r\n                    }\r\n                }");

        material.mainTexture      = _fontImage;
        material.hideFlags        = (HideFlags)13;
        material.shader.hideFlags = (HideFlags)13;
        _fontMaterial             = material;
        _fontCamera = gameObject.AddComponent <Camera> () as Camera;
        _fontCamera.nearClipPlane       = 0.1f;
        _fontCamera.farClipPlane        = 1f;
        _fontCamera.clearFlags          = (CameraClearFlags)4;
        _fontCamera.depth               = 99f;
        _fontCamera.cullingMask         = 0;
        _fontCamera.useOcclusionCulling = false;
        _fontCamera.orthographic        = true;
        _glyphLeft   = new float[94];
        _glyphTop    = new float[94];
        _glyphRight  = new float[94];
        _glyphBottom = new float[94];
        int   num   = 0;
        int   num2  = 0;
        int   width = _fontImage.width;
        float num3  = 1f / (float)_fontImage.width;
        float num4  = 1f / (float)_fontImage.height;

        for (int i = 0; i < 94; i++)
        {
            _glyphLeft [i]    = (float)num;
            _glyphTop [i]     = (float)num2;
            _glyphRight [i]   = (float)(num + 8);
            _glyphBottom [i]  = (float)(num2 + 15);
            _glyphLeft [i]   *= num3;
            _glyphRight [i]  *= num3;
            _glyphTop [i]    *= num4;
            _glyphBottom [i] *= num4;
            _glyphTop [i]     = 1f - _glyphTop [i];
            _glyphBottom [i]  = 1f - _glyphBottom [i];
            num += 8;
            if (num == width)
            {
                num   = 0;
                num2 += 15;
            }
        }
        _whiteUV = hDebug.UVRectangle.CreateFromTexture(3, 5, 1, 1, _fontImage.width, _fontImage.height);
    }
コード例 #2
0
ファイル: hDebug.cs プロジェクト: CreatureSurvive/Hydrogen
 void Start()
 {
     _fontImage = new Texture2D (128, 128);
             _fontImage.LoadImage (_fontImageData);
             _fontImage.filterMode = 0;
             _fontImage.wrapMode = (TextureWrapMode)1;
             _fontImage.hideFlags = (HideFlags)13;
             var material = new Material ("Shader \"hDebug/Text\"\r\n                {\r\n                      Properties\r\n                      {\r\n                          _MainTex (\"Main\", 2D) = \"white\" {}\r\n                      }\r\n                      \r\n                      Category\r\n                      {\r\n                        Tags\r\n                        {\r\n                            \"Queue\" = \"Transparent\"\r\n                        }\r\n                        \r\n                        Blend SrcAlpha OneMinusSrcAlpha\r\n                        AlphaTest Greater .01\r\n                        ColorMask RGB\r\n                        Cull Off\r\n                        Lighting Off\r\n                        ZWrite On\r\n                        \r\n                        Fog\r\n                        {\r\n                            Color(0, 0, 0, 0)\r\n                        }\r\n                        \r\n                        BindChannels\r\n                        {\r\n                            Bind \"Color\", color\r\n                            Bind \"Vertex\", vertex\r\n                            Bind \"TexCoord\", texcoord\r\n                        }\r\n                        \r\n                        SubShader\r\n                        {\r\n                            Pass\r\n                            {\r\n                                SetTexture [_MainTex]\r\n                                {\r\n                                    combine texture * primary\r\n                                }\r\n                            }\r\n                        }\r\n                    }\r\n                }");
             material.mainTexture = _fontImage;
             material.hideFlags = (HideFlags)13;
             material.shader.hideFlags = (HideFlags)13;
             _fontMaterial = material;
             _fontCamera = gameObject.AddComponent<Camera> () as Camera;
             _fontCamera.nearClipPlane = 0.1f;
             _fontCamera.farClipPlane = 1f;
             _fontCamera.clearFlags = (CameraClearFlags)4;
             _fontCamera.depth = 99f;
             _fontCamera.cullingMask = 0;
             _fontCamera.useOcclusionCulling = false;
             _fontCamera.orthographic = true;
             _glyphLeft = new float[94];
             _glyphTop = new float[94];
             _glyphRight = new float[94];
             _glyphBottom = new float[94];
             int num = 0;
             int num2 = 0;
             int width = _fontImage.width;
             float num3 = 1f / (float)_fontImage.width;
             float num4 = 1f / (float)_fontImage.height;
             for (int i = 0; i < 94; i++) {
                     _glyphLeft [i] = (float)num;
                     _glyphTop [i] = (float)num2;
                     _glyphRight [i] = (float)(num + 8);
                     _glyphBottom [i] = (float)(num2 + 15);
                     _glyphLeft [i] *= num3;
                     _glyphRight [i] *= num3;
                     _glyphTop [i] *= num4;
                     _glyphBottom [i] *= num4;
                     _glyphTop [i] = 1f - _glyphTop [i];
                     _glyphBottom [i] = 1f - _glyphBottom [i];
                     num += 8;
                     if (num == width) {
                             num = 0;
                             num2 += 15;
                     }
             }
             _whiteUV = hDebug.UVRectangle.CreateFromTexture (3, 5, 1, 1, _fontImage.width, _fontImage.height);
 }