Skip to content

Commit

Permalink
feat: Add transform option to active/deactive panels button
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed Sep 11, 2024
1 parent 84f97a6 commit 8e13fbe
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 25 deletions.
13 changes: 10 additions & 3 deletions Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_ActivePanelButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand All @@ -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);
}
}
Expand Down
13 changes: 10 additions & 3 deletions Assets/JCSUnity/Scripts/UI/Button/Panel/JCS_DeactivePanelButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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; } }
Expand All @@ -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);
}
}
Expand Down
10 changes: 2 additions & 8 deletions Assets/JCSUnity/Scripts/UI/GameWindow/JCS_BaseDialogueObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}

/// <summary>
Expand Down
9 changes: 4 additions & 5 deletions Assets/JCSUnity/Scripts/Util/JCS_UIUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ public static void HideCanvas(JCS_Canvas[] canvas)
/// <summary>
/// Active panels in array.
/// </summary>
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)
{
Expand All @@ -604,13 +604,12 @@ public static void ActivePanels(JCS_TweenPanel[] tps)
}
}


/// <summary>
/// Deactive panels in array.
/// </summary>
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)
{
Expand Down
29 changes: 29 additions & 0 deletions Assets/JCSUnity/Scripts/Util/JCS_Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,35 @@ public static Object[] FindObjectsByType(System.Type type)
#endif
}

/// <summary>
/// Set active according to it's type.
/// </summary>
public static void SetActive(List<Transform> 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);
}
}

/// <summary>
/// Set active to all children.
/// </summary>
public static void SetActiveChildren(Transform transform, bool act)
{
for (int index = 0; index < transform.childCount; ++index)
{
transform.GetChild(index).gameObject.SetActive(act);
}
}

/// <summary>
/// Check the value within the range plus acceptable range.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

0 comments on commit 8e13fbe

Please sign in to comment.