using UnityEngine; using System.Collections.Generic; namespace PixelCrushers.DialogueSystem.UnityGUI { /// /// Parameters for using GUI.DrawTexture[WithTexCoords]. /// [System.Serializable] public class GUIImageParams { /// /// The pixel offset and size of the image. If the width and height are zero, it uses the /// control's scaled rect size. /// public Rect pixelRect; /// /// The image to display. /// public Texture2D texture; /// /// If true, uses texCoords; otherwise scales according to scaleMode and imageAspect. /// public bool useTexCoords = false; /// /// The tex coords (in the range 0..1) of the source image. Used if useTexCoords is true. /// public Rect texCoords = new Rect(0, 0, 1, 1); /// /// The scale mode (if not using tex coords). /// public ScaleMode scaleMode = ScaleMode.ScaleToFit; /// /// If true, alpha blends the image. /// public bool alphaBlend = true; /// /// The color to tint the image. /// public Color color = Color.white; /// /// The aspect ratio for the source image. /// public float aspect = 0; /// /// Draws the image in the specified rect using full alpha. /// /// Rect. public void Draw(Rect rect) { Draw(rect, false, 1f); } /// /// Draw the specified rect, taking alpha into account. /// /// Rect. /// If set to true has alpha. /// Alpha value of color. public void Draw(Rect rect, bool hasAlpha, float alpha) { if (texture != null) { Color originalGuiColor = GUI.color; GUI.color = color; if (hasAlpha) GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, alpha); Rect imageRect = new Rect(rect.x + pixelRect.x, rect.y + pixelRect.y, Tools.ApproximatelyZero(pixelRect.width) ? rect.width : pixelRect.width, Tools.ApproximatelyZero(pixelRect.width) ? rect.height : pixelRect.height); if (useTexCoords) { GUI.DrawTextureWithTexCoords(imageRect, texture, texCoords, alphaBlend); } else { GUI.DrawTexture(imageRect, texture, scaleMode, alphaBlend, aspect); } //if (hasAlpha) GUI.color = originalGuiColor; } } } }