/// <summary> /// Info String drawn at the bottom of the Preview /// </summary> public override string GetInfoString() { UI_Gradient gradient = target as UI_Gradient; if (gradient == null) { return("Ooops, looks like something went wrong!"); } // Image size Text return(string.Format("Gradient Size: {0}x{1}", Mathf.RoundToInt(Mathf.Abs(gradient.rectTransform.rect.width)), Mathf.RoundToInt(Mathf.Abs(gradient.rectTransform.rect.height)))); }
/// <summary> /// Draw the Gradient preview. /// </summary> public override void OnPreviewGUI(Rect rect, GUIStyle background) { UI_Gradient gradient = target as UI_Gradient; if (gradient == null) { return; } Texture gradTexture = gradient.mainTexture; if (gradTexture == null) { return; } // Create the texture rectangle that is centered inside rect. Rect outerRect = rect; outerRect.width = Mathf.Abs(rect.width); outerRect.height = Mathf.Abs(rect.height); if (outerRect.width > 0f) { float f = rect.width / outerRect.width; outerRect.width *= f; outerRect.height *= f; } if (rect.height > outerRect.height) { outerRect.y += (rect.height - outerRect.height) * 0.5f; } else if (outerRect.height > rect.height) { float f = rect.height / outerRect.height; outerRect.width *= f; outerRect.height *= f; } if (rect.width > outerRect.width) { outerRect.x += (rect.width - outerRect.width) * 0.5f; } EditorGUI.DrawPreviewTexture(outerRect, gradTexture, gradient.material, ScaleMode.ScaleToFit, 1f); }