UnityEditor.PackageImport.DrawTexture C# (CSharp) Method

DrawTexture() public static method

public static DrawTexture ( Rect r, Texture2D tex, bool useDropshadow ) : void
r UnityEngine.Rect
tex UnityEngine.Texture2D
useDropshadow bool
return void
        public static void DrawTexture(Rect r, Texture2D tex, bool useDropshadow)
        {
            if (tex != null)
            {
                float width = tex.width;
                float height = tex.height;
                if ((width >= height) && (width > r.width))
                {
                    height = (height * r.width) / width;
                    width = r.width;
                }
                else if ((height > width) && (height > r.height))
                {
                    width = (width * r.height) / height;
                    height = r.height;
                }
                float x = r.x + Mathf.Round((r.width - width) / 2f);
                float y = r.y + Mathf.Round((r.height - height) / 2f);
                r = new Rect(x, y, width, height);
                if (useDropshadow && (Event.current.type == EventType.Repaint))
                {
                    Rect position = new RectOffset(1, 1, 1, 1).Remove(ms_Constants.textureIconDropShadow.border.Add(r));
                    ms_Constants.textureIconDropShadow.Draw(position, GUIContent.none, false, false, false, false);
                }
                GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit, true);
            }
        }

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::DrawTexture