Skip to content

Commit 8b9ead4

Browse files
committed
feat(UI): Add canvas show/hide hooks
1 parent 20b62f7 commit 8b9ead4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

Assets/JCSUnity/Scripts/UI/JCS_Canvas.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* $Notice: See LICENSE.txt for modification and distribution information
77
* Copyright (c) 2016 by Shen, Jen-Chieh $
88
*/
9+
using System;
910
using UnityEngine;
1011
using MyBox;
1112

@@ -24,6 +25,9 @@ public class JCS_Canvas : MonoBehaviour
2425

2526
private const string RESIZE_UI_PATH = "UI/ResizeUI";
2627

28+
public Action<JCS_Canvas> onShow = null; // Execution when canvas is shown.
29+
public Action<JCS_Canvas> onHide = null; // Execution when canvas is hidden.
30+
2731
private Canvas mCanvas = null;
2832

2933
private RectTransform mAppRect = null; // Application Rect (Window)
@@ -165,6 +169,8 @@ public void Show(bool mute = false)
165169
mCanvas.enabled = true;
166170
if (!mute)
167171
JCS_SoundPlayer.PlayByAttachment(mDeactiveSound, JCS_SoundMethod.PLAY_SOUND);
172+
173+
onShow?.Invoke(this);
168174
}
169175

170176
/// <summary>
@@ -175,6 +181,8 @@ public void Hide(bool mute = false)
175181
mCanvas.enabled = false;
176182
if (!mute)
177183
JCS_SoundPlayer.PlayByAttachment(mActiveSound, JCS_SoundMethod.PLAY_SOUND);
184+
185+
onHide?.Invoke(this);
178186
}
179187

180188
/// <summary>
@@ -199,7 +207,7 @@ private void CheckMainCanvas()
199207

200208
if (main != null)
201209
{
202-
JCS_Debug.LogWarning("Having multiple main canvases is often not allowed, " + this.gameObject.name);
210+
JCS_Debug.LogWarning("Having multiple main canvases is often not allowed: " + this.gameObject.name);
203211
return;
204212
}
205213

docs/ScriptReference/UI/JCS_Canvas.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Control of the canvas component.
66

77
| Name | Description |
88
|:----------------|:-------------------------------------------------|
9+
| onShow | Execution when canvas is shown. |
10+
| onHide | Execution when canvas is hidden. |
911
| mDisplayOnAwake | If true, show on awake time; otherwise, hide it. |
1012
| mMainCanvas | Resizable screen will be attach to this canvas. |
1113
| mActiveSound | Play sound when active the canvas. |

0 commit comments

Comments
 (0)