UnityEditor.PackageImport.LoadTexture C# (CSharp) Method

LoadTexture() private static method

private static LoadTexture ( string filepath, Texture2D &texture ) : void
filepath string
texture UnityEngine.Texture2D
return void
        private static void LoadTexture(string filepath, ref Texture2D texture)
        {
            if (texture == null)
            {
                texture = new Texture2D(0x80, 0x80);
            }
            byte[] data = null;
            try
            {
                data = File.ReadAllBytes(filepath);
            }
            catch
            {
            }
            if (((filepath == string.Empty) || (data == null)) || !texture.LoadImage(data))
            {
                Color[] pixels = texture.GetPixels();
                for (int i = 0; i < pixels.Length; i++)
                {
                    pixels[i] = new Color(0.5f, 0.5f, 0.5f, 0f);
                }
                texture.SetPixels(pixels);
                texture.Apply();
            }
        }

Usage Example

コード例 #1
0
        private void TopArea()
        {
            if (PackageImport.s_PackageIcon == null && !string.IsNullOrEmpty(this.m_PackageIconPath))
            {
                PackageImport.LoadTexture(this.m_PackageIconPath, ref PackageImport.s_PackageIcon);
            }
            bool  flag   = PackageImport.s_PackageIcon != null;
            float height = (!flag) ? 52f : 84f;
            Rect  rect   = GUILayoutUtility.GetRect(base.position.width, height);

            GUI.Label(rect, GUIContent.none, PackageImport.ms_Constants.topBarBg);
            Rect position;

            if (flag)
            {
                Rect r = new Rect(rect.x + 10f, rect.y + 10f, 64f, 64f);
                PackageImport.DrawTexture(r, PackageImport.s_PackageIcon, true);
                position = new Rect(r.xMax + 10f, r.yMin, rect.width, r.height);
            }
            else
            {
                position = new Rect(rect.x + 5f, rect.yMin, rect.width, rect.height);
            }
            GUI.Label(position, this.m_PackageName, PackageImport.ms_Constants.title);
        }
All Usage Examples Of UnityEditor.PackageImport::LoadTexture