Coder Social home page Coder Social logo

unity-window-panel's Introduction

Unity Window Panel

English | 日本語 |

What’s this?

'Unity Window Panel' is simple and extensible window UI component for Unity.

Supported Unity versions

Unity 2020.3 or higher.

Installation

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",

How to use

3 components are available by default:

  • Fade Window Panel: Fade style
    fade
  • Slide In Window Panel: Slide-in style
    slidein
  • Animated Window Panel: Animation style
    animated

Creation

Select GameObject -> UI -> Window Panel -> *** Window Panel in the menu to create a constructed GameObject.

Set initial open/close

Press Default To Open to set it open, and press Default To Close to set it close in the inspector.

Inspector exposed parameters

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

Scripting APIs

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

Customize animations of Animated Window Panel

  1. 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, use Open Duration and Close Duration in the inspector.
  2. Create an Animator Override Controller based on Packages/jp.neuneu9.window-panel/Animations/WindowPanel.controller.
  3. Set the open animation clip to window_panel_open and the close animation clip to window_panel_close.

Extension

Want to use your behavior? It’s easy.

  1. Create a class that inherits from neuneu9.WindowPanel.
  2. Override the following two methods:
    (The argument progress 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.
  3. 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.

popup

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));
    }
}

unity-window-panel's People

Contributors

neuneu9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.