Skip to content

Commit

Permalink
Updated to fix unirx issues and support 2019.*
Browse files Browse the repository at this point in the history
  • Loading branch information
grofit committed Oct 10, 2019
1 parent e6289f5 commit f75a125
Show file tree
Hide file tree
Showing 134 changed files with 8,713 additions and 4,699 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Temp
/src/src.userprefs
/*.unitypackage
src/\.vs/

dist/

src/.idea/

src/Logs/
949 changes: 641 additions & 308 deletions src/Assembly-CSharp-Editor.csproj

Large diffs are not rendered by default.

1,162 changes: 647 additions & 515 deletions src/Assembly-CSharp-firstpass.csproj

Large diffs are not rendered by default.

876 changes: 618 additions & 258 deletions src/Assembly-CSharp.csproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Assets/Examples/InputBindings/SetupToggleBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void Start()
{
ToggleElement.BindToggleTo(ToggleState);

var textualRepresentation = ToggleState.Select(GetTextualState).ToReactiveProperty();
var textualRepresentation = ToggleState.Select(GetTextualState).ToReadOnlyReactiveProperty();
textualRepresentation.AddTo(TextElement);

TextElement.BindTextTo(textualRepresentation);
Expand Down
43 changes: 43 additions & 0 deletions src/Assets/Plugins/BindingsRx/Bindings/GameObjectExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,48 @@ public static IDisposable BindTagTo(this GameObject input, IReactiveProperty<str

public static IDisposable BindTagTo(this GameObject input, Func<string> getter, Action<string> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<string>[] filters)
{ return GenericBindings.Bind(() => input.tag, x => input.tag = x, getter, setter, bindingType, filters).AddTo(input); }

public static IDisposable BindChildPrefabsTo<T>(this GameObject input, IReadOnlyReactiveCollection<T> list,
GameObject prefab, Action<T, GameObject> onChildCreated = null, Action<T, GameObject> onChildRemoving = null)
{ return BindChildPrefabsTo(input, list, prefab, GameObject.Instantiate, onChildCreated, onChildRemoving); }

public static IDisposable BindChildPrefabsTo<T>(this GameObject input, IReadOnlyReactiveCollection<T> list,
GameObject prefab, Func<GameObject, Transform, GameObject> instantiator,
Action<T, GameObject> onChildCreated = null, Action<T, GameObject> onChildRemoving = null)
{
var disposable = new CompositeDisposable();

void onElementAdded(CollectionAddEvent<T> data)
{
var newChild = instantiator(prefab, input.transform);
onChildCreated?.Invoke(data.Value, newChild);
}

void onElementUpdated(CollectionReplaceEvent<T> data)
{
var existingChild = input.transform.GetChild(data.Index);
onChildCreated?.Invoke(data.NewValue, existingChild.gameObject);
}

void onElementRemoved(CollectionRemoveEvent<T> data)
{
var existingChild = input.transform.GetChild(data.Index);
onChildRemoving?.Invoke(data.Value, existingChild.gameObject);
GameObject.Destroy(existingChild);
}

list.ObserveAdd().Subscribe(onElementAdded).AddTo(disposable);
list.ObserveReplace().Subscribe(onElementUpdated).AddTo(disposable);
list.ObserveRemove().Subscribe(onElementRemoved).AddTo(disposable);

input.transform.DeleteAllChildren();
foreach (var element in list)
{
var newChild = instantiator(prefab, input.transform);
onChildCreated?.Invoke(element, newChild);
}

return disposable.AddTo(input);
}
}
}
16 changes: 16 additions & 0 deletions src/Assets/Plugins/BindingsRx/Bindings/GenericBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ public static IDisposable Bind<T>(IReactiveProperty<T> propertyA , IReactiveProp
return new CompositeDisposable(propertyABinding, propertyBBinding);
}

public static IDisposable Bind<T>(IReactiveProperty<T> propertyA , IReadOnlyReactiveProperty<T> propertyB, params IFilter<T>[] filters)
{
return propertyB
.ApplyInputFilters(filters)
.DistinctUntilChanged()
.Subscribe(x => propertyA.Value = x);
}

public static IDisposable Bind<T>(Func<T> propertyAGetter, Action<T> propertyASetter, IReactiveProperty<T> propertyB, BindingTypes bindingTypes = BindingTypes.Default, params IFilter<T>[] filters)
{
var propertyBBinding = propertyB
Expand All @@ -46,6 +54,14 @@ public static IDisposable Bind<T>(Func<T> propertyAGetter, Action<T> propertyASe
return new CompositeDisposable(propertyABinding, propertyBBinding);
}

public static IDisposable Bind<T>(Action<T> propertyASetter, IReadOnlyReactiveProperty<T> propertyB, params IFilter<T>[] filters)
{
return propertyB
.ApplyInputFilters(filters)
.DistinctUntilChanged()
.Subscribe(propertyASetter);
}

public static IDisposable Bind<T>(Func<T> propertyAGetter, Action<T> propertyASetter, Func<T> propertyBGetter, Action<T> propertyBSetter, BindingTypes bindingTypes = BindingTypes.Default, params IFilter<T>[] filters)
{
var propertyBBinding = Observable.EveryUpdate()
Expand Down
9 changes: 9 additions & 0 deletions src/Assets/Plugins/BindingsRx/Bindings/TextExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace BindingsRx.Bindings
{
public static class TextExtensions
{
public static IDisposable BindTextTo(this Text input, IReadOnlyReactiveProperty<string> property, params IFilter<string>[] filters)
{ return GenericBindings.Bind(x => input.text = x, property, filters).AddTo(input); }

public static IDisposable BindTextTo(this Text input, IReactiveProperty<string> property, params IFilter<string>[] filters)
{ return GenericBindings.Bind(() => input.text, x => input.text = x, property, BindingTypes.OneWay, filters).AddTo(input); }

Expand Down Expand Up @@ -38,12 +41,18 @@ public static IDisposable BindTextTo<T>(this Text input, Func<T> getter, IConver

public static IDisposable BindFontSizeTo(this Text input, IReactiveProperty<int> property, params IFilter<int>[] filters)
{ return GenericBindings.Bind(() => input.fontSize, x => input.fontSize = x, property, BindingTypes.OneWay, filters).AddTo(input); }

public static IDisposable BindFontSizeTo(this Text input, IReadOnlyReactiveProperty<int> property, params IFilter<int>[] filters)
{ return GenericBindings.Bind(x => input.fontSize = x, property, filters).AddTo(input); }

public static IDisposable BindFontSizeTo(this Text input, Func<int> getter, params IFilter<int>[] filters)
{ return GenericBindings.Bind(() => input.fontSize, x => input.fontSize = x, getter, null, BindingTypes.OneWay, filters).AddTo(input); }

public static IDisposable BindColorTo(this Text input, IReactiveProperty<Color> property, BindingTypes bindingType = BindingTypes.Default, params IFilter<Color>[] filters)
{ return GenericBindings.Bind(() => input.color, x => input.color = x, property, bindingType, filters).AddTo(input); }

public static IDisposable BindColorTo(this Text input, IReadOnlyReactiveProperty<Color> property, params IFilter<Color>[] filters)
{ return GenericBindings.Bind(x => input.color = x, property, filters).AddTo(input); }

public static IDisposable BindColorTo(this Text input, Func<Color> getter, Action<Color> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<Color>[] filters)
{ return GenericBindings.Bind(() => input.color, x => input.color = x, getter, setter, bindingType, filters).AddTo(input); }
Expand Down
9 changes: 9 additions & 0 deletions src/Assets/Plugins/BindingsRx/Bindings/TransformExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,14 @@ public static IDisposable BindScaleTo(this Transform input, IReactiveProperty<Ve

public static IDisposable BindScaleTo(this Transform input, Func<Vector3> getter, Action<Vector3> setter, BindingTypes bindingType = BindingTypes.Default, params IFilter<Vector3>[] filters)
{ return GenericBindings.Bind(() => input.localScale, x => input.transform.localScale = x, getter, setter, bindingType, filters).AddTo(input); }

public static void DeleteAllChildren(this Transform transform)
{
for (var i = transform.childCount - 1; i >= 0; i--)
{
var child = transform.GetChild(i);
GameObject.Destroy(child.gameObject);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System;
using BindingsRx.Filters;
using UniRx;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using UniRx;


namespace BindingsRx.Extensions
{
public static class IReactivePropertyExtensions
{
public static ReactiveProperty<string> ToTextualProperty<T>(this IReactiveProperty<T> nonStringProperty)
{ return nonStringProperty.Select(x => x.ToString()).ToReactiveProperty(); }

}
}
3 changes: 1 addition & 2 deletions src/Assets/Plugins/UniRx.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Assets/Plugins/UniRx/Examples.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

90 changes: 90 additions & 0 deletions src/Assets/Plugins/UniRx/Examples/Sample01_ObservableWWW.cs
Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/Assets/Plugins/UniRx/Examples/Sample02_ObservableTriggers.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit f75a125

Please sign in to comment.