Code Monkey home page Code Monkey logo

ui-manager-for-unity's Introduction

UI Manager for Unity

Created to help me, and maybe you, to navigate between Screens, load Screen Prefabs, update list of available Screens in Editor etc.

Install with Unity Package Manager

  • in Unity go to Windows > Package Manager
  • press + and select Add package from git URL...
https://github.com/gbviktor/ui-manager-for-unity.git

Getting Started

  • Import from Samples a UILoadResources sample
  • create a Folder UIScreens in Resources folder
  • now you can create a ScriptableObject from Asset Menu in created UIScreens folder
    • Montana Games/DB/Screens List
      • this Scriptable Object looking for Prefabs inside this Folder (Root only) of type UIScreen and update list of available Screens
      • just put your Prefab in this Folder to make it visible for UI Manager
  • after, you can create your first Screen inherited from/extends UIScreen class
    • see UITestScreen as a sample
  • before UI Manager can work, initialize it with followed code (do it once, this script use static fields)
[SerializeField] ScreensList screensList;

void Awake(){
	//setup a Loader and
	new UI(new UILoaderResources(screensList))
}
  • now, you can call UI.OpenScreen<UITestScreen>() or UI.OpenNested<UITestScreen>()
    • OpenNested open Screens with save previous Screen in Stack, to open it back again, if you close current. (also save history)

API

  • UI.Open<UIYourScreenType>()
    • open new Screen and close automatically Previous (disabled/removed)
  • UI.OpenNested<UIYourNextScreen>()
    • open new Screen, and save previous in History (stack) open it, if you close current
  • UI.OpenAndCloseAllPrevious<UIMyScreen>()
    • close all Screen (clear history/stack), and open requested Screen
  • UI.OnBackButtonPressed() - use it to handle users inputs,
    • this method will be close current Screen and open previous if History is not empty.
  • UI.ForceCloseAll() - force close all opened Screens or saved in History (Stack)
    • use this, for Scenes transitions, to clear history of opened screens.
  • UI.CloseCurrentFocusPrevious() - close current screen, focus previous
  • UI.Get<UIMyScreen>() - instantiate a Screen, but not Open it (don't call OnOpen event)
    • you can manipulate or execute with this Screen before open
      • but i will be not recommend this method, smell like a bad practice
  • UI.DestroyScreen<UIMyScreen>() - remove/destroy this screen from Scene
    • use it careful, only if you manually want close screen and can't use UI.CloseCurrentFocusPrevious()

Create your custom Screen

  • create a new Canvas in Scene
  • add you script/component inherited from UIScreen to this Canvas
  • rename it, i recommend to name it like UI(some your name)Screen
  • save this Canvas as Prefab in root of folder where a ScriptableObject of type ScreensList already exist, or create it inside
    • this SO help you, it's make a updatable list of available Screens inside folder where SO persistent
  • after this steps, you can call in your code UI.OpenNested<UISomeMyNewScreen>()
    • if you got error, check this step again.

Feedback is awaited

  • under development...

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.