Skip to content

Commit a2000a7

Browse files
author
setchi
committed
Refactoring
1 parent 2347122 commit a2000a7

2 files changed

Lines changed: 17 additions & 24 deletions

File tree

Assets/Hypertext/Scripts/HypertextBase.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using System;
1+
using HypertextHelper;
2+
using System;
23
using System.Collections.Generic;
34
using UnityEngine;
45
using UnityEngine.EventSystems;
56
using UnityEngine.UI;
6-
using HypertextHelper;
77

88
public abstract class HypertextBase : Text, IPointerClickHandler
99
{
@@ -13,16 +13,16 @@ public abstract class HypertextBase : Text, IPointerClickHandler
1313

1414
struct ClickableEntry
1515
{
16-
public int WordStartIndex;
1716
public string Word;
17+
public int StartIndex;
1818
public Color Color;
1919
public Action<string> OnClick;
2020
public List<Rect> Rects;
2121

2222
public ClickableEntry(string word, int startIndex, Color color, Action<string> onClick)
2323
{
2424
Word = word;
25-
WordStartIndex = startIndex;
25+
StartIndex = startIndex;
2626
Color = color;
2727
OnClick = onClick;
2828
Rects = new List<Rect>();
@@ -32,23 +32,23 @@ public ClickableEntry(string word, int startIndex, Color color, Action<string> o
3232
/// <summary>
3333
/// クリック可能領域に関する情報を登録します
3434
/// </summary>
35-
/// <param name="wordStartIndex">対象ワードの開始インデックス</param>
35+
/// <param name="startIndex">対象ワードの開始インデックス</param>
3636
/// <param name="wordLength">対象ワードの文字数</param>
3737
/// <param name="color">対象ワードにつける色</param>
3838
/// <param name="onClick">対象ワードがクリックされたときのコールバック</param>
39-
protected void RegisterClickable(int wordStartIndex, int wordLength, Color color, Action<string> onClick)
39+
protected void RegisterClickable(int startIndex, int wordLength, Color color, Action<string> onClick)
4040
{
4141
if (onClick == null)
4242
{
4343
return;
4444
}
4545

46-
if (wordStartIndex < 0 || wordLength < 0 || wordStartIndex + wordLength > text.Length)
46+
if (startIndex < 0 || wordLength < 0 || startIndex + wordLength > text.Length)
4747
{
4848
return;
4949
}
5050

51-
_entries.Add(new ClickableEntry(text.Substring(wordStartIndex, wordLength), wordStartIndex, color, onClick));
51+
_entries.Add(new ClickableEntry(text.Substring(startIndex, wordLength), startIndex, color, onClick));
5252
}
5353

5454
/// <summary>
@@ -90,7 +90,7 @@ void Modify(ref List<UIVertex> vertices)
9090
{
9191
var entry = _entries[i];
9292

93-
for (int textIndex = entry.WordStartIndex, wordEndIndex = entry.WordStartIndex + entry.Word.Length; textIndex < wordEndIndex; textIndex++)
93+
for (int textIndex = entry.StartIndex, wordEndIndex = entry.StartIndex + entry.Word.Length; textIndex < wordEndIndex; textIndex++)
9494
{
9595
var vertexStartIndex = textIndex * CharVertsNum;
9696
if (vertexStartIndex + CharVertsNum > verticesCount)
@@ -130,10 +130,7 @@ void Modify(ref List<UIVertex> vertices)
130130
}
131131
}
132132

133-
var charRect = new Rect();
134-
charRect.min = min;
135-
charRect.max = max;
136-
entry.Rects.Add(charRect);
133+
entry.Rects.Add(new Rect { min = min, max = max });
137134
}
138135

139136
// 同じ行で隣り合った矩形をまとめる
@@ -198,10 +195,7 @@ Rect MergeRects(List<Rect> rects)
198195
}
199196
}
200197

201-
var rect = new Rect();
202-
rect.min = min;
203-
rect.max = max;
204-
return rect;
198+
return new Rect { min = min, max = max };
205199
}
206200

207201
// TODO: Canvas の Render Mode によって localPosition の算出方法を変える

Assets/Hypertext/Scripts/ObjectPool.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
using System.Collections.Generic;
2-
using UnityEngine;
3-
using UnityEngine.Events;
1+
using System;
2+
using System.Collections.Generic;
43

54
namespace HypertextHelper
65
{
76
public class ObjectPool<T> where T : new()
87
{
98
readonly Stack<T> _stack = new Stack<T>();
10-
readonly UnityAction<T> _onGet;
11-
readonly UnityAction<T> _onRelease;
9+
readonly Action<T> _onGet;
10+
readonly Action<T> _onRelease;
1211

1312
public int CountAll { get; set; }
1413
public int CountActive { get { return CountAll - CountInactive; } }
1514
public int CountInactive { get { return _stack.Count; } }
1615

17-
public ObjectPool(UnityAction<T> onGet, UnityAction<T> onRelease)
16+
public ObjectPool(Action<T> onGet, Action<T> onRelease)
1817
{
1918
_onGet = onGet;
2019
_onRelease = onRelease;
@@ -45,7 +44,7 @@ public void Release(T element)
4544
{
4645
if (_stack.Count > 0 && ReferenceEquals(_stack.Peek(), element))
4746
{
48-
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
47+
UnityEngine.Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
4948
}
5049

5150
if (_onRelease != null)

0 commit comments

Comments
 (0)