'Unity Window Panel' is simple and extensible window UI component for Unity.
Unity 2020.3 or higher.
Via Package Manager.
Open the Package Manager window in your Unity editor, select Add package from git URL...
from the +
button in the top left, enter following and press the Add
button.
https://github.com/neuneu9/unity-window-panel.git?path=Packages/jp.neuneu9.window-panel
Or open the Packages/manifest.json
file and add an item like the following to the dependencies
field.
"jp.neuneu9.window-panel": "https://github.com/neuneu9/unity-window-panel.git?path=Packages/jp.neuneu9.window-panel",
3 components are available by default:
Fade Window Panel
: Fade style
Slide In Window Panel
: Slide-in style
Animated Window Panel
: Animation style
Select GameObject -> UI -> Window Panel -> *** Window Panel
in the menu to create a constructed GameObject.
Press Default To Open
to set it open, and press Default To Close
to set it close in the inspector.
Name | Explanation |
---|---|
Window | Reference to window object |
Background | Reference to background object |
Skip Opening On Clicked | Whether to complete the transition immediately if clicked while open transitioning |
Close On Background Clicked | Whether to close if the background is clicked |
Open Duration | Open transition time [s] |
Close Duration | Close transition time [s] |
On Pre Open | Called before starting the open transition |
On Opened | Called after opened |
On Pre Close | Called before starting the close transition |
On Closed | Called after closed |
Method name | Explanation |
---|---|
Open() Open(UnityAction onCompleted) |
Open the window panel. If it's already open or about to be opened, nothing will be done.onCompleted : Completion callback |
Close() Close(UnityAction onCompleted) |
Close the window panel. If it's already closed or about to close, nothing will be done.onCompleted : Completion callback |
OpenImmediately() |
Open the window panel instantly. If it's already open, nothing will be done. |
CloseImmediately() |
Close the window panel instantly. If it's already closed, nothing will be done. |
GetWindow<TWindow>() |
Get a component of the window object.TWindow : Type of component to get |
- Create open and close animation clips
NOTE: The clip length is arbitrary, but Animated Window Panel normalizes it to 1 [s].
To set the length of the open/close transition, useOpen Duration
andClose Duration
in the inspector. - Create an Animator Override Controller based on
Packages/jp.neuneu9.window-panel/Animations/WindowPanel.controller
. - Set the open animation clip to
window_panel_open
and the close animation clip towindow_panel_close
.
Want to use your behavior? It’s easy.
- Create a class that inherits from
neuneu9.WindowPanel
. - Override the following two methods:
(The argumentprogress
is a transition rate between 0 and 1.)void OpenAction(float progress)
: Code the open transition processing.void CloseAction(float progress)
: Code the close transition processing.
- Use the class script instead of scripts such as Fade Window Panel.
Below is an example implementation of a pop-up styled window using DOTween.
using UnityEngine;
using DG.Tweening;
using neuneu9.WindowPanel;
public class PopUpWindowPanel : WindowPanel
{
[SerializeField]
private Ease _openEase = Ease.OutBack;
[SerializeField]
private Ease _closeEase = Ease.InQuart;
[SerializeField]
private Vector3 _scaleOnClosed = new Vector3(0.6f, 0.6f, 1f);
protected override void OpenAction(float progress)
{
_window.alpha = Mathf.Lerp(0f, 1f, progress * 2f);
_window.transform.localScale = Vector3.LerpUnclamped(_scaleOnClosed, Vector3.one, DOVirtual.EasedValue(0f, 1f, progress, _openEase));
}
protected override void CloseAction(float progress)
{
_window.alpha = Mathf.Lerp(1f, 0f, (progress - 0.5f) * 2f);
_window.transform.localScale = Vector3.LerpUnclamped(Vector3.one, _scaleOnClosed, DOVirtual.EasedValue(0f, 1f, progress, _closeEase));
}
}