Skip to content

Instantly share code, notes, and snippets.

View Protonz's full-sized avatar

Proton One Protonz

View GitHub Profile
@Protonz
Protonz / UniRx_ReactiveCommandTest.cs
Created December 12, 2016 10:32
Testing out the ReactiveCommand
public class UniRxUnitTests {
[Test]
public void ReactiveCommandTest_2() {
// Arrange
ReactiveProperty<long> CurrentHp = new ReactiveProperty<long>(100);
// Only allow when the player is dead
// ReactiveCommand Resurrect = CurrentHp.Select(hp=> return hp <= 0).ToReactiveCommand();
int canExecuteCalled = 0;
ReactiveCommand Resurrect = CurrentHp.Select(hp=> { canExecuteCalled++; return hp <= 0; }).ToReactiveCommand();
@Protonz
Protonz / UniRx_MergePropertyTest.cs
Last active February 1, 2017 00:18
Merging multiple ReactiveProperties into a single output signal when any one of them changes
[Test]
public void MergePropertyTest() {
// Create an IEnumerable list of reactive proeprties
List<ReactiveProperty<int>> rxPropertyList = new List<ReactiveProperty<int>>();
// Add a couple reactive properties
rxPropertyList.Add(new ReactiveProperty<int>(1));
rxPropertyList.Add(new ReactiveProperty<int>(2));
// Convert the IEnumerable list to an observable stream
@Protonz
Protonz / TweenObservable.cs
Last active February 26, 2018 19:46
Using UniRx to create a TweenStream
using System;
using System.Collections;
using UniRx;
using UnityEngine;
using System.Threading;
namespace UniRx {
public static partial class CustomObservable {
using System;
namespace UniRx {
public static class SwitchExtensions {
public static IObservable<OUT> SwitchSelectWhenTrue<OUT>( this IObservable<bool> observable, Func<IObservable<OUT>> resultIfTrue ) {
return observable.Select(value => value == true ? resultIfTrue() : Observable.Empty<OUT>()).Switch();
}
@Protonz
Protonz / AnimationStateTest.cs
Last active July 18, 2017 21:35
Reacting to Animation State Changes
using UnityEngine;
using UniRx;
using UniRx.Triggers;
using System;
[RequireComponent(typeof(Animator))]
public class AnimationStateTest : MonoBehaviour {
void Start () {
@Protonz
Protonz / LayerGridGraphToggle.cs
Last active August 24, 2017 21:31
Create and Destroy NavGraphs at Runtime
using Pathfinding;
using System.Collections;
using UnityEngine;
public class LayerGridGraphToggle : MonoBehaviour {
public int Width = 200; // (nodes)
public int Depth = 200; // (nodes)
public float NodeSize = 0.5f;
public Vector3 Center = Vector3.zero;
@Protonz
Protonz / ListSpawnerRx.cs
Created October 9, 2017 23:56
[Rx] Spawn prefabs at pre-defined spawn points. There can be a delay before spawning, then the prefabs can be spawned in batches with a delay between each batch.
using UnityEngine;
using UniRx;
using System;
/// <summary>
/// Spawn prefabs at pre-defined spawn points.
/// There can be a delay before spawning, then the prefabs can be spawned in batches with a delay between each batch.
/// </summary>
public class ListSpawnerRx : MonoBehaviour {
@Protonz
Protonz / ListSpawner.cs
Created October 9, 2017 23:57
Spawn prefabs at pre-defined spawn points. There can be a delay before spawning, then the prefabs can be spawned in batches with a delay between each batch.
using UnityEngine;
/// <summary>
/// Spawn prefabs at pre-defined spawn points.
/// There can be a delay before spawning, then the prefabs can be spawned in batches with a delay between each batch.
/// </summary>
public class ListSpawner : MonoBehaviour {
public GameObject[] PrefabList;
public Transform[] SpawnPoints;
@Protonz
Protonz / RxCharacter.cs
Last active October 23, 2017 08:28
Testing Out a Simple Component Manager
using UnityEngine;
using UniRx;
using UnityEngine.SceneManagement;
public class Character {
public enum State {
Idle,
Attacking
}
public ReactiveProperty<State> CurStateObservable = new ReactiveProperty<State>();
using UnityEngine;
using UniRx.Triggers;
using UniRx;
public class DamageVolume : MonoBehaviour {
public bool IsNegateVolume = false;
void Start () {
Collider c = GetComponent<Collider>();