99using System ;
1010using UnityEngine ;
1111using MyBox ;
12+ using NUnit . Framework . Internal ;
1213
1314namespace JCSUnity
1415{
@@ -35,14 +36,40 @@ public class JCS_Canvas : MonoBehaviour
3536 // Execution when canvas is hidden by fading.
3637 public Action < JCS_Canvas > onHideFade = null ;
3738
38- private Canvas mCanvas = null ;
3939
40- private CanvasGroup mCanvasGroup = null ;
40+
41+
4142
4243 private RectTransform mAppRect = null ; // Application Rect (Window)
4344
45+ #if UNITY_EDITOR
46+ [ Separator ( "Helper Variables (JCS_Canvas)" ) ]
47+
48+ [ Tooltip ( "Turn on this to test this behaviour." ) ]
49+ [ SerializeField ]
50+ private bool mTest = false ;
51+
52+ [ Tooltip ( "Key to show canvas." ) ]
53+ [ SerializeField ]
54+ private KeyCode mKeyShow = KeyCode . A ;
55+
56+ [ Tooltip ( "Key to hide canvas." ) ]
57+ [ SerializeField ]
58+ private KeyCode mKeyHide = KeyCode . S ;
59+ #endif
60+
4461 [ Separator ( "Check Variables (JCS_Canvas)" ) ]
4562
63+ [ Tooltip ( "Canvas." ) ]
64+ [ SerializeField ]
65+ [ ReadOnly ]
66+ private Canvas mCanvas = null ;
67+
68+ [ Tooltip ( "Canvas group." ) ]
69+ [ SerializeField ]
70+ [ ReadOnly ]
71+ private CanvasGroup mCanvasGroup = null ;
72+
4673 [ Tooltip ( "Resize object." ) ]
4774 [ SerializeField ]
4875 [ ReadOnly ]
@@ -161,9 +188,26 @@ private void Start()
161188
162189 private void Update ( )
163190 {
191+ #if UNITY_EDITOR
192+ Test ( ) ;
193+ #endif
194+
164195 DoFading ( ) ;
165196 }
166197
198+ #if UNITY_EDITOR
199+ private void Test ( )
200+ {
201+ if ( ! mTest )
202+ return ;
203+
204+ if ( Input . GetKeyDown ( mKeyShow ) )
205+ Show ( ) ;
206+ else if ( Input . GetKeyDown ( mKeyHide ) )
207+ Hide ( ) ;
208+ }
209+ #endif
210+
167211 /// <summary>
168212 /// Return the `canvas` that is the parent of the `trans` object.
169213 ///
@@ -222,16 +266,16 @@ public void Show(bool fade, bool mute = false)
222266 if ( ! mute )
223267 JCS_SoundPlayer . PlayByAttachment ( mDeactiveSound , JCS_SoundMethod . PLAY_SOUND ) ;
224268
225- if ( fade )
269+ mCanvas . enabled = true ;
270+
271+ if ( fade && mCanvasGroup )
226272 {
227273 mFading = JCS_FadeType . IN ;
228274
229275 mFadeAlpa = mFadeInAmount ;
230276 }
231277 else
232278 {
233- mCanvas . enabled = true ;
234-
235279 if ( mCanvasGroup != null )
236280 mCanvasGroup . alpha = mFadeInAmount ;
237281 }
@@ -251,8 +295,11 @@ public void Hide(bool fade, bool mute = false)
251295 if ( ! mute )
252296 JCS_SoundPlayer . PlayByAttachment ( mActiveSound , JCS_SoundMethod . PLAY_SOUND ) ;
253297
254- if ( fade )
298+ if ( fade && mCanvasGroup )
255299 {
300+ // Remains enabled since we're going to do fading.
301+ mCanvas . enabled = true ;
302+
256303 mFading = JCS_FadeType . OUT ;
257304
258305 mFadeAlpa = mFadeOutAmount ;
0 commit comments