Skip to content

Commit 041edb1

Browse files
committed
Update UniRx
1 parent 6580f66 commit 041edb1

File tree

494 files changed

+42511
-42566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

494 files changed

+42511
-42566
lines changed
Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,82 @@
1-
#if !(UNITY_METRO || UNITY_WP8)
2-
3-
using UnityEngine;
4-
5-
namespace UniRx.Examples
6-
{
7-
// sample script, attach your object.
8-
public class Sample01_ObservableWWW : MonoBehaviour
9-
{
10-
void Start()
11-
{
12-
// Basic: Download from google.
13-
{
14-
ObservableWWW.Get("http://google.co.jp/")
15-
.Subscribe(
16-
x => Debug.Log(x.Substring(0, 100)), // onSuccess
17-
ex => Debug.LogException(ex)); // onError
18-
}
19-
20-
// Linear Pattern with LINQ Query Expressions
21-
// download after google, start bing download
22-
{
23-
var query = from google in ObservableWWW.Get("http://google.com/")
24-
from bing in ObservableWWW.Get("http://bing.com/")
25-
select new { google, bing };
26-
27-
var cancel = query.Subscribe(x => Debug.Log(x.google.Substring(0, 100) + ":" + x.bing.Substring(0, 100)));
28-
29-
// Call Dispose is cancel downloading.
30-
cancel.Dispose();
31-
}
32-
33-
// Observable.WhenAll is for parallel asynchronous operation
34-
// (It's like Observable.Zip but specialized for single async operations like Task.WhenAll of .NET 4)
35-
{
36-
var parallel = Observable.WhenAll(
37-
ObservableWWW.Get("http://google.com/"),
38-
ObservableWWW.Get("http://bing.com/"),
39-
ObservableWWW.Get("http://unity3d.com/"));
40-
41-
parallel.Subscribe(xs =>
42-
{
43-
Debug.Log(xs[0].Substring(0, 100)); // google
44-
Debug.Log(xs[1].Substring(0, 100)); // bing
45-
Debug.Log(xs[2].Substring(0, 100)); // unity
46-
});
47-
}
48-
49-
// with Progress
50-
{
51-
// notifier for progress
52-
var progressNotifier = new ScheduledNotifier<float>();
53-
progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress
54-
55-
// pass notifier to WWW.Get/Post
56-
ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
57-
}
58-
59-
// with Error
60-
{
61-
// If WWW has .error, ObservableWWW throws WWWErrorException to onError pipeline.
62-
// WWWErrorException has RawErrorMessage, HasResponse, StatusCode, ResponseHeaders
63-
ObservableWWW.Get("http://www.google.com/404")
64-
.CatchIgnore((WWWErrorException ex) =>
65-
{
66-
Debug.Log(ex.RawErrorMessage);
67-
if (ex.HasResponse)
68-
{
69-
Debug.Log(ex.StatusCode);
70-
}
71-
foreach (var item in ex.ResponseHeaders)
72-
{
73-
Debug.Log(item.Key + ":" + item.Value);
74-
}
75-
})
76-
.Subscribe();
77-
}
78-
}
79-
}
80-
}
81-
1+
#if !(UNITY_METRO || UNITY_WP8)
2+
3+
using UnityEngine;
4+
5+
namespace UniRx.Examples
6+
{
7+
// sample script, attach your object.
8+
public class Sample01_ObservableWWW : MonoBehaviour
9+
{
10+
void Start()
11+
{
12+
// Basic: Download from google.
13+
{
14+
ObservableWWW.Get("http://google.co.jp/")
15+
.Subscribe(
16+
x => Debug.Log(x.Substring(0, 100)), // onSuccess
17+
ex => Debug.LogException(ex)); // onError
18+
}
19+
20+
// Linear Pattern with LINQ Query Expressions
21+
// download after google, start bing download
22+
{
23+
var query = from google in ObservableWWW.Get("http://google.com/")
24+
from bing in ObservableWWW.Get("http://bing.com/")
25+
select new { google, bing };
26+
27+
var cancel = query.Subscribe(x => Debug.Log(x.google.Substring(0, 100) + ":" + x.bing.Substring(0, 100)));
28+
29+
// Call Dispose is cancel downloading.
30+
cancel.Dispose();
31+
}
32+
33+
// Observable.WhenAll is for parallel asynchronous operation
34+
// (It's like Observable.Zip but specialized for single async operations like Task.WhenAll of .NET 4)
35+
{
36+
var parallel = Observable.WhenAll(
37+
ObservableWWW.Get("http://google.com/"),
38+
ObservableWWW.Get("http://bing.com/"),
39+
ObservableWWW.Get("http://unity3d.com/"));
40+
41+
parallel.Subscribe(xs =>
42+
{
43+
Debug.Log(xs[0].Substring(0, 100)); // google
44+
Debug.Log(xs[1].Substring(0, 100)); // bing
45+
Debug.Log(xs[2].Substring(0, 100)); // unity
46+
});
47+
}
48+
49+
// with Progress
50+
{
51+
// notifier for progress
52+
var progressNotifier = new ScheduledNotifier<float>();
53+
progressNotifier.Subscribe(x => Debug.Log(x)); // write www.progress
54+
55+
// pass notifier to WWW.Get/Post
56+
ObservableWWW.Get("http://google.com/", progress: progressNotifier).Subscribe();
57+
}
58+
59+
// with Error
60+
{
61+
// If WWW has .error, ObservableWWW throws WWWErrorException to onError pipeline.
62+
// WWWErrorException has RawErrorMessage, HasResponse, StatusCode, ResponseHeaders
63+
ObservableWWW.Get("http://www.google.com/404")
64+
.CatchIgnore((WWWErrorException ex) =>
65+
{
66+
Debug.Log(ex.RawErrorMessage);
67+
if (ex.HasResponse)
68+
{
69+
Debug.Log(ex.StatusCode);
70+
}
71+
foreach (var item in ex.ResponseHeaders)
72+
{
73+
Debug.Log(item.Key + ":" + item.Value);
74+
}
75+
})
76+
.Subscribe();
77+
}
78+
}
79+
}
80+
}
81+
8282
#endif

Assets/Plugins/UniRx/Examples/Sample01_ObservableWWW.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
using UnityEngine;
2-
using UniRx.Triggers; // Triggers Namepsace
3-
using System;
4-
5-
namespace UniRx.Examples
6-
{
7-
public class Sample02_ObservableTriggers : MonoBehaviour
8-
{
9-
void Start()
10-
{
11-
// Get the plain object
12-
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
13-
14-
// Add ObservableXxxTrigger for handle MonoBehaviour's event as Observable
15-
cube.AddComponent<ObservableUpdateTrigger>()
16-
.UpdateAsObservable()
17-
.SampleFrame(30)
18-
.Subscribe(x => Debug.Log("cube"), () => Debug.Log("destroy"));
19-
20-
// destroy after 3 second:)
21-
GameObject.Destroy(cube, 3f);
22-
}
23-
}
1+
using UnityEngine;
2+
using UniRx.Triggers; // Triggers Namepsace
3+
using System;
4+
5+
namespace UniRx.Examples
6+
{
7+
public class Sample02_ObservableTriggers : MonoBehaviour
8+
{
9+
void Start()
10+
{
11+
// Get the plain object
12+
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
13+
14+
// Add ObservableXxxTrigger for handle MonoBehaviour's event as Observable
15+
cube.AddComponent<ObservableUpdateTrigger>()
16+
.UpdateAsObservable()
17+
.SampleFrame(30)
18+
.Subscribe(x => Debug.Log("cube"), () => Debug.Log("destroy"));
19+
20+
// destroy after 3 second:)
21+
GameObject.Destroy(cube, 3f);
22+
}
23+
}
2424
}

Assets/Plugins/UniRx/Examples/Sample02_ObservableTriggers.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
2-
3-
using UnityEngine;
4-
using UniRx.Triggers; // for enable gameObject.EventAsObservbale()
5-
6-
namespace UniRx.Examples
7-
{
8-
public class Sample03_GameObjectAsObservable : MonoBehaviour
9-
{
10-
void Start()
11-
{
12-
// All events can subscribe by ***AsObservable if enables UniRx.Triggers
13-
this.OnMouseDownAsObservable()
14-
.SelectMany(_ => this.gameObject.UpdateAsObservable())
15-
.TakeUntil(this.gameObject.OnMouseUpAsObservable())
16-
.Select(_ => Input.mousePosition)
17-
.RepeatUntilDestroy(this)
18-
.Subscribe(x => Debug.Log(x), ()=> Debug.Log("!!!" + "complete"));
19-
}
20-
}
21-
}
22-
1+
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
2+
3+
using UnityEngine;
4+
using UniRx.Triggers; // for enable gameObject.EventAsObservbale()
5+
6+
namespace UniRx.Examples
7+
{
8+
public class Sample03_GameObjectAsObservable : MonoBehaviour
9+
{
10+
void Start()
11+
{
12+
// All events can subscribe by ***AsObservable if enables UniRx.Triggers
13+
this.OnMouseDownAsObservable()
14+
.SelectMany(_ => this.gameObject.UpdateAsObservable())
15+
.TakeUntil(this.gameObject.OnMouseUpAsObservable())
16+
.Select(_ => Input.mousePosition)
17+
.RepeatUntilDestroy(this)
18+
.Subscribe(x => Debug.Log(x), ()=> Debug.Log("!!!" + "complete"));
19+
}
20+
}
21+
}
22+
2323
#endif

Assets/Plugins/UniRx/Examples/Sample03_GameObjectAsObservable.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)