Giter Site home page Giter Site logo

unity3d.uimanager's Introduction

UiManager for Unity3D

Features

  • Modal dialog management.
  • Common dialog boxes such as MessageBox and InputBox.

How to use

Modal Dialog management.

Modal

This library provides basic modal dialog managements on Unity-GUI. Modal dialog box works like a function which gets input argument, does work, and returns return value. When a modal dialog box shows, input of other windows under showing dialog box will be blocked.

// show up TestDialogBox with an arugment
var handle = UiManager.Instance.ShowModalRoot<TestDialogBox>("Input your name?");
// waits for dialog to finish it's work
yield return StartCoroutine(handle.WaitForHide());
// gets return value from dialog
Debug.Log(handle.ReturnValue);

Define modal dialog box

DialogBox should inherit UiDialog. When dialog box shows up, OnShow handler will be invoked with param is passed by ShowModalRoot. When work done and there is a return value, Hide method can be used.

//
public class TestDialogBox : UiDialog
{
    public override void OnShow(object param)
    {
        // gets an argument from caller
        Message.text = (string)param;
        Input.text = "";
    }

    public void OnOkButtonClick()
    {
        // returns values to caller
        Hide(Input.text);
    }
}

Show modal dialog

It's quite simple to show modal dialog boxes but there are several ways for showing dialog box.

  • ShowModalPrefab: Use the prefab dialog box. Whenever show up new dialog, dialog box will be instantiated.
  • ShowModalTemplate: Use the template dialog box in the scene. Whenever show up new dialog, dialog box will be cloned.
  • ShowModal<T>: Use a passed dialog box whose type is T.
  • ShowModalRoot<T>: Use a named dialog box under Canvas/DialogBox in the scene.

For getting return value of it, there are two ways.

First one is using Hidden callback.

var handle = UiManager.Instance.ShowModalRoot<TestDialogBox>("Input your name?");
handle.Hidden += (dlg, val) => { Debug,Log(val); };

Second one is using coroutine. It's quite useful under modal chaining.

var handle = UiManager.Instance.ShowModalRoot<TestDialogBox>("Input your name?");
yield return StartCoroutine(handle.WaitForHide());
Debug.Log(handle.ReturnValue);

Common dialog boxes.

Common message box

MessageBox

UiMessageBox.Show("This is a message question <b>box</b>",
                  UiMessageBox.QuestionType.OkCancel,
                  r => { /* Callback */ });

Common input box

InputBox

UiInputBox.Show("Please input your name:",
                "Input",
                r => { /* Callback */ });

unity3d.uimanager's People

Contributors

veblush avatar

Watchers

James Cloos 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.