Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
fixed samples, ReadMe for Release 4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Aug 19, 2014
1 parent ae9c01d commit 71ed7f3
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 35 deletions.
14 changes: 7 additions & 7 deletions Assets/ObjectTest/NewBehaviourScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public override void Start()
// DoubleCLick Sample of
// The introduction to Reactive Programming you've been missing
// https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
//OnMouseDownAsObservable().Buffer(OnMouseDownAsObservable().Throttle(TimeSpan.FromMilliseconds(250)))
// .Where(xs =>
// {
// logger.Debug(xs.Count);
// return xs.Count >= 2;
// })
// .Subscribe(_ => logger.Debug("Double Click Detected"));

//var clickStream = Observable.EveryUpdate()
// .Where(_ => Input.GetMouseButtonDown(0));

//clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
// .Where(xs => xs.Count >= 2)
// .Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));

base.Start();
}
Expand Down
4 changes: 3 additions & 1 deletion Assets/UniRx/Examples/Sample04_ConvertFromUnityCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ namespace UniRx.Examples
{
public class Sample04_ConvertFromUnityCallback : TypedMonoBehaviour
{
// This is about log but more reliable log sample => Sample11_Logger

private class LogCallback
{
public string Condition;
public string StackTrace;
public UnityEngine.LogType LogType;
}

private static class LogHelper
static class LogHelper
{
static Subject<LogCallback> subject;

Expand Down
11 changes: 11 additions & 0 deletions Assets/UniRx/Examples/Sample06_ConvertToCoroutine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,16 @@ public class Sample06_ConvertToCoroutine : TypedMonoBehaviour

Debug.Log(v); // 10(callback is last value)
}

// like WWW.text/error, LazyTask is awaitable value container
IEnumerator LazyTaskTest()
{
// IObservable<T>
var task = Observable.Start(() => 100).ToLazyTask();

yield return task.Start(); // wait for OnCompleted

Debug.Log(task.Result); // or task.Exception
}
}
}
22 changes: 10 additions & 12 deletions Assets/UniRx/Examples/Sample08_DetectDoubleClick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ public override void Awake()
// Observable.EveryApplicationFocus/EveryApplicationPause
// Observable.OnceApplicationQuit

var detected = false;
Observable.EveryUpdate()
.Where(_ => Input.GetMouseButtonDown(0))
.Buffer(TimeSpan.FromMilliseconds(300), TimeSpan.FromMilliseconds(100))
.Where(xs => xs.Count >= 2 && !detected)
.Do(_ =>
{
detected = true;
Scheduler.ThreadPool.Schedule(TimeSpan.FromSeconds(1), () => detected = false);
})
.ObserveOnMainThread()
.Subscribe(_ => Debug.Log("DoubleClick Detected"));
// This DoubleCLick Sample is from
// The introduction to Reactive Programming you've been missing
// https://gist.github.com/staltz/868e7e9bc2a7b8c1f754

var clickStream = Observable.EveryUpdate()
.Where(_ => Input.GetMouseButtonDown(0));

clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
.Where(xs => xs.Count >= 2)
.Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));
}
}
}
11 changes: 6 additions & 5 deletions Assets/UniRx/Examples/Sample10_MainThreadDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public void Run()
// Add Action to MainThreadDispatcher. Action is saved queue, run on next update.
MainThreadDispatcher.Post(() => Debug.Log("test"));

// Timebased operations is run on Threadpool(as default)
// ObserveOnMainThread return to mainthread
// Timebased operations is run on MainThread(as default)
// All timebased operation(Interval, Timer, Delay, Buffer, etc...)is single thread, thread safe!
Observable.Interval(TimeSpan.FromSeconds(1))
.ObserveOnMainThread()
.Subscribe(x => Debug.Log(x));

// Run on MainThreadScheduler
Observable.Interval(TimeSpan.FromSeconds(1), Scheduler.MainThread)
// Observable.Start use ThreadPool Scheduler as default.
// ObserveOnMainThread return to mainthread
Observable.Start(() => Unit.Default) // asynchronous work
.ObserveOnMainThread()
.Subscribe(x => Debug.Log(x));
}

Expand Down
35 changes: 33 additions & 2 deletions Assets/UniRx/ReadMe.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
UniRx - Reactive Extensions for Unity / ver.4.4
UniRx - Reactive Extensions for Unity / ver.4.5
===
Created by Yoshifumi Kawai(neuecc)

What is UniRx?
---
UniRx(Reactive Extensions for Unity) is re-implementation of .NET Reactive Extensions.
It's free and open source on GitHub.
It's free and open source on GitHub.
Supported platforms are PC/Android/iOS/WP8/WindowsStore.
You can check latest info, source code and issues on https://github.com/neuecc/UniRx
We welcome to your contribute such as bug report, request, and pull request.

Expand All @@ -32,6 +33,26 @@ Rx considere event as reactive sequence which is possible to compose and perform

Unity is single thread but UniRx helps multithreading for join, cancel, access GameObject etc.

The Introduction
---
Great introduction article of Rx - [The introduction to Reactive Programming you've been missing](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754). Following code is same sample of detect double click.

```
var clickStream = Observable.EveryUpdate()
.Where(_ => Input.GetMouseButtonDown(0));

clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
.Where(xs => xs.Count >= 2)
.Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));
```

This example includes the following contents(In only five lines!).

* Game loop(Update) as event stream
* Event stream is composable
* Merging self stream
* Easily handle time based operation

How to Use for WWW
---
async operation, use ObservableWWW, it's Get/Post returns IObservable.
Expand Down Expand Up @@ -237,6 +258,16 @@ Observable.WhenAll(heavyMethod, heavyMethod2)
});
```

DefaultScheduler
---
UniRx's default time based operation(Interval, Timer, Buffer(timeSpan), etc...)'s Scheduler is Scheduler.MainThread.
It means most operator(excpet Observable.Start) is work on single-thread,
you don't need ObserverOn and you don't mind thread safety.
It's differece with RxNet but better fit to Unity environment.

Scheduler.MainThread under Time.timeScale's influence.
If you want to ignore, use Scheduler.MainThreadIgnoreTimeScale.

How to Use for MonoBehaviour
---
UniRx has two extended MonoBehaviour. TypedMonoBehaviour is typesafe MonoBehaviour.
Expand Down
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Created by Yoshifumi Kawai(neuecc)

What is UniRx?
---
UniRx(Reactive Extensions for Unity) is re-implementation of .NET Reactive Extensions. Official Rx is great but can't work on Unity and has some issue of iOS AOT. This library remove there issues and add some specified utility for Unity.
UniRx(Reactive Extensions for Unity) is re-implementation of .NET Reactive Extensions. Official Rx is great but can't work on Unity and has some issue of iOS AOT. This library remove there issues and add some specified utility for Unity. Supported platforms are PC/Android/iOS/WP8/WindowsStore.

UniRx is available in Unity Asset Store(FREE) - http://u3d.as/content/neuecc/uni-rx-reactive-extensions-for-unity/7tT

Expand All @@ -30,6 +30,26 @@ GameLoop(every Update, OnCollisionEnter, etc), Sensor(like Kinect, Leap Motion,

Unity is single thread but UniRx helps multithreading for join, cancel, access GameObject etc.

The Introduction
---
Great introduction article of Rx - [The introduction to Reactive Programming you've been missing](https://gist.github.com/staltz/868e7e9bc2a7b8c1f754). Following code is same sample of detect double click.

```
var clickStream = Observable.EveryUpdate()
.Where(_ => Input.GetMouseButtonDown(0));
clickStream.Buffer(clickStream.Throttle(TimeSpan.FromMilliseconds(250)))
.Where(xs => xs.Count >= 2)
.Subscribe(xs => Debug.Log("DoubleClick Detected! Count:" + xs.Count));
```

This example includes the following contents(In only five lines!).

* Game loop(Update) as event stream
* Event stream is composable
* Merging self stream
* Easily handle time based operation

How to Use for WWW
---
async operation, use ObservableWWW, it's Get/Post returns IObservable.
Expand Down Expand Up @@ -235,6 +255,13 @@ Observable.WhenAll(heavyMethod, heavyMethod2)
});
```

DefaultScheduler
---
UniRx's default time based operation(Interval, Timer, Buffer(timeSpan), etc...)'s Scheduler is `Scheduler.MainThread`.It means most operator(excpet `Observable.Start`) is work on single-thread, you don't need ObserverOn and you don't mind thread safety. It's differece with RxNet but better fit to Unity environment.

`Scheduler.MainThread` under Time.timeScale's influence.If you want to ignore, use ` Scheduler.MainThreadIgnoreTimeScale`.


How to Use for MonoBehaviour
---
UniRx has two extended MonoBehaviour. TypedMonoBehaviour is typesafe MonoBehaviour.
Expand Down
12 changes: 5 additions & 7 deletions UnityVS.UniRx.CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,30 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{55DB241B-2717-422C-3093-18D20F58B73B}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>
</RootNamespace>
<RootNamespace></RootNamespace>
<AssemblyName>Assembly-CSharp</AssemblyName>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Unity Subset v3.5</TargetFrameworkProfile>
<CompilerResponseFile>
</CompilerResponseFile>
<CompilerResponseFile></CompilerResponseFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Debug\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>DEBUG;TRACE;UNITY_4_5_1;UNITY_4_5;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE</DefineConstants>
<DefineConstants>DEBUG;TRACE;UNITY_4_5_1;UNITY_4_5;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>false</Optimize>
<OutputPath>Temp\UnityVS_bin\Release\</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DefineConstants>TRACE;UNITY_4_5_1;UNITY_4_5;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN;UNITY_PRO_LICENSE</DefineConstants>
<DefineConstants>TRACE;UNITY_4_5_1;UNITY_4_5;UNITY_STANDALONE_WIN;ENABLE_MICROPHONE;ENABLE_TEXTUREID_MAP;ENABLE_UNITYEVENTS;ENABLE_NEW_HIERARCHY ;ENABLE_AUDIO_FMOD;UNITY_STANDALONE;ENABLE_MONO;ENABLE_TERRAIN;ENABLE_SUBSTANCE;ENABLE_GENERICS;INCLUDE_WP8SUPPORT;ENABLE_MOVIES;ENABLE_WWW;ENABLE_IMAGEEFFECTS;ENABLE_WEBCAM;INCLUDE_METROSUPPORT;RENDER_SOFTWARE_CURSOR;ENABLE_NETWORK;ENABLE_PHYSICS;ENABLE_CACHING;ENABLE_CLOTH;ENABLE_2D_PHYSICS;ENABLE_SHADOWS;ENABLE_AUDIO;ENABLE_NAVMESH_CARVING;ENABLE_DUCK_TYPING;ENABLE_SINGLE_INSTANCE_BUILD_SETTING;DEVELOPMENT_BUILD;ENABLE_PROFILER;UNITY_EDITOR;UNITY_EDITOR_WIN</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
Expand Down Expand Up @@ -133,4 +131,4 @@
<None Include="Assets\UniRx\ReadMe.txt" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2013\UnityVS.CSharp.targets" />
</Project>
</Project>

0 comments on commit 71ed7f3

Please sign in to comment.