Code Monkey home page Code Monkey logo

unitymodalwindows's Introduction

UnityModalWindows

Simple system for creating modal windows with callbacks in Unity, with extensible template.

In action

Simple modal windows

This code

SimpleModalWindow.Create()
                 .SetHeader("Simple Modal")
                 .SetBody("Here goes body")
                 .Show();

Gives you this simple dismissable modal window:

Preview

You can also add buttons with callbacks and make modal window not dismissable:

SimpleModalWindow.Create(ignorable: false)
                 .SetHeader("Modal With Buttons")
                 .SetBody("You must press one of the buttons")
                 .AddButton("Yes", () => print("Yes pressed"), ModalButtonType.Success)
                 .AddButton("No", () => print("No pressed"), ModalButtonType.Danger)
                 .Show();

Which will lead you to this result:

Preview

Custom modals

You can make your own modal windows, for example, modal with input field creation simply as following:

  1. Create script and inherit it from ModalWindow<T>
using System;
using UnityEngine;
using UnityEngine.UI;

public class InputModalWindow : ModalWindow<InputModalWindow>
{
    [SerializeField] private InputField inputField;
    private Action<string> onInputFieldDone;

    public InputModalWindow SetInputField(Action<string> onDone)
    {
        onInputFieldDone = onDone;
        return this;
    }

    void SubmitInput()
    {
        onInputFieldDone?.Invoke(inputField.text);
        onInputFieldDone = null;
        Close();
    }

    public void UI_InputFieldOKButton()
    {
        SubmitInput();
    }
}
  1. Create prefab for it (use original modal window prefab as template) and place it under Resources/Modal Windows

Preview

  1. Use it from your code in this way:
ModalWindow<InputModalWindow>.Create()
                   .SetHeader("Input Field Modal")
                   .SetBody("Enter something:")
                   .SetInputField((inputResult) => print("Text: " + inputResult))
                   .Show();

Result:

Preview

Installation

Option 1:

Download latest .unitypackage release from the releases tab and import it in your project.

Option 2:

Download .zip of this repository and extract all files from Assets/ModalWindows to your project folder.

More windows

Toast

Preview

Conclusion

Thanks for using this asset, i will be pleasured to see any feedback :)

unitymodalwindows's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

unitymodalwindows's Issues

Modal animations Update Mode should use unscaled time.

It is common to set Time.timeScale=0 to halt gameplay and then set it back to 1 to continue. However, non gameplay animations in UI will also be halted unless the Update Mode of these animation is set to unscaled time.

InputField support

Do you plan to add an input field to the constructor of the modal window?

For example, I would like to display to the user a window with two fields and a button that would receive values from these fields.

Thanks in advance

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.