Skip to content

Add Static interface. #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LICENSE.meta
README.md.meta
38 changes: 27 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

A thread-safe way of dispatching IEnumerator functions to the main thread in unity. Useful for calling UI functions and other actions that Unity limits to the main thread from different threads. Initially written for Firebase Unity but now used across the board!

### Version
1.0 - Tested and functional in one or more production applications, including those from major companies.
## Version
1.0 - Tested and functional in one or more production applications, including those from major companies.

### Installation
1.1 - Added a static interface for easier useage.

## Installation

No dependencies needed other than Unity. This script was created in Unity 5.3, and has been tested in 5.3, 5.4, and 5.5 by the creators, but is being used across many more versions. If something breaks, let us know!

1. Download the UnityMainThreadDispatcher prefab and add it to your scene, or simple create an empty GameObject, call it UnityMainThreadDispatcher.
2. Download the UnityMainThreadDispatcher.cs script and add it to your prefab
3. You can now dispatch objects to the main thread in Unity.

### Usage
## Usage
```C#
public IEnumerator ThisWillBeExecutedOnTheMainThread() {
Debug.Log ("This is executed from the main thread");
Expand All @@ -26,20 +28,34 @@ No dependencies needed other than Unity. This script was created in Unity 5.3, a
OR

```C#
UnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log ("This is executed from the main thread"));
UnityMainThreadDispatcher.Instance().Enqueue(() => Debug.Log("This is executed from the main thread"));
```
### Development

Want to contribute? Great! If you find a bug or want to make improvements, simply fork the repo and make a pull request with your changes on your own fork.
OR

Also - I'm looking for additional maintainers who are still actively using this in production as I now run a startup and am not actively doing engineering work anymore.
```C#
UnityMainThreadDispatcher.Dispatch(() => Debug.Log("This is executed from the main thread"));
```

### Author
@PimDeWitte
OR

```C#
var result = UnityMainThreadDispatcher.Dispatch(() => Resource.Load<TextAsset>("test").text);
```

OR

```C#
var result = await UnityMainThreadDispatcher.DispatchAsync(() => Resource.Load<TextAsset>("test").text);
```

## Development

Want to contribute? Great! If you find a bug or want to make improvements, simply fork the repo and make a pull request with your changes on your own fork.

Also - I'm looking for additional maintainers who are still actively using this in production as I now run a startup and am not actively doing engineering work anymore.

## Author
@PimDeWitte

[@rwindegger](https://www.windegger.wtf "Windegger Rene")
Loading