123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530 |
- using UnityEngine;
- using System.Collections;
- namespace TMPro.Examples
- {
- public class TMP_TextInfoDebugTool : MonoBehaviour
- {
- // Since this script is used for debugging, we exclude it from builds.
- // TODO: Rework this script to make it into an editor utility.
- #if UNITY_EDITOR
- public bool ShowCharacters;
- public bool ShowWords;
- public bool ShowLinks;
- public bool ShowLines;
- public bool ShowMeshBounds;
- public bool ShowTextBounds;
- [Space(10)]
- [TextArea(2, 2)]
- public string ObjectStats;
- [SerializeField]
- private TMP_Text m_TextComponent;
- [SerializeField]
- private Transform m_Transform;
- void OnDrawGizmos()
- {
- if (m_TextComponent == null)
- {
- m_TextComponent = gameObject.GetComponent<TMP_Text>();
- if (m_TextComponent == null)
- return;
- if (m_Transform == null)
- m_Transform = gameObject.GetComponent<Transform>();
- }
- // Update Text Statistics
- TMP_TextInfo textInfo = m_TextComponent.textInfo;
- ObjectStats = "Characters: " + textInfo.characterCount + " Words: " + textInfo.wordCount + " Spaces: " + textInfo.spaceCount + " Sprites: " + textInfo.spriteCount + " Links: " + textInfo.linkCount
- + "\nLines: " + textInfo.lineCount + " Pages: " + textInfo.pageCount;
- // Draw Quads around each of the Characters
- #region Draw Characters
- if (ShowCharacters)
- DrawCharactersBounds();
- #endregion
- // Draw Quads around each of the words
- #region Draw Words
- if (ShowWords)
- DrawWordBounds();
- #endregion
- // Draw Quads around each of the words
- #region Draw Links
- if (ShowLinks)
- DrawLinkBounds();
- #endregion
- // Draw Quads around each line
- #region Draw Lines
- if (ShowLines)
- DrawLineBounds();
- #endregion
- // Draw Quad around the bounds of the text
- #region Draw Bounds
- if (ShowMeshBounds)
- DrawBounds();
- #endregion
- // Draw Quad around the rendered region of the text.
- #region Draw Text Bounds
- if (ShowTextBounds)
- DrawTextBounds();
- #endregion
- }
- /// <summary>
- /// Method to draw a rectangle around each character.
- /// </summary>
- /// <param name="text"></param>
- void DrawCharactersBounds()
- {
- TMP_TextInfo textInfo = m_TextComponent.textInfo;
- for (int i = 0; i < textInfo.characterCount; i++)
- {
- // Draw visible as well as invisible characters
- TMP_CharacterInfo cInfo = textInfo.characterInfo[i];
- bool isCharacterVisible = i >= m_TextComponent.maxVisibleCharacters ||
- cInfo.lineNumber >= m_TextComponent.maxVisibleLines ||
- (m_TextComponent.overflowMode == TextOverflowModes.Page && cInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
- if (!isCharacterVisible) continue;
- // Get Bottom Left and Top Right position of the current character
- Vector3 bottomLeft = m_Transform.TransformPoint(cInfo.bottomLeft);
- Vector3 topLeft = m_Transform.TransformPoint(new Vector3(cInfo.topLeft.x, cInfo.topLeft.y, 0));
- Vector3 topRight = m_Transform.TransformPoint(cInfo.topRight);
- Vector3 bottomRight = m_Transform.TransformPoint(new Vector3(cInfo.bottomRight.x, cInfo.bottomRight.y, 0));
- Color color = cInfo.isVisible ? Color.yellow : Color.grey;
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, color);
- // Baseline
- Vector3 baselineStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, cInfo.baseLine, 0)).y, 0);
- Vector3 baselineEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, cInfo.baseLine, 0)).y, 0);
- Gizmos.color = Color.cyan;
- Gizmos.DrawLine(baselineStart, baselineEnd);
- // Draw Ascender & Descender for each character.
- Vector3 ascenderStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, cInfo.ascender, 0)).y, 0);
- Vector3 ascenderEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, cInfo.ascender, 0)).y, 0);
- Vector3 descenderStart = new Vector3(bottomLeft.x, m_Transform.TransformPoint(new Vector3(0, cInfo.descender, 0)).y, 0);
- Vector3 descenderEnd = new Vector3(bottomRight.x, m_Transform.TransformPoint(new Vector3(0, cInfo.descender, 0)).y, 0);
- Gizmos.color = Color.cyan;
- Gizmos.DrawLine(ascenderStart, ascenderEnd);
- Gizmos.DrawLine(descenderStart, descenderEnd);
- // Draw Cap Height
- float capHeight = cInfo.baseLine + cInfo.fontAsset.faceInfo.capLine * cInfo.scale;
- Vector3 capHeightStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, capHeight, 0)).y, 0);
- Vector3 capHeightEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, capHeight, 0)).y, 0);
- Gizmos.color = Color.cyan;
- Gizmos.DrawLine(capHeightStart, capHeightEnd);
- // Draw Centerline
- float meanline = cInfo.baseLine + cInfo.fontAsset.faceInfo.meanLine * cInfo.scale;
- Vector3 centerlineStart = new Vector3(topLeft.x, m_Transform.TransformPoint(new Vector3(0, meanline, 0)).y, 0);
- Vector3 centerlineEnd = new Vector3(topRight.x, m_Transform.TransformPoint(new Vector3(0, meanline, 0)).y, 0);
- Gizmos.color = Color.cyan;
- Gizmos.DrawLine(centerlineStart, centerlineEnd);
- // Draw Origin for each character.
- float gizmoSize = (ascenderEnd.y - descenderEnd.y) * 0.02f;
- Vector3 origin = m_Transform.TransformPoint(cInfo.origin, cInfo.baseLine, 0);
- Vector3 originBL = new Vector3(origin.x - gizmoSize, origin.y - gizmoSize, 0);
- Vector3 originTL = new Vector3(originBL.x, origin.y + gizmoSize, 0);
- Vector3 originTR = new Vector3(origin.x + gizmoSize, originTL.y, 0);
- Vector3 originBR = new Vector3(originTR.x, originBL.y, 0);
- Gizmos.color = new Color(1, 0.5f, 0);
- Gizmos.DrawLine(originBL, originTL);
- Gizmos.DrawLine(originTL, originTR);
- Gizmos.DrawLine(originTR, originBR);
- Gizmos.DrawLine(originBR, originBL);
- // Draw xAdvance for each character.
- gizmoSize = (ascenderEnd.y - descenderEnd.y) * 0.04f;
- float xAdvance = m_Transform.TransformPoint(cInfo.xAdvance, 0, 0).x;
- Vector3 topAdvance = new Vector3(xAdvance, baselineStart.y + gizmoSize, 0);
- Vector3 bottomAdvance = new Vector3(xAdvance, baselineStart.y - gizmoSize, 0);
- Vector3 leftAdvance = new Vector3(xAdvance - gizmoSize, baselineStart.y, 0);
- Vector3 rightAdvance = new Vector3(xAdvance + gizmoSize, baselineStart.y, 0);
- Gizmos.color = Color.green;
- Gizmos.DrawLine(topAdvance, bottomAdvance);
- Gizmos.DrawLine(leftAdvance, rightAdvance);
- }
- }
- /// <summary>
- /// Method to draw rectangles around each word of the text.
- /// </summary>
- /// <param name="text"></param>
- void DrawWordBounds()
- {
- TMP_TextInfo textInfo = m_TextComponent.textInfo;
- for (int i = 0; i < textInfo.wordCount; i++)
- {
- TMP_WordInfo wInfo = textInfo.wordInfo[i];
- bool isBeginRegion = false;
- Vector3 bottomLeft = Vector3.zero;
- Vector3 topLeft = Vector3.zero;
- Vector3 bottomRight = Vector3.zero;
- Vector3 topRight = Vector3.zero;
- float maxAscender = -Mathf.Infinity;
- float minDescender = Mathf.Infinity;
- Color wordColor = Color.green;
- // Iterate through each character of the word
- for (int j = 0; j < wInfo.characterCount; j++)
- {
- int characterIndex = wInfo.firstCharacterIndex + j;
- TMP_CharacterInfo currentCharInfo = textInfo.characterInfo[characterIndex];
- int currentLine = currentCharInfo.lineNumber;
- bool isCharacterVisible = characterIndex > m_TextComponent.maxVisibleCharacters ||
- currentCharInfo.lineNumber > m_TextComponent.maxVisibleLines ||
- (m_TextComponent.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
- // Track Max Ascender and Min Descender
- maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender);
- minDescender = Mathf.Min(minDescender, currentCharInfo.descender);
- if (isBeginRegion == false && isCharacterVisible)
- {
- isBeginRegion = true;
- bottomLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
- topLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);
- //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]");
- // If Word is one character
- if (wInfo.characterCount == 1)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- }
- }
- // Last Character of Word
- if (isBeginRegion && j == wInfo.characterCount - 1)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- }
- // If Word is split on more than one line.
- else if (isBeginRegion && currentLine != textInfo.characterInfo[characterIndex + 1].lineNumber)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, wordColor);
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- maxAscender = -Mathf.Infinity;
- minDescender = Mathf.Infinity;
- }
- }
- //Debug.Log(wInfo.GetWord(m_TextMeshPro.textInfo.characterInfo));
- }
- }
- /// <summary>
- /// Draw rectangle around each of the links contained in the text.
- /// </summary>
- /// <param name="text"></param>
- void DrawLinkBounds()
- {
- TMP_TextInfo textInfo = m_TextComponent.textInfo;
- for (int i = 0; i < textInfo.linkCount; i++)
- {
- TMP_LinkInfo linkInfo = textInfo.linkInfo[i];
- bool isBeginRegion = false;
- Vector3 bottomLeft = Vector3.zero;
- Vector3 topLeft = Vector3.zero;
- Vector3 bottomRight = Vector3.zero;
- Vector3 topRight = Vector3.zero;
- float maxAscender = -Mathf.Infinity;
- float minDescender = Mathf.Infinity;
- Color32 linkColor = Color.cyan;
- // Iterate through each character of the link text
- for (int j = 0; j < linkInfo.linkTextLength; j++)
- {
- int characterIndex = linkInfo.linkTextfirstCharacterIndex + j;
- TMP_CharacterInfo currentCharInfo = textInfo.characterInfo[characterIndex];
- int currentLine = currentCharInfo.lineNumber;
- bool isCharacterVisible = characterIndex > m_TextComponent.maxVisibleCharacters ||
- currentCharInfo.lineNumber > m_TextComponent.maxVisibleLines ||
- (m_TextComponent.overflowMode == TextOverflowModes.Page && currentCharInfo.pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
- // Track Max Ascender and Min Descender
- maxAscender = Mathf.Max(maxAscender, currentCharInfo.ascender);
- minDescender = Mathf.Min(minDescender, currentCharInfo.descender);
- if (isBeginRegion == false && isCharacterVisible)
- {
- isBeginRegion = true;
- bottomLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.descender, 0);
- topLeft = new Vector3(currentCharInfo.bottomLeft.x, currentCharInfo.ascender, 0);
- //Debug.Log("Start Word Region at [" + currentCharInfo.character + "]");
- // If Link is one character
- if (linkInfo.linkTextLength == 1)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- }
- }
- // Last Character of Link
- if (isBeginRegion && j == linkInfo.linkTextLength - 1)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- }
- // If Link is split on more than one line.
- else if (isBeginRegion && currentLine != textInfo.characterInfo[characterIndex + 1].lineNumber)
- {
- isBeginRegion = false;
- topLeft = m_Transform.TransformPoint(new Vector3(topLeft.x, maxAscender, 0));
- bottomLeft = m_Transform.TransformPoint(new Vector3(bottomLeft.x, minDescender, 0));
- bottomRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, minDescender, 0));
- topRight = m_Transform.TransformPoint(new Vector3(currentCharInfo.topRight.x, maxAscender, 0));
- // Draw Region
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, linkColor);
- maxAscender = -Mathf.Infinity;
- minDescender = Mathf.Infinity;
- //Debug.Log("End Word Region at [" + currentCharInfo.character + "]");
- }
- }
- //Debug.Log(wInfo.GetWord(m_TextMeshPro.textInfo.characterInfo));
- }
- }
- /// <summary>
- /// Draw Rectangles around each lines of the text.
- /// </summary>
- /// <param name="text"></param>
- void DrawLineBounds()
- {
- TMP_TextInfo textInfo = m_TextComponent.textInfo;
- for (int i = 0; i < textInfo.lineCount; i++)
- {
- TMP_LineInfo lineInfo = textInfo.lineInfo[i];
- bool isLineVisible = (lineInfo.characterCount == 1 && textInfo.characterInfo[lineInfo.firstCharacterIndex].character == 10) ||
- i > m_TextComponent.maxVisibleLines ||
- (m_TextComponent.overflowMode == TextOverflowModes.Page && textInfo.characterInfo[lineInfo.firstCharacterIndex].pageNumber + 1 != m_TextComponent.pageToDisplay) ? false : true;
- if (!isLineVisible) continue;
- //if (!ShowLinesOnlyVisibleCharacters)
- //{
- // Get Bottom Left and Top Right position of each line
- float ascender = lineInfo.ascender;
- float descender = lineInfo.descender;
- float baseline = lineInfo.baseline;
- float maxAdvance = lineInfo.maxAdvance;
- Vector3 bottomLeft = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].bottomLeft.x, descender, 0));
- Vector3 topLeft = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].bottomLeft.x, ascender, 0));
- Vector3 topRight = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastCharacterIndex].topRight.x, ascender, 0));
- Vector3 bottomRight = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastCharacterIndex].topRight.x, descender, 0));
- DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, Color.green);
- Vector3 bottomOrigin = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].origin, descender, 0));
- Vector3 topOrigin = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].origin, ascender, 0));
- Vector3 bottomAdvance = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].origin + maxAdvance, descender, 0));
- Vector3 topAdvance = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].origin + maxAdvance, ascender, 0));
- DrawDottedRectangle(bottomOrigin, topOrigin, topAdvance, bottomAdvance, Color.green);
- Vector3 baselineStart = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstCharacterIndex].bottomLeft.x, baseline, 0));
- Vector3 baselineEnd = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastCharacterIndex].topRight.x, baseline, 0));
- Gizmos.color = Color.cyan;
- Gizmos.DrawLine(baselineStart, baselineEnd);
- // Draw LineExtents
- Gizmos.color = Color.grey;
- Gizmos.DrawLine(m_Transform.TransformPoint(lineInfo.lineExtents.min), m_Transform.TransformPoint(lineInfo.lineExtents.max));
- //}
- //else
- //{
- //// Get Bottom Left and Top Right position of each line
- //float ascender = lineInfo.ascender;
- //float descender = lineInfo.descender;
- //Vector3 bottomLeft = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstVisibleCharacterIndex].bottomLeft.x, descender, 0));
- //Vector3 topLeft = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstVisibleCharacterIndex].bottomLeft.x, ascender, 0));
- //Vector3 topRight = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastVisibleCharacterIndex].topRight.x, ascender, 0));
- //Vector3 bottomRight = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastVisibleCharacterIndex].topRight.x, descender, 0));
- //DrawRectangle(bottomLeft, topLeft, topRight, bottomRight, Color.green);
- //Vector3 baselineStart = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.firstVisibleCharacterIndex].bottomLeft.x, textInfo.characterInfo[lineInfo.firstVisibleCharacterIndex].baseLine, 0));
- //Vector3 baselineEnd = m_Transform.TransformPoint(new Vector3(textInfo.characterInfo[lineInfo.lastVisibleCharacterIndex].topRight.x, textInfo.characterInfo[lineInfo.lastVisibleCharacterIndex].baseLine, 0));
- //Gizmos.color = Color.cyan;
- //Gizmos.DrawLine(baselineStart, baselineEnd);
- //}
- }
- }
- /// <summary>
- /// Draw Rectangle around the bounds of the text object.
- /// </summary>
- void DrawBounds()
- {
- Bounds meshBounds = m_TextComponent.bounds;
-
- // Get Bottom Left and Top Right position of each word
- Vector3 bottomLeft = m_TextComponent.transform.position + (meshBounds.center - meshBounds.extents);
- Vector3 topRight = m_TextComponent.transform.position + (meshBounds.center + meshBounds.extents);
- DrawRectangle(bottomLeft, topRight, new Color(1, 0.5f, 0));
- }
- void DrawTextBounds()
- {
- Bounds textBounds = m_TextComponent.textBounds;
- Vector3 bottomLeft = m_TextComponent.transform.position + (textBounds.center - textBounds.extents);
- Vector3 topRight = m_TextComponent.transform.position + (textBounds.center + textBounds.extents);
- DrawRectangle(bottomLeft, topRight, new Color(0f, 0.5f, 0.5f));
- }
- // Draw Rectangles
- void DrawRectangle(Vector3 BL, Vector3 TR, Color color)
- {
- Gizmos.color = color;
- Gizmos.DrawLine(new Vector3(BL.x, BL.y, 0), new Vector3(BL.x, TR.y, 0));
- Gizmos.DrawLine(new Vector3(BL.x, TR.y, 0), new Vector3(TR.x, TR.y, 0));
- Gizmos.DrawLine(new Vector3(TR.x, TR.y, 0), new Vector3(TR.x, BL.y, 0));
- Gizmos.DrawLine(new Vector3(TR.x, BL.y, 0), new Vector3(BL.x, BL.y, 0));
- }
- // Draw Rectangles
- void DrawRectangle(Vector3 bl, Vector3 tl, Vector3 tr, Vector3 br, Color color)
- {
- Gizmos.color = color;
- Gizmos.DrawLine(bl, tl);
- Gizmos.DrawLine(tl, tr);
- Gizmos.DrawLine(tr, br);
- Gizmos.DrawLine(br, bl);
- }
- // Draw Rectangles
- void DrawDottedRectangle(Vector3 bl, Vector3 tl, Vector3 tr, Vector3 br, Color color)
- {
- var cam = Camera.current;
- float dotSpacing = (cam.WorldToScreenPoint(br).x - cam.WorldToScreenPoint(bl).x) / 75f;
- UnityEditor.Handles.color = color;
- UnityEditor.Handles.DrawDottedLine(bl, tl, dotSpacing);
- UnityEditor.Handles.DrawDottedLine(tl, tr, dotSpacing);
- UnityEditor.Handles.DrawDottedLine(tr, br, dotSpacing);
- UnityEditor.Handles.DrawDottedLine(br, bl, dotSpacing);
- }
- #endif
- }
- }
|