Skip to content

Commit 6377642

Browse files
committed
feat: Add get canvas by name
1 parent c82eaa2 commit 6377642

File tree

1 file changed

+7
-21
lines changed

1 file changed

+7
-21
lines changed

Assets/JCSUnity/Scripts/Managers/JCS_UIManager.cs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
99
using System.Collections.Generic;
10+
using System.Linq;
1011
using UnityEngine;
1112
using MyBox;
1213

@@ -21,7 +22,7 @@ public class JCS_UIManager : JCS_Manager<JCS_UIManager>
2122

2223
#if UNITY_EDITOR
2324
[Separator("Helper Variables (JCS_UIManager)")]
24-
25+
2526
[Tooltip("Test this component with key?")]
2627
[SerializeField]
2728
private bool mTestWithKey = false;
@@ -176,31 +177,16 @@ private void Test()
176177
public void AddCanvas(JCS_Canvas canvas)
177178
{
178179
mCanvases.Add(canvas);
179-
mCanvases = JCS_Array.RemoveEmptyMissing(mCanvases);
180-
mCanvases = SortCanvases_Insertion();
181-
}
182-
private List<JCS_Canvas> SortCanvases_Insertion()
183-
{
184-
for (int i = 0; i < mCanvases.Count; ++i)
185-
{
186-
for (int j = i; j > 0; --j)
187-
{
188-
if (mCanvases[j].canvas.sortingOrder < mCanvases[j - 1].canvas.sortingOrder)
189-
{
190-
JCS_Canvas temp = mCanvases[j];
191-
mCanvases[j] = mCanvases[j - 1];
192-
mCanvases[j - 1] = temp;
193-
}
194-
}
195-
}
196-
return mCanvases;
180+
mCanvases = mCanvases.OrderBy(x => x.canvas.sortingOrder).ToList();
197181
}
198182

199183
/// <summary>
200184
/// Return the canvas by name.
201185
/// </summary>
202186
public JCS_Canvas CanvasByName(string name)
203187
{
188+
mCanvases = JCS_Array.RemoveEmptyMissing(mCanvases);
189+
204190
foreach (JCS_Canvas canvas in mCanvases)
205191
{
206192
if (canvas.name == name)
@@ -219,10 +205,10 @@ public void HideTheLastOpenDialogue()
219205
if (GetOpenWindow().Count == 0)
220206
return;
221207

222-
JCS_DialogueObject jdo = GetOpenWindow().Last.Value;
208+
JCS_DialogueObject dialogue = GetOpenWindow().Last.Value;
223209

224210
// once it hide it will remove from the list it self!
225-
jdo.Hide();
211+
dialogue.Hide();
226212
}
227213

228214
/// <summary>

0 commit comments

Comments
 (0)