基础内容
必要插件安装 缓动曲线和动画基础 ElementFolder,Track与其次级模块,PathNode重构
This commit is contained in:
76
Assets/Plugins/UniRx/Scripts/Disposables/Disposable.cs
Normal file
76
Assets/Plugins/UniRx/Scripts/Disposables/Disposable.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
namespace UniRx
|
||||
{
|
||||
public static class Disposable
|
||||
{
|
||||
public static readonly IDisposable Empty = EmptyDisposable.Singleton;
|
||||
|
||||
public static IDisposable Create(Action disposeAction)
|
||||
{
|
||||
return new AnonymousDisposable(disposeAction);
|
||||
}
|
||||
|
||||
public static IDisposable CreateWithState<TState>(TState state, Action<TState> disposeAction)
|
||||
{
|
||||
return new AnonymousDisposable<TState>(state, disposeAction);
|
||||
}
|
||||
|
||||
class EmptyDisposable : IDisposable
|
||||
{
|
||||
public static EmptyDisposable Singleton = new EmptyDisposable();
|
||||
|
||||
private EmptyDisposable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class AnonymousDisposable : IDisposable
|
||||
{
|
||||
bool isDisposed = false;
|
||||
readonly Action dispose;
|
||||
|
||||
public AnonymousDisposable(Action dispose)
|
||||
{
|
||||
this.dispose = dispose;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AnonymousDisposable<T> : IDisposable
|
||||
{
|
||||
bool isDisposed = false;
|
||||
readonly T state;
|
||||
readonly Action<T> dispose;
|
||||
|
||||
public AnonymousDisposable(T state, Action<T> dispose)
|
||||
{
|
||||
this.state = state;
|
||||
this.dispose = dispose;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
dispose(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user