Skip to content

Instantly share code, notes, and snippets.

View neuecc's full-sized avatar

Yoshifumi Kawai neuecc

View GitHub Profile
@neuecc
neuecc / DictionaryDisposable.cs
Last active November 12, 2015 12:39
DictionaryDisposable
public class DictionaryDisposable<TKey, TValue> : IDisposable, IDictionary<TKey, TValue>
where TValue : IDisposable
{
bool isDisposed = false;
readonly Dictionary<TKey, TValue> inner;
public DictionaryDisposable()
{
inner = new Dictionary<TKey, TValue>();
}
using UnityEngine;
using UniRx;
public class MyBehaviour : MonoBehaviour
{
void Start()
{
// https://github.com/jbevain/cecil/issues/241
// https://github.com/saynomoo/unetweaver_error
@neuecc
neuecc / msgpack.md
Last active January 31, 2016 07:42
Serialize derived class
[DataContract]
public class Hoge
{
    [DataMember(Order = 0)]
    public int MyProperty1 { get; set; }
}

[DataContract]
public class HogeHoge : Hoge
@neuecc
neuecc / ToDictionaryBatching.cs
Created March 4, 2016 03:39
ToDictionaryBatching
public static class DictionaryPerfomanceExtensions
{
public static void ToDictionaryBatching<T, TKey1>(this T[] array,
Func<T, TKey1> keySelector1, out Dictionary<TKey1, T> dictionary1
)
{
dictionary1 = new Dictionary<TKey1, T>(array.Length);
for (int i = 0; i < array.Length; i++)
{
public class Hoge
{
public Action<int, string> onSomethingWithArgs2;
public void Hoge2()
{
var source = Observable.FromEvent<Action<int, string>, Tuple<int, string>>(
h => (x, y) => h(Tuple.Create(x, y)),
h => onSomethingWithArgs2 += h,
h => onSomethingWithArgs2 -= h);
async Task ThraedingError()
{
Debug.Log($"Start ThreadId:{Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(TimeSpan.FromMilliseconds(300));
Debug.Log($"From another thread, can't touch transform position. ThreadId:{Thread.CurrentThread.ManagedThreadId}");
Debug.Log(this.transform.position); // exception
}
async Task UseUniRxInBackground()
{
Debug.Log($"Start ThreadId:{ Thread.CurrentThread.ManagedThreadId}");
await Task.Delay(TimeSpan.FromMilliseconds(300));
Debug.Log($"From same thread, because UniRx installs UniRxSynchronizationContext.ThreadId:{ Thread.CurrentThread.ManagedThreadId}");
Debug.Log(this.transform.position); // show transform
}
@neuecc
neuecc / CoroutineBridge.cs
Last active October 4, 2016 06:37
for Blog #3
async Task CoroutineBridge()
{
Debug.Log("start www await");
var www = await new WWW("https://unity3d.com");
Debug.Log(www.text);
await CustomCoroutine();
Debug.Log("await after 3 seconds");
}
IEnumerator CustomCoroutine()
@neuecc
neuecc / AwaitObservable.cs
Created October 4, 2016 06:30
for Blog #4
async Task AwaitObservable()
{
Debug.Log("start await observable");
await Observable.NextFrame(); // like yield return null
await Observable.TimerFrame(5); // await 5 frame
try
{
// ObservableWWW promote exception when await(difference in await WWW)
var result = await ObservableWWW.Get("https://404.com");
Debug.Log(result);
@neuecc
neuecc / SerializerPerformance.cs
Created October 25, 2016 12:47
SerializerPerformance
using MsgPack.Serialization;
using ProtoBuf;
using System;
using System.Diagnostics;
using System.IO;
using ZeroFormatter;
// スーパー雑雑クラス。
[ZeroFormattable]