using System; using System.Collections; using System.Collections.Generic; using HyperlinkText; using UnityEngine.EventSystems; namespace UnityEngine.UI { [ExecuteInEditMode] public abstract class HyperTextBase : BaseMeshEffect, ICanvasRaycastFilter { private Canvas RootCanvas { get { Canvas result; if ((result = this._rootCanvas) == null) { result = (this._rootCanvas = base.GetComponentInParent()); } return result; } } protected Text text { get { Text result; if ((result = this.m_TextComp) == null) { result = (this.m_TextComp = base.GetComponent()); } return result; } } protected void RegisterClickable(int startIndex, int wordLength, string returnString, Color color, Action onClick, Action onEnter = null, Action onExit = null) { if (onClick == null) { Debug.LogWarning("クリック時のイベントにnullが指定されました"); return; } if (startIndex < 0 || wordLength < 0 || startIndex + wordLength > this.text.text.Length) { Debug.LogWarning("テキストの文字数範囲外です"); return; } this._entries.Add(new HyperTextBase.ClickableEntry(this.text.text.Substring(startIndex, wordLength), startIndex, returnString, color, onClick, onEnter, onExit)); } public virtual void RemoveClickable() { this._entries.Clear(); } protected abstract void RegisterClickable(); public override void ModifyMesh(VertexHelper vertexHelper) { this._entries.Clear(); this.RegisterClickable(); List list = HyperTextBase._verticesPool.Get(); vertexHelper.GetUIVertexStream(list); this.Modify(ref list); vertexHelper.Clear(); vertexHelper.AddUIVertexTriangleStream(list); HyperTextBase._verticesPool.Release(list); if (Application.isPlaying) { base.StartCoroutine(this.CreateLinkObject()); } } protected void Modify(ref List vertices) { if (!base.enabled) { return; } int count = vertices.Count; int i = 0; int count2 = this._entries.Count; while (i < count2) { HyperTextBase.ClickableEntry value = this._entries[i]; value.CharVertices.Clear(); int j = value.StartIndex; int num = value.StartIndex + value.ClickableWord.Length; while (j < num) { int num2 = j * 6; if (num2 + 6 > count) { break; } char c = this.text.text[j]; if (c != '\n' && c != '\r') { Vector2 min = Vector2.one * float.MaxValue; Vector2 max = Vector2.one * float.MinValue; for (int k = 0; k < 6; k++) { UIVertex uivertex = vertices[num2 + k]; Vector3 position = vertices[num2 + k].position; if (position.y < min.y) { min.y = position.y; } if (position.x < min.x) { min.x = position.x; } if (position.y > max.y) { max.y = position.y; } if (position.x > max.x) { max.x = position.x; } value.CharVertices.Add(uivertex); uivertex.position = Vector3.zero; vertices[num2 + k] = uivertex; } value.Rects.Add(new Rect { min = min, max = max }); } j++; } List list = new List(); foreach (List rects in this.SplitRectsByRow(value.Rects)) { list.Add(this.CalculateAABB(rects)); } value.Rects = list; this._entries[i] = value; i++; } } private List> SplitRectsByRow(List rects) { List> list = new List>(); int num = 0; int i = 1; int count = rects.Count; while (i < count) { if (rects[i].xMin < rects[i - 1].xMin) { list.Add(rects.GetRange(num, i - num)); num = i; } i++; } if (num < rects.Count) { list.Add(rects.GetRange(num, rects.Count - num)); } return list; } private Rect CalculateAABB(List rects) { Vector2 min = Vector2.one * float.MaxValue; Vector2 max = Vector2.one * float.MinValue; int i = 0; int count = rects.Count; while (i < count) { if (rects[i].xMin < min.x) { min.x = rects[i].xMin; } if (rects[i].yMin < min.y) { min.y = rects[i].yMin; } if (rects[i].xMax > max.x) { max.x = rects[i].xMax; } if (rects[i].yMax > max.y) { max.y = rects[i].yMax; } i++; } return new Rect { min = min, max = max }; } private IEnumerator CreateLinkObject() { yield return null; if (!base.enabled) { yield break; } int i = 0; while (i < this._entries.Count) { HyperTextBase.ClickableEntry entry = this._entries[i]; bool flag = entry.Rects.Count <= 0; Rect rect = this.CalculateAABB(entry.Rects); GameObject gameObject; if (base.transform.childCount <= i) { gameObject = new GameObject("clickable"); gameObject.transform.SetParent(base.transform, false); goto IL_FE; } gameObject = base.transform.GetChild(i).gameObject; if (!flag) { goto IL_FE; } gameObject.SetActive(false); IL_25F: i++; continue; IL_FE: gameObject.name = entry.ClickableWord; if (!gameObject.activeSelf) { gameObject.SetActive(true); } RectTransform rectTransform = gameObject.GetComponent(); if (rectTransform == null) { rectTransform = gameObject.AddComponent(); } Text text = gameObject.GetComponent(); if (text == null) { text = gameObject.AddComponent(); Button button = gameObject.AddComponent