Skip to content

Commit

Permalink
Start of development game
Browse files Browse the repository at this point in the history
  • Loading branch information
alerdenisov committed Apr 16, 2016
0 parents commit 7dd5ffa
Show file tree
Hide file tree
Showing 529 changed files with 42,992 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/[Ll]ibrary/
/[Tt]emp/
/[Oo]bj/
/[Bb]uild/
/[Bb]uilds/
/Assets/AssetStoreTools*

# Autogenerated VS/MD solution and project files
ExportedObj/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd


# Unity3D generated meta files
*.pidb.meta

# Unity3D Generated File On Crash Reports
sysinfo.txt

# Builds
*.apk
*.unitypackage
11 changes: 11 additions & 0 deletions Assets/Jump.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using UnityEngine;
using System.Collections;

public class Jump : MonoBehaviour {

// Update is called once per frame
void Update ()
{
transform.position = Vector3.up*Mathf.Abs(Mathf.Sin(Time.time));
}
}
12 changes: 12 additions & 0 deletions Assets/Jump.cs.meta

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

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

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

9 changes: 9 additions & 0 deletions 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 Assets/Plugins/UniRx/Examples.meta

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

82 changes: 82 additions & 0 deletions Assets/Plugins/UniRx/Examples/Sample01_ObservableWWW.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#if !(UNITY_METRO || UNITY_WP8)

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
12 changes: 12 additions & 0 deletions Assets/Plugins/UniRx/Examples/Sample01_ObservableWWW.cs.meta

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

24 changes: 24 additions & 0 deletions 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);
}
}
}
12 changes: 12 additions & 0 deletions Assets/Plugins/UniRx/Examples/Sample02_ObservableTriggers.cs.meta

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

23 changes: 23 additions & 0 deletions Assets/Plugins/UniRx/Examples/Sample03_GameObjectAsObservable.cs
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.

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

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

38 changes: 38 additions & 0 deletions Assets/Plugins/UniRx/Examples/Sample05_ConvertFromCoroutine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections;
using UnityEngine;

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();
}
}
}
}

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

Loading

0 comments on commit 7dd5ffa

Please sign in to comment.