Skip to content

Commit c82eaa2

Browse files
committed
chore: Add function to get canvas by name
1 parent 4efb04e commit c82eaa2

File tree

2 files changed

+42
-28
lines changed

2 files changed

+42
-28
lines changed

Assets/JCSUnity/Scripts/Managers/JCS_UIManager.cs

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void SetDialogue(JCS_DialogueType type, JCS_DialogueObject jdo)
8989
// return;
9090
//}
9191

92-
this.mFocusGameDialogue = jdo;
92+
mFocusGameDialogue = jdo;
9393
}
9494
break;
9595
case JCS_DialogueType.SYSTEM_DIALOGUE:
@@ -105,7 +105,7 @@ public void SetDialogue(JCS_DialogueType type, JCS_DialogueObject jdo)
105105
break;
106106
}
107107
}
108-
public JCS_DialogueObject GetJCSDialogue(JCS_DialogueType type)
108+
public JCS_DialogueObject GetDialogue(JCS_DialogueType type)
109109
{
110110
switch (type)
111111
{
@@ -133,15 +133,15 @@ private void Awake()
133133
{
134134
RegisterInstance(this);
135135

136-
this.mOpenWindow = new LinkedList<JCS_DialogueObject>();
136+
mOpenWindow = new LinkedList<JCS_DialogueObject>();
137137

138-
this.mGlobalUndoRedoSystem = this.gameObject.AddComponent<JCS_UndoRedoSystem>();
138+
mGlobalUndoRedoSystem = gameObject.AddComponent<JCS_UndoRedoSystem>();
139139
}
140140
private void Start()
141141
{
142142
// pop the fade screen.
143143
string path = JCS_UISettings.FADE_SCREEN_PATH;
144-
this.mFadeScreen = JCS_Util.Instantiate(path).GetComponent<JCS_FadeScreen>();
144+
mFadeScreen = JCS_Util.Instantiate(path).GetComponent<JCS_FadeScreen>();
145145
}
146146

147147
#if UNITY_EDITOR
@@ -165,7 +165,7 @@ private void Test()
165165

166166
if (JCS_Input.GetKeyDown(KeyCode.S))
167167
{
168-
UnFocus();
168+
Unfocus();
169169
}
170170
}
171171
#endif
@@ -175,7 +175,7 @@ private void Test()
175175
/// </summary>
176176
public void AddCanvas(JCS_Canvas canvas)
177177
{
178-
this.mCanvases.Add(canvas);
178+
mCanvases.Add(canvas);
179179
mCanvases = JCS_Array.RemoveEmptyMissing(mCanvases);
180180
mCanvases = SortCanvases_Insertion();
181181
}
@@ -196,6 +196,20 @@ private List<JCS_Canvas> SortCanvases_Insertion()
196196
return mCanvases;
197197
}
198198

199+
/// <summary>
200+
/// Return the canvas by name.
201+
/// </summary>
202+
public JCS_Canvas CanvasByName(string name)
203+
{
204+
foreach (JCS_Canvas canvas in mCanvases)
205+
{
206+
if (canvas.name == name)
207+
return canvas;
208+
}
209+
210+
return null;
211+
}
212+
199213
/// <summary>
200214
/// Hide the last open dialogue in the current scene.
201215
/// </summary>
@@ -286,7 +300,7 @@ public void Focus(float time, Color color)
286300
/// <summary>
287301
/// Fade out the screen, back to original amount of value.
288302
/// </summary>
289-
public void UnFocus()
303+
public void Unfocus()
290304
{
291305
JCS_FadeObject fadeObj = mFadeScreen.fadeObject;
292306
fadeObj.FadeOut();
@@ -295,7 +309,7 @@ public void UnFocus()
295309
/// <summary>
296310
/// Fade out the screen, back to original amount of value.
297311
/// </summary>
298-
public void UnFocus(float time)
312+
public void Unfocus(float time)
299313
{
300314
JCS_FadeObject fadeObj = mFadeScreen.fadeObject;
301315
fadeObj.FadeOut(time);

Assets/JCSUnity/Scripts/UI/JCS_Canvas.cs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ public enum ShowMethod
137137

138138
/* Setter & Getter */
139139

140-
public RectTransform appRect { get { return this.mAppRect; } }
141-
public Canvas canvas { get { return this.mCanvas; } }
142-
public CanvasGroup canvasGroup { get { return this.mCanvasGroup; } }
143-
public JCS_ResizeUI resizeUI { get { return this.mResizeUI; } }
140+
public RectTransform appRect { get { return mAppRect; } }
141+
public Canvas canvas { get { return mCanvas; } }
142+
public CanvasGroup canvasGroup { get { return mCanvasGroup; } }
143+
public JCS_ResizeUI resizeUI { get { return mResizeUI; } }
144144

145-
public bool displayOnAwake { get { return this.mDisplayOnAwake; } }
146-
public bool mainCanvas { get { return this.mMainCanvas; } }
147-
public ShowMethod showMethod { get { return this.mShowMethod; } set { this.mShowMethod = value; } }
145+
public bool displayOnAwake { get { return mDisplayOnAwake; } }
146+
public bool mainCanvas { get { return mMainCanvas; } }
147+
public ShowMethod showMethod { get { return mShowMethod; } set { mShowMethod = value; } }
148148

149-
public float fadeFriction { get { return this.mFadeFriction; } set { this.mFadeFriction = value; } }
150-
public float fadeInAmount { get { return this.mFadeInAmount; } set { this.mFadeInAmount = value; } }
151-
public float fadeOutAmount { get { return this.mFadeOutAmount; } set { this.mFadeOutAmount = value; } }
149+
public float fadeFriction { get { return mFadeFriction; } set { mFadeFriction = value; } }
150+
public float fadeInAmount { get { return mFadeInAmount; } set { mFadeInAmount = value; } }
151+
public float fadeOutAmount { get { return mFadeOutAmount; } set { mFadeOutAmount = value; } }
152152

153-
public JCS_TimeType timeType { get { return this.mTimeType; } set { this.mTimeType = value; } }
154-
public AudioClip soundOnShow { get { return this.mSoundOnShow; } set { this.mSoundOnShow = value; } }
155-
public AudioClip soundOnHide { get { return this.mSoundOnHide; } set { this.mSoundOnHide = value; } }
153+
public JCS_TimeType timeType { get { return mTimeType; } set { mTimeType = value; } }
154+
public AudioClip soundOnShow { get { return mSoundOnShow; } set { mSoundOnShow = value; } }
155+
public AudioClip soundOnHide { get { return mSoundOnHide; } set { mSoundOnHide = value; } }
156156

157157
public static float SCALE_FACTOR
158158
{
@@ -171,9 +171,9 @@ private void Awake()
171171
{
172172
CheckMainCanvas();
173173

174-
this.mAppRect = this.GetComponent<RectTransform>();
175-
this.mCanvas = this.GetComponent<Canvas>();
176-
this.mCanvasGroup = this.GetComponent<CanvasGroup>();
174+
mAppRect = GetComponent<RectTransform>();
175+
mCanvas = GetComponent<Canvas>();
176+
mCanvasGroup = GetComponent<CanvasGroup>();
177177

178178
var uis = JCS_UISettings.FirstInstance();
179179
var screens = JCS_ScreenSettings.FirstInstance();
@@ -186,7 +186,7 @@ private void Awake()
186186
// resizable UI in order to resize the UI correctly
187187
mResizeUI = spawned.GetComponent<JCS_ResizeUI>();
188188

189-
mResizeUI.transform.SetParent(this.transform);
189+
mResizeUI.transform.SetParent(transform);
190190
}
191191

192192
uim.AddCanvas(this);
@@ -293,7 +293,7 @@ public static JCS_Canvas GuessCanvas(Transform trans = null)
293293
/// <param name="com"> Component add to canvas. </param>
294294
public void AddComponentToResizeCanvas(Component com)
295295
{
296-
Transform newParent = (mResizeUI != null) ? mResizeUI.transform : this.mCanvas.transform;
296+
Transform newParent = (mResizeUI != null) ? mResizeUI.transform : mCanvas.transform;
297297

298298
if (newParent == null)
299299
Debug.LogError($"Attach resize canvas exception: {com}");
@@ -422,7 +422,7 @@ public bool IsFading()
422422
/// </summary>
423423
private void CheckMainCanvas()
424424
{
425-
if (!this.mMainCanvas)
425+
if (!mMainCanvas)
426426
return;
427427

428428
if (main != null)

0 commit comments

Comments
 (0)