Update Project
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public class BindSignalFromBinder<TObject, TSignal>
|
||||
{
|
||||
readonly BindStatement _bindStatement;
|
||||
readonly Func<TObject, Action<TSignal>> _methodGetter;
|
||||
readonly DiContainer _container;
|
||||
readonly SignalBindingBindInfo _signalBindInfo;
|
||||
|
||||
public BindSignalFromBinder(
|
||||
SignalBindingBindInfo signalBindInfo, BindStatement bindStatement, Func<TObject, Action<TSignal>> methodGetter,
|
||||
DiContainer container)
|
||||
{
|
||||
_signalBindInfo = signalBindInfo;
|
||||
_bindStatement = bindStatement;
|
||||
_methodGetter = methodGetter;
|
||||
_container = container;
|
||||
}
|
||||
|
||||
public SignalCopyBinder FromResolve()
|
||||
{
|
||||
return From(x => x.FromResolve().AsCached());
|
||||
}
|
||||
|
||||
public SignalCopyBinder FromResolveAll()
|
||||
{
|
||||
return From(x => x.FromResolveAll().AsCached());
|
||||
}
|
||||
|
||||
public SignalCopyBinder FromNew()
|
||||
{
|
||||
return From(x => x.FromNew().AsCached());
|
||||
}
|
||||
|
||||
public SignalCopyBinder From(Action<ConcreteBinderGeneric<TObject>> objectBindCallback)
|
||||
{
|
||||
Assert.That(!_bindStatement.HasFinalizer);
|
||||
_bindStatement.SetFinalizer(new NullBindingFinalizer());
|
||||
|
||||
var objectLookupId = Guid.NewGuid();
|
||||
|
||||
// Very important here that we use NoFlush otherwise the main binding will be finalized early
|
||||
var objectBinder = _container.BindNoFlush<TObject>().WithId(objectLookupId);
|
||||
|
||||
objectBindCallback(objectBinder);
|
||||
|
||||
// We need to do this to make sure SignalCallbackWithLookupWrapper does not have
|
||||
// generic types to avoid AOT issues
|
||||
Func<object, Action<object>> methodGetterMapper =
|
||||
obj => s => _methodGetter((TObject)obj)((TSignal)s);
|
||||
|
||||
var wrapperBinder = _container.Bind<IDisposable>()
|
||||
.To<SignalCallbackWithLookupWrapper>()
|
||||
.AsCached()
|
||||
.WithArguments(_signalBindInfo, typeof(TObject), objectLookupId, methodGetterMapper)
|
||||
.NonLazy();
|
||||
|
||||
var copyBinder = new SignalCopyBinder( wrapperBinder.BindInfo);
|
||||
// Make sure if they use one of the Copy/Move methods that it applies to both bindings
|
||||
copyBinder.AddCopyBindInfo(objectBinder.BindInfo);
|
||||
return copyBinder;
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c779f758eaadfd54fb9c66f7acc75716
|
||||
timeCreated: 1521288279
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public class BindSignalIdToBinder<TSignal> : BindSignalToBinder<TSignal>
|
||||
{
|
||||
public BindSignalIdToBinder(DiContainer container, SignalBindingBindInfo signalBindInfo)
|
||||
: base(container, signalBindInfo)
|
||||
{
|
||||
}
|
||||
|
||||
public BindSignalToBinder<TSignal> WithId(object identifier)
|
||||
{
|
||||
SignalBindInfo.Identifier = identifier;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecce6d44c178e564c8937125741f3c8c
|
||||
timeCreated: 1538401230
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using ModestTree;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
public class BindSignalToBinder<TSignal>
|
||||
{
|
||||
DiContainer _container;
|
||||
BindStatement _bindStatement;
|
||||
SignalBindingBindInfo _signalBindInfo;
|
||||
|
||||
public BindSignalToBinder(DiContainer container, SignalBindingBindInfo signalBindInfo)
|
||||
{
|
||||
_container = container;
|
||||
|
||||
_signalBindInfo = signalBindInfo;
|
||||
// This will ensure that they finish the binding
|
||||
_bindStatement = container.StartBinding();
|
||||
}
|
||||
|
||||
protected SignalBindingBindInfo SignalBindInfo
|
||||
{
|
||||
get { return _signalBindInfo; }
|
||||
}
|
||||
|
||||
public SignalCopyBinder ToMethod(Action<TSignal> callback)
|
||||
{
|
||||
Assert.That(!_bindStatement.HasFinalizer);
|
||||
_bindStatement.SetFinalizer(new NullBindingFinalizer());
|
||||
|
||||
var bindInfo = _container.Bind<IDisposable>()
|
||||
.To<SignalCallbackWrapper>()
|
||||
.AsCached()
|
||||
// Note that there's a reason we don't just make SignalCallbackWrapper have a generic
|
||||
// argument for signal type - because when using struct type signals it throws
|
||||
// exceptions on AOT platforms
|
||||
.WithArguments(_signalBindInfo, (Action<object>)(o => callback((TSignal)o)))
|
||||
.NonLazy().BindInfo;
|
||||
|
||||
return new SignalCopyBinder(bindInfo);
|
||||
}
|
||||
|
||||
public SignalCopyBinder ToMethod(Action callback)
|
||||
{
|
||||
return ToMethod(signal => callback());
|
||||
}
|
||||
|
||||
public BindSignalFromBinder<TObject, TSignal> ToMethod<TObject>(Action<TObject, TSignal> handler)
|
||||
{
|
||||
return ToMethod<TObject>(x => (Action<TSignal>)(s => handler(x, s)));
|
||||
}
|
||||
|
||||
public BindSignalFromBinder<TObject, TSignal> ToMethod<TObject>(Func<TObject, Action> handlerGetter)
|
||||
{
|
||||
return ToMethod<TObject>(x => (Action<TSignal>)(s => handlerGetter(x)()));
|
||||
}
|
||||
|
||||
public BindSignalFromBinder<TObject, TSignal> ToMethod<TObject>(Func<TObject, Action<TSignal>> handlerGetter)
|
||||
{
|
||||
return new BindSignalFromBinder<TObject, TSignal>(
|
||||
_signalBindInfo, _bindStatement, handlerGetter, _container);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6df1bca64a984074fb4af41dc1d42a07
|
||||
timeCreated: 1521288279
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Note that there's a reason we don't just have a generic
|
||||
// argument for signal type - because when using struct type signals it throws
|
||||
// exceptions on AOT platforms
|
||||
public class SignalCallbackWithLookupWrapper : IDisposable
|
||||
{
|
||||
readonly DiContainer _container;
|
||||
readonly SignalBus _signalBus;
|
||||
readonly Guid _lookupId;
|
||||
readonly Func<object, Action<object>> _methodGetter;
|
||||
readonly Type _objectType;
|
||||
readonly Type _signalType;
|
||||
readonly object _identifier;
|
||||
|
||||
public SignalCallbackWithLookupWrapper(
|
||||
SignalBindingBindInfo signalBindInfo,
|
||||
Type objectType,
|
||||
Guid lookupId,
|
||||
Func<object, Action<object>> methodGetter,
|
||||
SignalBus signalBus,
|
||||
DiContainer container)
|
||||
{
|
||||
_objectType = objectType;
|
||||
_signalType = signalBindInfo.SignalType;
|
||||
_identifier = signalBindInfo.Identifier;
|
||||
_container = container;
|
||||
_methodGetter = methodGetter;
|
||||
_signalBus = signalBus;
|
||||
_lookupId = lookupId;
|
||||
|
||||
signalBus.SubscribeId(signalBindInfo.SignalType, _identifier, OnSignalFired);
|
||||
}
|
||||
|
||||
void OnSignalFired(object signal)
|
||||
{
|
||||
var objects = _container.ResolveIdAll(_objectType, _lookupId);
|
||||
|
||||
for (int i = 0; i < objects.Count; i++)
|
||||
{
|
||||
_methodGetter(objects[i])(signal);
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.UnsubscribeId(_signalType, _identifier, OnSignalFired);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b11a635fa1263c4f9a9a0d70d7efcf2
|
||||
timeCreated: 1521293791
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
|
||||
namespace Zenject
|
||||
{
|
||||
// Note that there's a reason we don't just have a generic
|
||||
// argument for signal type - because when using struct type signals it throws
|
||||
// exceptions on AOT platforms
|
||||
public class SignalCallbackWrapper : IDisposable
|
||||
{
|
||||
readonly SignalBus _signalBus;
|
||||
readonly Action<object> _action;
|
||||
readonly Type _signalType;
|
||||
readonly object _identifier;
|
||||
|
||||
public SignalCallbackWrapper(
|
||||
SignalBindingBindInfo bindInfo,
|
||||
Action<object> action,
|
||||
SignalBus signalBus)
|
||||
{
|
||||
_signalType = bindInfo.SignalType;
|
||||
_identifier = bindInfo.Identifier;
|
||||
_signalBus = signalBus;
|
||||
_action = action;
|
||||
|
||||
signalBus.SubscribeId(bindInfo.SignalType, _identifier, OnSignalFired);
|
||||
}
|
||||
|
||||
void OnSignalFired(object signal)
|
||||
{
|
||||
_action(signal);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_signalBus.UnsubscribeId(_signalType, _identifier, OnSignalFired);
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a8599dbdf9033e468671e40de134ccf
|
||||
timeCreated: 1521289018
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user