• This repository has been archived on 07/Sep/2022
  • Stars
    star
    603
  • Rank 74,294 (Top 2 %)
  • Language
    C#
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

UIWidgets is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.

⚠ī¸ The main repository of UIWidgets is migrated to https://github.com/UIWidgets/com.unity.uiwidgets and developed at the new place. Although you can still report issues here, please try visit the new site to obtain the latest UIWidgets. Thanks!

UIWidgets 2.0 (preview)

中文

🚀 Join us 🚀

The team is now providing several open positions for full-time software engineer based in Shanghai, Unity China 🇨đŸ‡ŗ.

If you are skilled in Unity or flutter and interested in UIWidgets, please join our QQ Group: UIWidgets (Group ID: 234207153), WeChat Group: UIWidgets äēŒįž¤ or contact me directly (QQ: 541252510) for the oppotunity to Come and Build UIWidgets with us in Unity China!

Introduction

UIWidgets is a plugin package for Unity Editor which helps developers to create, debug and deploy efficient, cross-platform Apps using the Unity Engine.

UIWidgets is mainly derived from Flutter. However, taking advantage of the powerful Unity Engine, it offers developers many new features to improve their Apps as well as the develop workflow significantly.

UIWidgets 2.0 is developed for Unity China version deliberately and aims to optimize the overall performance of the package. Specifically, a performance gain around 10% is observed on mobile devices like iPhone 6 after upgrading to UIWidgets 2.0.

If you still want to use the original UIWidgets 1.0, please download the archived packages from Releases or switch your working branch to uiwidgets_1.0.

Efficiency

Using the latest Unity rendering SDKs, a UIWidgets App can run very fast and keep >60fps in most times.

Cross-Platform

A UIWidgets App can be deployed on all kinds of platforms including PCs and mobile devices directly, like any other Unity projects.

Multimedia Support

Except for basic 2D UIs, developers are also able to include 3D Models, audios, particle-systems to their UIWidgets Apps.

Developer-Friendly

A UIWidgets App can be debug in the Unity Editor directly with many advanced tools like CPU/GPU Profiling, FPS Profiling.

Example

Projects using UIWidgets

Unity Connect App

The Unity Connect App is created using UIWidgets 2.0 and available for both Android (https://unity.cn/connectApp/download) and iOS (Searching for "Unity Connect" in App Store). This project is open-sourced @https://github.com/UIWidgets/ConnectAppCN2.

Unity Chinese Doc

The official website of Unity Chinese Documentation (https://connect.unity.com/doc) is powered by UIWidgets 1.0 and open-sourced @https://github.com/UnityTech/DocCN.

Requirements

Unity

⚠ī¸ UIWidgets 2.0 are only compatible with Unity China version

Specifically, the compatible Unity versions for each UIWidgets release are listed below. You can download the latest Unity on https://unity.cn/releases.

UIWidgets version Unity 2019 LTS Unity 2020 LTS
1.5.4 and below 2019.4.10f1 and above N\A
2.0.1 2019.4.26f1c1 N\A
2.0.3 2019.4.26f1c1 ~ 2019.4.29f1c1 N\A
2.0.4 and above 2019.4.26f1c1 ~ 2019.4.29f1c1 2020.3.24f1c2 and above

UIWidgets Package (video tutorial)

Visit our Github repository https://github.com/Unity-Technologies/com.unity.uiwidgets to download the latest UIWidgets package.

Move the downloaded package folder into the root folder of your Unity project.

Generally, you can make it using a console (or terminal) application by just a few commands as below:

 cd <YourProjectPath>
 git clone https://github.com/Unity-Technologies/com.unity.uiwidgets.git com.unity.uiwidgets

Note that there are many native libraries we built for UIWidget 2.0 to boost its performance, which are large files and hosted by Git Large File Storage. You need to install this service first and then use it to fetch these libraries.

Finally, in PackageManger of unity, select add local file. select package.json under /com.unity.uiwidgets

Runtime Environment

⚠ī¸ Though UIWidgets 1.0 is compatible to all platforms, currently UIWidgets 2.0 only supports MacOS(Intel64, Metal/OpenGLCore), iOS(Metal/OpenGLes), Android(OpenGLes) and Windows(Direct3D11). More devices will be supported in the future.

Getting Start

i. Overview

In this tutorial, we will create a very simple UIWidgets App as the kick-starter. The app contains only a text label and a button. The text label will count the times of clicks upon the button.

First of all, please open or create a Unity Project and open it with Unity Editor.

ii. Scene Build

A UIWidgets App is usually built upon a Unity UI Canvas. Please follow the steps to create a UI Canvas in Unity.

  1. Create a new Scene by "File -> New Scene";
  2. Create a UI Canvas in the scene by "GameObject -> UI -> Canvas";
  3. Add a Panel (i.e., Panel 1) to the UI Canvas by right click on the Canvas and select "UI -> Panel". Then remove the Image Component from the Panel.

iii. Create Widget

A UIWidgets App is written in C# Scripts. Please follow the steps to create an App and play it in Unity Editor.

  1. Create a new C# Script named "UIWidgetsExample.cs" and paste the following codes into it.

     using System.Collections.Generic;
     using uiwidgets;
     using Unity.UIWidgets.cupertino;
     using Unity.UIWidgets.engine;
     using Unity.UIWidgets.ui;
     using Unity.UIWidgets.widgets;
     using Text = Unity.UIWidgets.widgets.Text;
     using ui_ = Unity.UIWidgets.widgets.ui_;
     using TextStyle = Unity.UIWidgets.painting.TextStyle;
    
     namespace UIWidgetsSample
     {
         public class UIWidgetsExample : UIWidgetsPanel
         {
             protected void OnEnable()
             {
                 // if you want to use your own font or font icons.
                     // AddFont("Material Icons", new List<string> {"MaterialIcons-Regular.ttf"}, new List<int> {0});
                 base.OnEnable();
             }
    
             protected override void main()
             {
                 ui_.runApp(new MyApp());
             }
    
             class MyApp : StatelessWidget
             {
                 public override Widget build(BuildContext context)
                 {
                     return new CupertinoApp(
                         home: new CounterApp()
                     );
                 }
             }
         }
    
         internal class CounterApp : StatefulWidget
         {
             public override State createState()
             {
                 return new CountDemoState();
             }
         }
    
         internal class CountDemoState : State<CounterApp>
         {
             private int count = 0;
    
             public override Widget build(BuildContext context)
             {
                 return new Container(
                     color: Color.fromARGB(255, 255, 0, 0),
                     child: new Column(children: new List<Widget>()
                         {
                             new Text($"count: {count}", style: new TextStyle(color: Color.fromARGB(255, 0 ,0 ,255))),
                             new CupertinoButton(
                                 onPressed: () =>
                                 {
                                     setState(() =>
                                     {
                                         count++;
                                     });
                                 },
                                 child: new Container(
                                     color: Color.fromARGB(255,0 , 255, 0),
                                     width: 100,
                                     height: 40
                                 )
                             ),
                         }
                     )
                 );
             }
         }
     }
  2. Save this script and attach it to Panel 1 as its component.

  3. Press the "Play" Button to start the App in Unity Editor.

iv. Build App

Finally, the UIWidgets App can be built to packages for any specific platform by the following steps.

  1. Open the Build Settings Panel by "File -> Build Settings..."
  2. Choose a target platform and click "Build". Then the Unity Editor will automatically assemble all relevant resources and generate the final App package.

How to load images?

  1. Put your images files in StreamingAssets folder. e.g. image1.png.
  2. Use Image.file("image1.png") to load the image.

UIWidgets supports Gif as well!

  1. Put your gif files in StreamingAssets folder. e.g. loading1.gif.
  2. Use Image.file("loading1.gif") to load the gif images.

Show Status Bar on Android

Status bar is always hidden by default when an Unity project is running on an Android device. If you want to show the status bar in your App, you can disableStart in fullscreen and record outside safe area, make sure showStatusBar is true under UIWidgetsAndroidConfiguration

Image Import Setting

Please put images under StreamingAssets folder, a and loading it using Image.file.

Show External Texture

You can use the new builtin API UIWidgetsExternalTextureHelper.createCompatibleExternalTexture to create a compatible render texture in Unity and render it on a Texture widget in UIWidgets. With the feature, you can easily embed 3d models, videos, etc. in your App.

Note that currently this feature is only supported for OpenGLCore (Mac), OpenGLes (iOS&Android) and D3D11 (Windows) with Unity 2020.3.37f1c1 and newer. A simple example (i.e., 3DTest1.unity) can be found in our sample project.

Performance Optimization on Mobile devices

By setting UIWidgetsGlobalConfiguration.EnableAutoAdjustFramerate = true in your project, UIWidgets will drop the frame rate of your App to 0 if the UI contents of UIWidgetsPanel is not changed for some time. This will help to prevent battery drain on mobile devices significantly. Note that this feature is disabled by default.

Long time garbage collection may cause App to stuck frequently. You can enable incremental garbage collection to avoid it. You can enable this feature by setting UIWidgetsGlobalConfiguration.EnableIncrementalGC = true, and enabling Project Setting -> Player -> Other Settings -> Use incremental GC.

Debug UIWidgets Application

In the Editor, you can switch debug/release mode by “UIWidgets->EnableDebug”.

In the Player, the debug/development build will enable debug mode. The release build will disable debug mode automatically.

Using Window Scope

If you see the error AssertionError: Window.instance is null or null pointer error of Window.instance, it means the code is not running in the window scope. In this case, you can enclose your code with window scope as below:

using(Isolate.getScope(the isolate of your App)) {
    // code dealing with UIWidgets,
    // e.g. setState(() => {....})
}

This is needed if the code is in methods not invoked by UIWidgets. For example, if the code is in completed callback of UnityWebRequest, you need to enclose them with window scope. Please see our HttpRequestSample for detail. For callback/event handler methods from UIWidgets (e.g Widget.build, State.initState...), you don't need do it yourself, since the framework ensure it's in window scope.

Learn

Samples

You can find many UIWidgets sample projects on Github, which cover different aspects and provide you learning materials in various levels:

Wiki

The develop team is still working on the UIWidgets Wiki. However, since UIWidgets is mainly derived from Flutter, you can refer to Flutter Wiki to access detailed descriptions of UIWidgets APIs from those of their Flutter counterparts. Meanwhile, you can join our discussion channel to keep in touch with the community.

FAQ

  1. The editor crashes when openning a UIWidgets 2.0 project, e.g., the Sample projects.

    Please make sure that you are using campatible Unity versions to the specific UIWidgets version. For example, UIWidgets 2.0.3 is only supported on Unity China version between 2019.4.26f1c1 and 2019.4.29f1c1. You can find the detailed information in this section.

  2. After openning a UIWidgets 2.0 project I receive an error DllNotFoundException: libUIWidgets.

    Please make sure that the native libraries are correctly downloaded to your project. You can find them under UIWidgetsPackageRoot/Runtime/Plugins. For example, the libUIWidgets.dll under the sub folder X86_64 is the native library for Windows and the libUIWidgets.dylib under osx is for Mac.

    If the libraries are not there or their sizes are small (<1MB), please ensure that you have installed Git Large File Storage in your computer and then try the following command line inside the UIWidgets repository.

    git lfs pull
    
  3. What is the difference between UIWidgets 2.0 and UIWidgets 1.0 ?

    In UIWidgets 1.0 we used Unity Graphics API for the rendering and all rendering codes are writen in C#. Therefore it is able to run freely on all platforms that Unity supports but relatively slow. The rendering result is also not exactly the same as in flutter due to the difference between the Unity rendering engine and flutter engine.

    In UIWidgets 2.0, we wrapped the flutter engine inside a native library which is writen in C++ and used it to render on Unity Textures. Its rendering result is the same as in flutter and the performance is also better. However, in order to ensure that the flutter engine works properly along with Unity, we modified both the flutter and Unity Engine. As the result, currently UIWidgets 2.0 can only run on specific Unity versions, i.e., Unity China version and supports only part of the build targets of Unity.

    For better rendering result, performance and continuous upgrade and support, you are always suggested to use UIWidgets 2.0 for your project. Use UIWidgets 1.0 only if you need to support specific target platforms like webgl.

  4. I encountered with a link error with OpenGLES for iOS build using UIWidgets 2.0 with Unity 2020.3LTS.

    This is caused by Unity because it removed the dependency on OpenGLES library on Unity 2020.3. To fix this issue, please open the XCode project and manually add the OpenGLES library to the UnityFramework target.

Contact Us

QQ Group: UIWidgets (Group ID: 234207153)

How to Contribute

Check CONTRIBUTING.md

More Repositories

1

ml-agents

The Unity Machine Learning Agents Toolkit (ML-Agents) is an open-source project that enables games and simulations to serve as environments for training intelligent agents using deep reinforcement learning and imitation learning.
C#
16,946
star
2

UnityCsReference

Unity C# reference source code.
C#
10,410
star
3

EntityComponentSystemSamples

C#
7,135
star
4

FPSSample

A first person multiplayer shooter example project in Unity
C#
4,864
star
5

PostProcessing

Post Processing Stack
C#
3,665
star
6

arfoundation-samples

Example content for Unity projects based on AR Foundation
C#
3,040
star
7

NavMeshComponents

High Level API Components for Runtime NavMesh Building
C#
3,008
star
8

BoatAttack

Demo Project using the Universal RP from Unity3D
C#
2,534
star
9

Graphics

Unity Graphics - Including Scriptable Render Pipeline
C#
2,504
star
10

com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
C#
2,138
star
11

AssetBundles-Browser

Editor tool for viewing and debugging asset bundle contents before and after builds
C#
1,940
star
12

UniversalRenderingExamples

This project contains a collection of Custom Renderer examples. This will be updated as we refine the feature and add more options.
C#
1,923
star
13

com.unity.multiplayer.samples.coop

A small-scale cooperative game sample built on the new, Unity networking framework to teach developers about creating a similar multiplayer game.
C#
1,595
star
14

VolumetricLighting

Lighting effects implemented for the Adam demo: volumetric fog, area lights and tube lights
C#
1,576
star
15

Unity-Robotics-Hub

Central repository for tools, tutorials, resources, and documentation for robotics simulation in Unity.
C#
1,544
star
16

AutoLOD

Automatic LOD generation + scene optimization
C#
1,534
star
17

VisualEffectGraph-Samples

Visual Effect Graph - Samples Project
C#
1,498
star
18

InputSystem

An efficient and versatile input system for Unity.
C#
1,428
star
19

game-programming-patterns-demo

A repo of small demos that assemble some of the well-known design patterns in Unity development to support the ebook "Level up your code with game programming patterns"
C#
1,427
star
20

2d-extras

Fun 2D Stuff that we'd like to share!
C#
1,387
star
21

Animation-Instancing

This technique is designed to instance Characters(SkinnedMeshRender).
C#
1,366
star
22

Unity.Mathematics

The C# math library used in Unity providing vector types and math functions with a shader like syntax
C#
1,354
star
23

multiplayer

Unity multiplayer packages and samples
1,328
star
24

UnityRenderStreaming

Streaming server for Unity
C#
1,306
star
25

DOTS-training-samples

Samples designed as exercises to be ported from Unity GameObjects/MonoBehaviours to Unity DOTS.
C#
1,281
star
26

Addressables-Sample

Demo project using Addressables package
C#
1,277
star
27

ShaderGraph

Unity ShaderGraph project
C#
1,154
star
28

AssetGraph

Visual Workflow Automation Tool for Unity.
C#
1,088
star
29

XR-Interaction-Toolkit-Examples

This repository contains various examples to use with the XR Interaction Toolkit
C#
1,068
star
30

FontainebleauDemo

Fontainebleau demo
C#
947
star
31

uGUI

Source code for the Unity UI system.
C#
937
star
32

DOTSSample

A third person, multiplayer sample project. Built with Unity and using the new Data Oriented Tech Stack (DOTS).
C#
932
star
33

EditorXR

Author XR in XR
C#
925
star
34

SpaceshipDemo

Spaceship Demo - AAA Playable First person demo showcasing effects made with Visual Effect Graph and rendered with High Definition Render Pipeline
C#
916
star
35

VFXToolbox

Additional tools for Visual Effect Artists
C#
909
star
36

2d-techdemos

Tech Demos for Unity 2D Features
C#
881
star
37

ProjectTinySamples

Samples for Project Tiny
C#
880
star
38

HLODSystem

C#
844
star
39

ProjectAuditor

Project Auditor is an experimental static analysis tool for Unity Projects.
C#
815
star
40

UnityPlayground

A collection of simple scripts to create 2D physics game, intended for giving workshops to a young audience
C#
806
star
41

com.unity.formats.alembic

Alembic importer and exporter plugin for Unity
C#
786
star
42

HLSLcc

DirectX shader bytecode cross compiler
C++
770
star
43

com.unity.webrtc

WebRTC package for Unity
Assembly
753
star
44

giles

GILES: A Runtime Level Editor for Unity3D
C#
743
star
45

com.unity.perception

Perception toolkit for sim2real training and validation in Unity
C#
734
star
46

BackgroundDownload

Plugins for mobile platforms to enable file downloads in background
C#
721
star
47

UniteAustinTechnicalPresentation

C#
721
star
48

com.unity.demoteam.hair

An integrated solution for authoring / importing / simulating / rendering strand-based hair in Unity.
C#
712
star
49

SuperScience

Gems of Unity Labs for our user-base.
C#
711
star
50

com.unity.multiplayer.docs

Open Source documentation for Unity Multiplayer, which includes Netcode for GameObjects, the Unity Transport Package, Multiplayer Tools and Educational references and Sample Games such as Boss Room.
JavaScript
634
star
51

NativeRenderingPlugin

C++ Rendering Plugin example for Unity
C
633
star
52

guid-based-reference

A component for giving Game Objects a GUID and a class to create references to objects in any Scene by GUID
C#
615
star
53

uaal-example

Objective-C++
605
star
54

Standard-Assets-Characters

Unity Standard Asset Controllers
C#
602
star
55

megacity-metro

Megacity-Metro: a thrilling shooter game, using Netcode for Entities for a multiplayer experience supporting 128+ players. Latest DOTS packages and Unity Gaming Services elevate the user experience, demonstrating how to craft engaging multiplayer games.
C#
567
star
56

barracuda-release

C#
565
star
57

MeshApiExamples

Example project for Unity 2020.1 Mesh API improvements
C#
558
star
58

unity-cache-server

Unity CacheServer optimized for multi-client local networks
JavaScript
554
star
59

SimpleAnimation

A simple Animation Component that leverages PlayableGraphs
C#
539
star
60

GenericFrameRecorder

This GitHub package is DEPRECATED. Please get the new Unity Recorder from the Asset Store (https://assetstore.unity.com/packages/essentials/unity-recorder-94079) Use the editor builtin Bug Reporter to report issues. You can track and vote for issues on the Issue Tracker (https://issuetracker.unity3d.com)
C#
533
star
61

obstacle-tower-env

Obstacle Tower Environment
Python
532
star
62

graph-visualizer

Visualizer for your Playable graphs
C#
522
star
63

DeLightingTool

De-Lighting tool
C#
518
star
64

com.unity.demoteam.digital-human

Library of tech features used to realize the digital human from 'The Heretic' and 'Enemies'.
C#
517
star
65

PhysicsExamples2D

Examples of various Unity 2D Physics components and features.
C#
512
star
66

com.unity.cinemachine

Smart camera tools for passionate creators
C#
503
star
67

usd-unity-sdk

Integration of Pixar's Universal Scene Description into Unity. UPDATE: This package has been superseded by our new bundle of USD packages. Please see README & link below for further details.
C#
498
star
68

arfoundation-demos

AR Foundation demo projects
C#
494
star
69

facial-ar-remote

**This project is discontinued** Facial AR Remote is a tool that allows you to capture blendshape animations directly from your iPhone X into Unity 3d by use of an app on your phone.
C#
482
star
70

animation-jobs-samples

Code samples using the animation C# jobs feature.
C#
464
star
71

vscode-unity-debug

Unity debugging support for VS Code
C#
459
star
72

MeshSyncDCCPlugins

DCC plugins for MeshSync in Unity. Supported tools: Maya, Maya LT, 3ds Max, Motion Builder, Modo, Blender, Metasequoia
C++
438
star
73

UIElementsExamples

Unity project containing examples to use UIElements in the Editor
C#
436
star
74

Unity.Animation.Samples

Repository of projects that showcase the new DOTS animation package (com.unity.animation).
C#
419
star
75

com.unity.demoteam.mesh-to-sdf

A light and fast real-time SDF generator, primarily for animated characters. The dynamic SDF can be used for all sorts of VFX. Also enables hair-to-character collisions in the new hair package.
C#
402
star
76

MeasuredMaterialLibraryURP

HLSL
377
star
77

BatchBreakingCause

This project demonstrates different cases when Unity has to break a batch while rendering.
GLSL
355
star
78

MeasuredMaterialLibraryHDRP

C#
355
star
79

UIToolkitUnityRoyaleRuntimeDemo

This is a sample project to introduce the use of UI Toolkit in Runtime
C#
351
star
80

UnityDataTools

Experimental tools and libraries for reading and analyzing Unity data files.
C#
328
star
81

HDRPRayTracingScenes

This repository contains a startup DXR project.
327
star
82

SynthDet

SynthDet - An end-to-end object detection pipeline using synthetic data
C#
324
star
83

EndlessRunnerSampleGame

Repository for the Endless Runner Game Sample (Trash Dash)
C#
324
star
84

boat-attack-water

Package repo containing the water system created for the URP Boat Attack demo project.
C#
318
star
85

BuildReportInspector

Editor script which implements an inspector for the BuildReport class
C#
317
star
86

multiplayer-community-contributions

Community contributions to Unity Multiplayer Networking products and services.
C#
316
star
87

com.unity.services.samples.use-cases

The collection of samples in this repo use Unity Gaming Services in a Unity project to demonstrate live gaming operations.
C#
312
star
88

com.unity.probuilder

C#
305
star
89

XRLineRenderer

An XR-Focused line renderer that mimics rendering with 3d capsules while only using two quads worth of geometry.
C#
299
star
90

com.unity.demoteam.digital-human.sample

Character sample featuring the digital human from 'The Heretic'.
C#
298
star
91

VRAlchemyLab

VR Demo project using HDRP and unity 2019.3
C#
283
star
92

marathon-envs

A set of high-dimensional continuous control environments for use with Unity ML-Agents Toolkit.
C#
279
star
93

articulations-robot-demo

C#
278
star
94

NotificationsSamples

Sample project for Unity Notifications
C#
265
star
95

SkyboxPanoramicShader

Skybox shader for support of 360/180/cubemap video and static content
ShaderLab
265
star
96

PeopleSansPeople

Unity's privacy-preserving human-centric synthetic data generator
C#
261
star
97

Robotics-Object-Pose-Estimation

A complete end-to-end demonstration in which we collect training data in Unity and use that data to train a deep neural network to predict the pose of a cube. This model is then deployed in a simulated robotic pick-and-place task.
Python
250
star
98

ECS-Network-Racing-Sample

ECS multiplayer racing sample to showcase using Unity Entities and netcode with best practices
C#
248
star
99

2d-pixel-perfect

Pixel Perfect Camera
C#
244
star
100

ShaderGraph-Custom-Lighting

A sample project showcasing a simple method to calculate custom lighting inside of Shader Graph for the Lightweight Render Pipeline. Includes a sample toon shaded scene and example assets. Built for Unity 2019.2 .
Mathematica
244
star