UniRx 에셋 추가

This commit is contained in:
Mingu Kim
2025-06-02 00:27:36 +09:00
parent 915f292d7d
commit 8a54d47b56
510 changed files with 42973 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
#if !(UNITY_METRO || UNITY_WP8)
#if UNITY_2018_3_OR_NEWER
#pragma warning disable CS0618
#endif
using UnityEngine;
namespace UniRx.Examples
{
// sample script, attach your object.
public class Sample01_ObservableWWW : MonoBehaviour
{
void Start()
{
// Basic: Download from google.
{
ObservableWWW.Get("http://google.co.jp/")
.Subscribe(
x => Debug.Log(x.Substring(0, 100)), // onSuccess
ex => Debug.LogException(ex)); // onError
}
// Linear Pattern with LINQ Query Expressions
// download after google, start bing download
{
var query = from google in ObservableWWW.Get("http://google.com/")
from bing in ObservableWWW.Get("http://bing.com/")
select new { google, bing };
var cancel = query.Subscribe(x => Debug.Log(x.google.Substring(0, 100) + ":" + x.bing.Substring(0, 100)));
// Call Dispose is cancel downloading.
cancel.Dispose();
}
// Observable.WhenAll is for parallel asynchronous operation
// (It's like Observable.Zip but specialized for single async operations like Task.WhenAll of .NET 4)
{
var parallel = Observable.WhenAll(
ObservableWWW.Get("http://google.com/"),
ObservableWWW.Get("http://bing.com/"),
ObservableWWW.Get("http://unity3d.com/"));
parallel.Subscribe(xs =>
{
Debug.Log(xs[0].Substring(0, 100)); // google
Debug.Log(xs[1].Substring(0, 100)); // bing
Debug.Log(xs[2].Substring(0, 100)); // unity
});
}
// with Progress
{
// notifier for progress
var progressNotifier = new ScheduledNotifier<float>();
progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress
// pass notifier to WWW.Get/Post
ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
}
// with Error
{
// If WWW has .error, ObservableWWW throws WWWErrorException to onError pipeline.
// WWWErrorException has RawErrorMessage, HasResponse, StatusCode, ResponseHeaders
ObservableWWW.Get("http://www.google.com/404")
.CatchIgnore((WWWErrorException ex) =>
{
Debug.Log(ex.RawErrorMessage);
if (ex.HasResponse)
{
Debug.Log(ex.StatusCode);
}
foreach (var item in ex.ResponseHeaders)
{
Debug.Log(item.Key + ":" + item.Value);
}
})
.Subscribe();
}
}
}
}
#endif
#if UNITY_2018_3_OR_NEWER
#pragma warning restore CS0618
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bf3770fc51ac89f45987dbde37ae81bd
timeCreated: 1455373901
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,24 @@
using UnityEngine;
using UniRx.Triggers; // Triggers Namepsace
using System;
namespace UniRx.Examples
{
public class Sample02_ObservableTriggers : MonoBehaviour
{
void Start()
{
// Get the plain object
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
// Add ObservableXxxTrigger for handle MonoBehaviour's event as Observable
cube.AddComponent<ObservableUpdateTrigger>()
.UpdateAsObservable()
.SampleFrame(30)
.Subscribe(x => Debug.Log("cube"), () => Debug.Log("destroy"));
// destroy after 3 second:)
GameObject.Destroy(cube, 3f);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cb5e978d683e94f4d9c2c81be80f93a7
timeCreated: 1455373901
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
using UnityEngine;
using UniRx.Triggers; // for enable gameObject.EventAsObservbale()
namespace UniRx.Examples
{
public class Sample03_GameObjectAsObservable : MonoBehaviour
{
void Start()
{
// All events can subscribe by ***AsObservable if enables UniRx.Triggers
this.OnMouseDownAsObservable()
.SelectMany(_ => this.gameObject.UpdateAsObservable())
.TakeUntil(this.gameObject.OnMouseUpAsObservable())
.Select(_ => Input.mousePosition)
.RepeatUntilDestroy(this)
.Subscribe(x => Debug.Log(x), ()=> Debug.Log("!!!" + "complete"));
}
}
}
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 005e349e5ccdd2b47bddc813b81afe40
timeCreated: 1455373897
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,66 @@
using System;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample04_ConvertFromUnityCallback : MonoBehaviour
{
// This is about log but more reliable log sample => Sample11_Logger
private class LogCallback
{
public string Condition;
public string StackTrace;
public UnityEngine.LogType LogType;
}
static class LogHelper
{
// If static register callback, use Subject for event branching.
#if (UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7)
static Subject<LogCallback> subject;
public static IObservable<LogCallback> LogCallbackAsObservable()
{
if (subject == null)
{
subject = new Subject<LogCallback>();
// Publish to Subject in callback
UnityEngine.Application.RegisterLogCallback((condition, stackTrace, type) =>
{
subject.OnNext(new LogCallback { Condition = condition, StackTrace = stackTrace, LogType = type });
});
}
return subject.AsObservable();
}
#else
// If standard evetns, you can use Observable.FromEvent.
public static IObservable<LogCallback> LogCallbackAsObservable()
{
return Observable.FromEvent<Application.LogCallback, LogCallback>(
h => (condition, stackTrace, type) => h(new LogCallback { Condition = condition, StackTrace = stackTrace, LogType = type }),
h => Application.logMessageReceived += h, h => Application.logMessageReceived -= h);
}
#endif
}
void Awake()
{
// method is separatable and composable
LogHelper.LogCallbackAsObservable()
.Where(x => x.LogType == LogType.Warning)
.Subscribe(x => Debug.Log(x));
LogHelper.LogCallbackAsObservable()
.Where(x => x.LogType == LogType.Error)
.Subscribe(x => Debug.Log(x));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 73e69fd4bbb724045a4e06050fbc5af3
timeCreated: 1455373899
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections;
using System.Threading;
using UnityEngine;
#if UNITY_2018_3_OR_NEWER
#pragma warning disable CS0618
#endif
namespace UniRx.Examples
{
public class Sample05_ConvertFromCoroutine
{
// public method
public static IObservable<string> GetWWW(string url)
{
// convert coroutine to IObservable
return Observable.FromCoroutine<string>((observer, cancellationToken) => GetWWWCore(url, observer, cancellationToken));
}
// IEnumerator with callback
static IEnumerator GetWWWCore(string url, IObserver<string> observer, CancellationToken cancellationToken)
{
var www = new UnityEngine.WWW(url);
while (!www.isDone && !cancellationToken.IsCancellationRequested)
{
yield return null;
}
if (cancellationToken.IsCancellationRequested) yield break;
if (www.error != null)
{
observer.OnError(new Exception(www.error));
}
else
{
observer.OnNext(www.text);
observer.OnCompleted();
}
}
}
}
#if UNITY_2018_3_OR_NEWER
#pragma warning restore CS0618
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 41f3df73f7da66b4980f6d9a86927796
timeCreated: 1455373898
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample06_ConvertToCoroutine : MonoBehaviour
{
// convert IObservable to Coroutine
void Start()
{
StartCoroutine(ComplexCoroutineTest());
}
IEnumerator ComplexCoroutineTest()
{
yield return new WaitForSeconds(1);
var v = default(int);
yield return Observable.Range(1, 10).StartAsCoroutine(x => v = x);
Debug.Log(v); // 10(callback is last value)
yield return new WaitForSeconds(3);
yield return Observable.Return(100).StartAsCoroutine(x => v = x);
Debug.Log(v); // 100
}
// Note:ToAwaitableEnumerator/StartAsCoroutine/LazyTask are obsolete way on Unity 5.3
// You can use ToYieldInstruction.
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
#if UNITY_2018_3_OR_NEWER
#pragma warning disable CS0618
#endif
IEnumerator TestNewCustomYieldInstruction()
{
// wait Rx Observable.
yield return Observable.Timer(TimeSpan.FromSeconds(1)).ToYieldInstruction();
// you can change the scheduler(this is ignore Time.scale)
yield return Observable.Timer(TimeSpan.FromSeconds(1), Scheduler.MainThreadIgnoreTimeScale).ToYieldInstruction();
// get return value from ObservableYieldInstruction
var o = ObservableWWW.Get("http://unity3d.com/").ToYieldInstruction(throwOnError: false);
yield return o;
if (o.HasError) { Debug.Log(o.Error.ToString()); }
if (o.HasResult) { Debug.Log(o.Result); }
// other sample(wait until transform.position.y >= 100)
yield return this.ObserveEveryValueChanged(x => x.transform).FirstOrDefault(x => x.position.y >= 100).ToYieldInstruction();
}
#if UNITY_2018_3_OR_NEWER
#pragma warning restore CS0618
#endif
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5da8247fbc4a4c84e96a727b44903214
timeCreated: 1455373899
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,45 @@
#pragma warning disable 0168
#pragma warning disable 0219
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample07_OrchestratIEnumerator : MonoBehaviour
{
// two coroutines
IEnumerator AsyncA()
{
Debug.Log("a start");
yield return new WaitForSeconds(3);
Debug.Log("a end");
}
IEnumerator AsyncB()
{
Debug.Log("b start");
yield return new WaitForEndOfFrame();
Debug.Log("b end");
}
void Start()
{
// after completed AsyncA, run AsyncB as continuous routine.
// UniRx expands SelectMany(IEnumerator) as SelectMany(IEnumerator.ToObservable())
var cancel = Observable.FromCoroutine(AsyncA)
.SelectMany(AsyncB)
.Subscribe();
// If you want to stop Coroutine(as cancel), call subscription.Dispose()
// cancel.Dispose();
}
}
}
#pragma warning restore 0219
#pragma warning restore 0168

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d437607dfffa8ff428bda3366354078d
timeCreated: 1455373901
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample08_DetectDoubleClick : MonoBehaviour
{
void Start()
{
// Global event handling is very useful.
// UniRx can handle there events.
// Observable.EveryUpdate/EveryFixedUpdate/EveryEndOfFrame
// Observable.EveryApplicationFocus/EveryApplicationPause
// Observable.OnceApplicationQuit
// 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));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: eb801bbfb1ffcd64389e90c8f2435b79
timeCreated: 1455373902
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,69 @@
#pragma warning disable 0067
using System;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample09_EventHandling : MonoBehaviour
{
public class MyEventArgs : EventArgs
{
public int MyProperty { get; set; }
}
public event EventHandler<MyEventArgs> FooBar;
public event Action<int> FooFoo;
CompositeDisposable disposables = new CompositeDisposable();
// Subject is Rx's native event expression and recommend way for use Rx as event.
// Subject.OnNext as fire event,
// expose IObserver is subscibable for external source, it's no need convert.
Subject<int> onBarBar = new Subject<int>();
public IObservable<int> OnBarBar { get { return onBarBar; } }
void Start()
{
// convert to IO<EventPattern> as (sender, eventArgs)
Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>(
h => h.Invoke, h => FooBar += h, h => FooBar -= h)
.Subscribe()
.AddTo(disposables); // IDisposable can add to collection easily by AddTo
// convert to IO<EventArgs>, many situation this is useful than FromEventPattern
Observable.FromEvent<EventHandler<MyEventArgs>, MyEventArgs>(
h => (sender, e) => h(e), h => FooBar += h, h => FooBar -= h)
.Subscribe()
.AddTo(disposables);
// You can convert Action like event.
Observable.FromEvent<int>(
h => FooFoo += h, h => FooFoo -= h)
.Subscribe()
.AddTo(disposables);
// AOT Safe EventHandling, use dummy capture, see:https://github.com/neuecc/UniRx/wiki/AOT-Exception-Patterns-and-Hacks
var capture = 0;
Observable.FromEventPattern<EventHandler<MyEventArgs>, MyEventArgs>(h =>
{
capture.GetHashCode(); // dummy for AOT
return new EventHandler<MyEventArgs>(h);
}, h => FooBar += h, h => FooBar -= h)
.Subscribe()
.AddTo(disposables);
// Subject as like event.
OnBarBar.Subscribe().AddTo(disposables);
onBarBar.OnNext(1); // fire event
}
void OnDestroy()
{
// manage subscription lifecycle
disposables.Dispose();
}
}
}
#pragma warning restore 0067

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 95140e49213aa6f49a470a81873b87c0
timeCreated: 1455373900
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample10_MainThreadDispatcher
{
public void Run()
{
// MainThreadDispatcher is heart of Rx and Unity integration
// StartCoroutine can start coroutine besides MonoBehaviour.
MainThreadDispatcher.StartCoroutine(TestAsync());
// We have two way of run coroutine, FromCoroutine or StartCoroutine.
// StartCoroutine is Unity primitive way and it's awaitable by yield return.
// FromCoroutine is Rx, it's composable and cancellable by subscription's IDisposable.
// FromCoroutine's overload can have return value, see:Sample05_ConvertFromCoroutine
Observable.FromCoroutine(TestAsync).Subscribe();
// Add Action to MainThreadDispatcher. Action is saved queue, run on next update.
MainThreadDispatcher.Post(_ => Debug.Log("test"), null);
// 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))
.Subscribe(x => Debug.Log(x));
// Observable.Start use ThreadPool Scheduler as default.
// ObserveOnMainThread return to mainthread
Observable.Start(() => Unit.Default) // asynchronous work
.ObserveOnMainThread()
.Subscribe(x => Debug.Log(x));
}
IEnumerator TestAsync()
{
Debug.Log("a");
yield return new WaitForSeconds(1);
Debug.Log("b");
yield return new WaitForSeconds(1);
Debug.Log("c");
yield return new WaitForSeconds(1);
Debug.Log("d");
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6a0b959735346af48b772254afc8afdd
timeCreated: 1455373899
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections;
using UniRx.Diagnostics;
using UnityEngine;
namespace UniRx.Examples
{
public class Sample11_Logger
{
// UniRx.Diagnostics.Logger
// logger is threadsafe, define per class with name.
static readonly UniRx.Diagnostics.Logger logger = new UniRx.Diagnostics.Logger("Sample11");
// call once at applicationinit
public void ApplicationInitialize()
{
// Log as Stream, UniRx.Diagnostics.ObservableLogger.Listener is IObservable<LogEntry>
// You can subscribe and output to any place.
ObservableLogger.Listener.LogToUnityDebug();
// for example, filter only Exception and upload to web.
// (make custom sink(IObserver<EventEntry>) is better to use)
ObservableLogger.Listener
.Where(x => x.LogType == LogType.Exception)
.Subscribe(x =>
{
// ObservableWWW.Post("", null).Subscribe();
});
}
public void Run()
{
// Debug is write only DebugBuild.
logger.Debug("Debug Message");
// or other logging methods
logger.Log("Message");
logger.Exception(new Exception("test exception"));
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f5aa72c61e2548a4bac4d65f93c63bf1
timeCreated: 1455373902
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a4aea8df1ad11c47a1db84432dd30f8
timeCreated: 1455373896
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
// for uGUI(from 4.6)
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
using System;
using UnityEngine;
using UnityEngine.UI;
namespace UniRx.Examples
{
public class Sample12_ReactiveProperty : MonoBehaviour
{
// Open Sample12Scene. Set from canvas
public Button MyButton;
public Toggle MyToggle;
public InputField MyInput;
public Text MyText;
public Slider MySlider;
// You can monitor/modifie in inspector by SpecializedReactiveProperty
public IntReactiveProperty IntRxProp = new IntReactiveProperty();
Enemy enemy = new Enemy(1000);
void Start()
{
// UnityEvent as Observable
// (shortcut, MyButton.OnClickAsObservable())
MyButton.onClick.AsObservable().Subscribe(_ => enemy.CurrentHp.Value -= 99);
// Toggle, Input etc as Observable(OnValueChangedAsObservable is helper for provide isOn value on subscribe)
// SubscribeToInteractable is UniRx.UI Extension Method, same as .interactable = x)
MyToggle.OnValueChangedAsObservable().SubscribeToInteractable(MyButton);
// input shows delay after 1 second
#if !(UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
MyInput.OnValueChangedAsObservable()
#else
MyInput.OnValueChangeAsObservable()
#endif
.Where(x => x != null)
.Delay(TimeSpan.FromSeconds(1))
.SubscribeToText(MyText); // SubscribeToText is UniRx.UI Extension Method
// converting for human visibility
MySlider.OnValueChangedAsObservable()
.SubscribeToText(MyText, x => Math.Round(x, 2).ToString());
// from RxProp, CurrentHp changing(Button Click) is observable
enemy.CurrentHp.SubscribeToText(MyText);
enemy.IsDead.Where(isDead => isDead == true)
.Subscribe(_ =>
{
MyToggle.interactable = MyButton.interactable = false;
});
// initial text:)
IntRxProp.SubscribeToText(MyText);
}
}
// Reactive Notification Model
public class Enemy
{
public IReactiveProperty<long> CurrentHp { get; private set; }
public IReadOnlyReactiveProperty<bool> IsDead { get; private set; }
public Enemy(int initialHp)
{
// Declarative Property
CurrentHp = new ReactiveProperty<long>(initialHp);
IsDead = CurrentHp.Select(x => x <= 0).ToReactiveProperty();
}
}
}
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 18e34490a83a27e44adf93dd4ffd1f22
timeCreated: 1455373897
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b879645f640b02b43a8e78e210c1da1f
timeCreated: 1455373896
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
// for uGUI(from 4.6)
#if !(UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.EventSystems;
namespace UniRx.Examples
{
public class Sample13_ToDoApp : MonoBehaviour
{
// Open Sample13Scene. Set from canvas
public Text Title;
public InputField ToDoInput;
public Button AddButton;
public Button ClearButton;
public GameObject TodoList;
// prefab:)
public GameObject SampleItemPrefab;
ReactiveCollection<GameObject> toDos = new ReactiveCollection<GameObject>();
void Start()
{
// merge Button click and push enter key on input field.
var submit = Observable.Merge(
AddButton.OnClickAsObservable().Select(_ => ToDoInput.text),
ToDoInput.OnEndEditAsObservable().Where(_ => Input.GetKeyDown(KeyCode.Return)));
// add to reactive collection
submit.Where(x => x != "")
.Subscribe(x =>
{
ToDoInput.text = ""; // clear input field
var item = Instantiate(SampleItemPrefab) as GameObject;
(item.GetComponentInChildren(typeof(Text)) as Text).text = x;
toDos.Add(item);
});
// Collection Change Handling
toDos.ObserveCountChanged().Subscribe(x => Title.text = "TODO App, ItemCount:" + x);
toDos.ObserveAdd().Subscribe(x =>
{
x.Value.transform.SetParent(TodoList.transform, false);
});
toDos.ObserveRemove().Subscribe(x =>
{
GameObject.Destroy(x.Value);
});
// Clear
ClearButton.OnClickAsObservable()
.Subscribe(_ =>
{
var removeTargets = toDos.Where(x => x.GetComponent<Toggle>().isOn).ToArray();
foreach (var item in removeTargets)
{
toDos.Remove(item);
}
});
}
}
}
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 022ecfa555367154c8cf87d61465f7e2
timeCreated: 1455373897
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,284 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &152834
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22461494}
- 222: {fileID: 22298102}
- 114: {fileID: 11434412}
m_Layer: 5
m_Name: Background
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &172388
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22491898}
- 222: {fileID: 22251748}
- 114: {fileID: 11438756}
m_Layer: 5
m_Name: Label
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &174974
GameObject:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22463654}
- 222: {fileID: 22278786}
- 114: {fileID: 11497312}
m_Layer: 5
m_Name: Checkmark
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!1 &182208
GameObject:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
serializedVersion: 4
m_Component:
- 224: {fileID: 22478562}
- 114: {fileID: 11479148}
m_Layer: 5
m_Name: Sample13_ToDoItem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &11434412
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 152834}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 1
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!114 &11438756
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 172388}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 708705254, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: .196078435, g: .196078435, b: .196078435, a: 1}
m_FontData:
m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
m_FontSize: 30
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 10
m_MaxSize: 40
m_Alignment: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'TODOITEM
'
--- !u!114 &11479148
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 182208}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 2109663825, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Navigation:
m_Mode: 3
m_SelectOnUp: {fileID: 0}
m_SelectOnDown: {fileID: 0}
m_SelectOnLeft: {fileID: 0}
m_SelectOnRight: {fileID: 0}
m_Transition: 1
m_Colors:
m_NormalColor: {r: 1, g: 1, b: 1, a: 1}
m_HighlightedColor: {r: .960784316, g: .960784316, b: .960784316, a: 1}
m_PressedColor: {r: .784313738, g: .784313738, b: .784313738, a: 1}
m_DisabledColor: {r: .784313738, g: .784313738, b: .784313738, a: .501960814}
m_ColorMultiplier: 1
m_FadeDuration: .100000001
m_SpriteState:
m_HighlightedSprite: {fileID: 0}
m_PressedSprite: {fileID: 0}
m_DisabledSprite: {fileID: 0}
m_AnimationTriggers:
m_NormalTrigger: Normal
m_HighlightedTrigger: Highlighted
m_PressedTrigger: Pressed
m_DisabledTrigger: Disabled
m_Interactable: 1
m_TargetGraphic: {fileID: 11434412}
toggleTransition: 1
graphic: {fileID: 11497312}
m_Group: {fileID: 0}
onValueChanged:
m_PersistentCalls:
m_Calls: []
m_TypeName: UnityEngine.UI.Toggle+ToggleEvent, UnityEngine.UI, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null
m_IsOn: 1
--- !u!114 &11497312
MonoBehaviour:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 174974}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -765806418, guid: f5f67c52d1564df4a8936ccd202a3bd8, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_Sprite: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
--- !u!222 &22251748
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 172388}
--- !u!222 &22278786
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 174974}
--- !u!222 &22298102
CanvasRenderer:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 152834}
--- !u!224 &22461494
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 152834}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22463654}
m_Father: {fileID: 22478562}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 10, y: -10}
m_SizeDelta: {x: 20, y: 30}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22463654
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 174974}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22461494}
m_RootOrder: 0
m_AnchorMin: {x: .5, y: .5}
m_AnchorMax: {x: .5, y: .5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 20, y: 30}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22478562
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 182208}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 22461494}
- {fileID: 22491898}
m_Father: {fileID: 0}
m_RootOrder: 0
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: .5, y: .5}
--- !u!224 &22491898
RectTransform:
m_ObjectHideFlags: 1
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 100100000}
m_GameObject: {fileID: 172388}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 22478562}
m_RootOrder: 1
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 9, y: -.5}
m_SizeDelta: {x: -28, y: -3}
m_Pivot: {x: .5, y: .5}
--- !u!1001 &100100000
Prefab:
m_ObjectHideFlags: 1
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications: []
m_RemovedComponents: []
m_ParentPrefab: {fileID: 0}
m_RootGameObject: {fileID: 182208}
m_IsPrefabParent: 1

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 173222196f3e1f0448b383f260df7d44
timeCreated: 1455373909
licenseType: Store
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,12 @@
{
"name": "UniRx.Examples",
"references": [
"UniRx"
],
"optionalUnityReferences": [
"TestAssemblies"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 71799519d12379b49b6b53aea974bea5
AssemblyDefinitionImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: