Skip to content

Instantly share code, notes, and snippets.

View Protonz's full-sized avatar

Proton One Protonz

View GitHub Profile
@Protonz
Protonz / SwitchGarbage.cs
Created January 25, 2018 21:43
Experimenting with how much garbage is created when using UniRx Switch
using UnityEngine;
using UniRx;
using System;
using System.Collections.Generic;
using System.Linq;
public class SwitchGarbage : MonoBehaviour {
void Start() {
using UnityEngine;
using UniRx;
using System;
using System.Linq;
public class DamageVolumePlayer : MonoBehaviour {
// Health should live in a different component. Just here for simplicity
public FloatReactiveProperty Health = new FloatReactiveProperty(100);
public float DamagePerSecond = 1.0f;
using UnityEngine;
using UniRx.Triggers;
using UniRx;
public class DamageVolume : MonoBehaviour {
public bool IsNegateVolume = false;
void Start () {
Collider c = GetComponent<Collider>();
@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>();
@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 / 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 / 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 / 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 () {
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 / 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 {