From 8e13fbebe34ac459f822609434424f5c4e0b55e4 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Tue, 10 Sep 2024 20:58:57 -0700 Subject: [PATCH] feat: Add transform option to active/deactive panels button --- .../UI/Button/Panel/JCS_ActivePanelButton.cs | 13 +++++++-- .../Panel/JCS_ActivePanelGamePadButton.cs | 13 +++++++-- .../Button/Panel/JCS_DeactivePanelButton.cs | 13 +++++++-- .../Panel/JCS_DeactivePanelGamePadButton.cs | 13 +++++++-- .../UI/GameWindow/JCS_BaseDialogueObject.cs | 10 ++----- Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs | 9 +++--- Assets/JCSUnity/Scripts/Util/JCS_Util.cs | 29 +++++++++++++++++++ .../UI/Button/Panel/JCS_ActivePanelButton.md | 1 + .../Button/Panel/JCS_DeactivePanelButton.md | 1 + 9 files changed, 77 insertions(+), 25 deletions(-) diff --git a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelButton.cs b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelButton.cs index 75b1bf6c..4876ed6b 100644 --- a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelButton.cs +++ b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelButton.cs @@ -20,9 +20,13 @@ public class JCS_ActivePanelButton : JCS_Button [Separator("Runtime Variables (JCS_ActivePanelButton)")] + [Tooltip("Transform to be active.")] + [SerializeField] + private Transform[] mTransforms = null; + [Tooltip("Panels to be active.")] [SerializeField] - private JCS_DialogueObject[] mDialogueObjects = null; + private JCS_PanelRoot[] mPanelRoots = null; [Tooltip("Tween Panels to be active.")] [SerializeField] @@ -34,7 +38,8 @@ public class JCS_ActivePanelButton : JCS_Button /* Setter & Getter */ - public JCS_DialogueObject[] DialogueObjects { get { return this.mDialogueObjects; } } + public Transform[] transforms { get { return this.mTransforms; } } + public JCS_PanelRoot[] PanelRoots { get { return this.mPanelRoots; } } public JCS_TweenPanel[] TweenPanels { get { return this.mTweenPanels; } } public bool PlaySound { get { return this.mPlaySound; } set { this.mPlaySound = value; } } @@ -43,7 +48,9 @@ public class JCS_ActivePanelButton : JCS_Button public override void OnClick() { - JCS_UIUtil.ActivePanels(mDialogueObjects, mPlaySound); + JCS_Util.SetActive(mTransforms, true); + + JCS_UIUtil.ActivePanels(mPanelRoots, mPlaySound); JCS_UIUtil.ActivePanels(mTweenPanels); } } diff --git a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelGamePadButton.cs b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelGamePadButton.cs index bd98cdbf..4844252f 100644 --- a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelGamePadButton.cs +++ b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelGamePadButton.cs @@ -20,9 +20,13 @@ public class JCS_ActivePanelGamepadButton : JCS_GamepadButton [Separator("Runtime Variables (JCS_ActivePanelGamepadButton)")] + [Tooltip("Transform to be active.")] + [SerializeField] + private Transform[] mTransforms = null; + [Tooltip("Panels to be active.")] [SerializeField] - private JCS_DialogueObject[] mDialogueObjects = null; + private JCS_PanelRoot[] mPanelRoots = null; [Tooltip("Tween Panels to be active.")] [SerializeField] @@ -34,7 +38,8 @@ public class JCS_ActivePanelGamepadButton : JCS_GamepadButton /* Setter & Getter */ - public JCS_DialogueObject[] DialogueObjects { get { return this.mDialogueObjects; } } + public Transform[] transforms { get { return this.mTransforms; } } + public JCS_PanelRoot[] PanelRoots { get { return this.mPanelRoots; } } public JCS_TweenPanel[] TweenPanels { get { return this.mTweenPanels; } } public bool PlaySound { get { return this.mPlaySound; } set { this.mPlaySound = value; } } @@ -43,7 +48,9 @@ public class JCS_ActivePanelGamepadButton : JCS_GamepadButton public override void OnClick() { - JCS_UIUtil.ActivePanels(mDialogueObjects, mPlaySound); + JCS_Util.SetActive(mTransforms, true); + + JCS_UIUtil.ActivePanels(mPanelRoots, mPlaySound); JCS_UIUtil.ActivePanels(mTweenPanels); } } diff --git a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelButton.cs b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelButton.cs index e87bba11..03e02172 100644 --- a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelButton.cs +++ b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelButton.cs @@ -20,9 +20,13 @@ public class JCS_DeactivePanelButton : JCS_Button [Separator("Runtime Variables (JCS_DeactivePanelButton)")] + [Tooltip("Transforms to be deactive.")] + [SerializeField] + private Transform[] mTransforms = null; + [Tooltip("Panels to be deactive.")] [SerializeField] - private JCS_DialogueObject[] mDialogueObjects = null; + private JCS_PanelRoot[] mPanelRoots = null; [Tooltip("Tween Panels to be deactive.")] [SerializeField] @@ -34,7 +38,8 @@ public class JCS_DeactivePanelButton : JCS_Button /* Setter & Getter */ - public JCS_DialogueObject[] DialogueObjects { get { return this.mDialogueObjects; } } + public Transform[] transforms { get { return this.mTransforms; } } + public JCS_PanelRoot[] PanelRoots { get { return this.mPanelRoots; } } public JCS_TweenPanel[] TweenPanels { get { return this.mTweenPanels; } } public bool PlaySound { get { return this.mPlaySound; } set { this.mPlaySound = value; } } @@ -43,7 +48,9 @@ public class JCS_DeactivePanelButton : JCS_Button public override void OnClick() { - JCS_UIUtil.DeactivePanels(mDialogueObjects, mPlaySound); + JCS_Util.SetActive(mTransforms, false); + + JCS_UIUtil.DeactivePanels(mPanelRoots, mPlaySound); JCS_UIUtil.DeactivePanels(mTweenPanels); } } diff --git a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelGamePadButton.cs b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelGamePadButton.cs index 9c611f23..c7832a9e 100644 --- a/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelGamePadButton.cs +++ b/Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelGamePadButton.cs @@ -20,9 +20,13 @@ public class JCS_DeactivePanelGamepadButton : JCS_GamepadButton [Separator("Runtime Variables (JCS_DeactivePanelGamepadButton)")] + [Tooltip("Transforms to be deactive.")] + [SerializeField] + private Transform[] mTransforms = null; + [Tooltip("Panels to be deactive.")] [SerializeField] - private JCS_DialogueObject[] mDialogueObjects = null; + private JCS_PanelRoot[] mPanelRoots = null; [Tooltip("Tween Panels to be deactive.")] [SerializeField] @@ -34,7 +38,8 @@ public class JCS_DeactivePanelGamepadButton : JCS_GamepadButton /* Setter & Getter */ - public JCS_DialogueObject[] DialogueObjects { get { return this.mDialogueObjects; } } + public Transform[] transforms { get { return this.mTransforms; } } + public JCS_PanelRoot[] PanelRoots { get { return this.mPanelRoots; } } public JCS_TweenPanel[] TweenPanels { get { return this.mTweenPanels; } } public bool PlaySound { get { return this.mPlaySound; } set { this.mPlaySound = value; } } @@ -43,7 +48,9 @@ public class JCS_DeactivePanelGamepadButton : JCS_GamepadButton public override void OnClick() { - JCS_UIUtil.DeactivePanels(mDialogueObjects, mPlaySound); + JCS_Util.SetActive(mTransforms, false); + + JCS_UIUtil.DeactivePanels(mPanelRoots, mPlaySound); JCS_UIUtil.DeactivePanels(mTweenPanels); } } diff --git a/Assets/JCSUnity/Scripts/UI/GameWindow/JCS_BaseDialogueObject.cs b/Assets/JCSUnity/Scripts/UI/GameWindow/JCS_BaseDialogueObject.cs index 5d5d028d..d109487c 100644 --- a/Assets/JCSUnity/Scripts/UI/GameWindow/JCS_BaseDialogueObject.cs +++ b/Assets/JCSUnity/Scripts/UI/GameWindow/JCS_BaseDialogueObject.cs @@ -125,10 +125,7 @@ public virtual void Show(bool mute = false) mIsVisible = true; // active all the child object - for (int index = 0; index < this.transform.childCount; ++index) - { - this.transform.GetChild(index).gameObject.SetActive(true); - } + JCS_Util.SetActiveChildren(this.transform, true); JCS_Util.MoveToTheLastChild(this.transform); } @@ -144,10 +141,7 @@ public virtual void Hide(bool mute = false) mIsVisible = false; // deactive all the child object - for (int index = 0; index < this.transform.childCount; ++index) - { - this.transform.GetChild(index).gameObject.SetActive(false); - } + JCS_Util.SetActiveChildren(this.transform, false); } /// diff --git a/Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs b/Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs index 3768716e..ea8f0a95 100644 --- a/Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs +++ b/Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs @@ -585,9 +585,9 @@ public static void HideCanvas(JCS_Canvas[] canvas) /// /// Active panels in array. /// - public static void ActivePanels(JCS_DialogueObject[] dos, bool sound) + public static void ActivePanels(JCS_PanelRoot[] dos, bool sound) { - foreach (JCS_DialogueObject panel in dos) + foreach (JCS_PanelRoot panel in dos) { if (panel != null) { @@ -604,13 +604,12 @@ public static void ActivePanels(JCS_TweenPanel[] tps) } } - /// /// Deactive panels in array. /// - public static void DeactivePanels(JCS_DialogueObject[] dos, bool sound) + public static void DeactivePanels(JCS_PanelRoot[] dos, bool sound) { - foreach (JCS_DialogueObject panel in dos) + foreach (JCS_PanelRoot panel in dos) { if (panel != null) { diff --git a/Assets/JCSUnity/Scripts/Util/JCS_Util.cs b/Assets/JCSUnity/Scripts/Util/JCS_Util.cs index a3e65a16..1ccf0b73 100644 --- a/Assets/JCSUnity/Scripts/Util/JCS_Util.cs +++ b/Assets/JCSUnity/Scripts/Util/JCS_Util.cs @@ -136,6 +136,35 @@ public static Object[] FindObjectsByType(System.Type type) #endif } + /// + /// Set active according to it's type. + /// + public static void SetActive(List transforms, bool act) + { + SetActive(transforms.ToArray(), act); + } + public static void SetActive(Transform[] transforms, bool act) + { + foreach (Transform trans in transforms) + { + if (trans == null) + continue; + + trans.gameObject.SetActive(act); + } + } + + /// + /// Set active to all children. + /// + public static void SetActiveChildren(Transform transform, bool act) + { + for (int index = 0; index < transform.childCount; ++index) + { + transform.GetChild(index).gameObject.SetActive(act); + } + } + /// /// Check the value within the range plus acceptable range. /// diff --git a/docs/ScriptReference/UI/Button/Panel/JCS_ActivePanelButton.md b/docs/ScriptReference/UI/Button/Panel/JCS_ActivePanelButton.md index c5832226..f589be49 100644 --- a/docs/ScriptReference/UI/Button/Panel/JCS_ActivePanelButton.md +++ b/docs/ScriptReference/UI/Button/Panel/JCS_ActivePanelButton.md @@ -6,6 +6,7 @@ Button that active the panel. | Name | Description | |:----------------|:---------------------------| +| mTransforms | Transforms to be active. | | DialogueObjects | Panels to be active. | | TweenPanels | Tween Panels to be active. | | PlaySound | Play dialogue sound. | diff --git a/docs/ScriptReference/UI/Button/Panel/JCS_DeactivePanelButton.md b/docs/ScriptReference/UI/Button/Panel/JCS_DeactivePanelButton.md index 3b780ddd..2d3d4ac2 100644 --- a/docs/ScriptReference/UI/Button/Panel/JCS_DeactivePanelButton.md +++ b/docs/ScriptReference/UI/Button/Panel/JCS_DeactivePanelButton.md @@ -6,6 +6,7 @@ Button that deactive the panel. | Name | Description | |:-----------------|:------------------------------| +| mTransforms | Transforms to be deactive. | | mDialogueObjects | Panels to be deactive. | | mTweenPanels | Tween Panels to be deactive." | | PlaySound | Play dialogue sound. |