IEnumerator Init() { #pragma warning disable 168 // Ensure the global comp root is initialized so that it doesn't get parented to us below var globalRoot = GlobalCompositionRoot.Instance; #pragma warning restore 168 _beforeInstallHooks = SceneCompositionRoot.BeforeInstallHooks; SceneCompositionRoot.BeforeInstallHooks = null; _afterInstallHooks = SceneCompositionRoot.AfterInstallHooks; SceneCompositionRoot.AfterInstallHooks = null; var rootObjectsBeforeLoad = UnityUtil.GetRootGameObjects(); ZenUtil.LoadSceneAdditive( SceneName, AddPreBindings, AddPostBindings); // Wait one frame for objects to be added to the scene heirarchy yield return(null); var newlyAddedObjects = UnityUtil.GetRootGameObjects().Except(rootObjectsBeforeLoad); foreach (var obj in newlyAddedObjects) { obj.transform.SetParent(this.transform); } }
public BindingConditionSetter ToInstance(Type concreteType, object instance) { if (ZenUtil.IsNull(instance) && !Container.IsValidating) { string message; if (ContractType == concreteType) { message = "Received null instance during Bind command with type '{0}'".Fmt(ContractType.Name()); } else { message = "Received null instance during Bind command when binding type '{0}' to '{1}'".Fmt(ContractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } if (!ZenUtil.IsNull(instance) && !instance.GetType().DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } return(ToProvider(new InstanceProvider(concreteType, instance))); }
protected BindingConditionSetter ToSingleInstance(Type concreteType, string concreteIdentifier, object instance) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } if (ZenUtil.IsNull(instance) && !Container.IsValidating) { string message; if (ContractType == concreteType) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(ContractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(ContractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(concreteIdentifier, concreteType, instance))); }
public BindingConditionSetter ToSingleInstance <TConcrete>(TConcrete instance, string identifier) { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == concreteType) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), concreteType.Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(identifier, instance))); }
public void Awake() { DontDestroyOnLoad(gameObject); ZenUtil.LoadScene( SceneName, AddPreBindings, AddPostBindings); }
public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int hash = 17; hash = hash * 29 + (this.Identifier == null ? 0 : this.Identifier.GetHashCode()); hash = hash * 29 + (ZenUtil.IsNull(this.Prefab) ? 0 : this.Prefab.GetHashCode()); return(hash); } }
// Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToTransientPrefab <TConcrete>(GameObject prefab) where TConcrete : Component, TContract { // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(typeof(TConcrete).Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab <TConcrete>(_container, prefab))); }
public void Awake() { DontDestroyOnLoad(gameObject); _beforeInstallHooks = SceneCompositionRoot.BeforeInstallHooks; SceneCompositionRoot.BeforeInstallHooks = null; _afterInstallHooks = SceneCompositionRoot.AfterInstallHooks; SceneCompositionRoot.AfterInstallHooks = null; ZenUtil.LoadScene( SceneName, AddPreBindings, AddPostBindings); }
// Note that concreteType here could be an interface as well public BindingConditionSetter ToSinglePrefab(Type concreteType, string concreteIdentifier, GameObject prefab) { Assert.That(concreteType.DerivesFromOrEqual <TContract>()); if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException( "Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } var prefabSingletonMap = _container.Resolve <PrefabSingletonProviderMap>(); return(ToProvider( prefabSingletonMap.CreateProvider(concreteIdentifier, concreteType, prefab))); }
public void Awake() { #pragma warning disable 168 // Ensure the global comp root is initialized so that it doesn't get parented to us below var globalRoot = GlobalCompositionRoot.Instance; #pragma warning restore 168 _beforeInstallHooks = SceneCompositionRoot.BeforeInstallHooks; SceneCompositionRoot.BeforeInstallHooks = null; _afterInstallHooks = SceneCompositionRoot.AfterInstallHooks; SceneCompositionRoot.AfterInstallHooks = null; ZenUtil.LoadSceneAdditive( SceneName, AddPreBindings, AddPostBindings); }
public BindingConditionSetter ToTransientPrefab(Type concreteType, GameObject prefab) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab(concreteType, prefab))); }
public void Awake() { // We always want to initialize GlobalCompositionRoot as early as possible GlobalCompositionRoot.Instance.EnsureIsInitialized(); _beforeInstallHooks = SceneCompositionRoot.BeforeInstallHooks; SceneCompositionRoot.BeforeInstallHooks = null; _afterInstallHooks = SceneCompositionRoot.AfterInstallHooks; SceneCompositionRoot.AfterInstallHooks = null; SceneCompositionRoot.DecoratedScenes.Add(this.gameObject.scene); ZenUtil.LoadSceneAdditive( SceneName, AddPreBindings, AddPostBindings); }
// Note: Here we assume that the contract is a component on the given prefab public BindingConditionSetter ToTransientFromPrefab <TConcrete>(GameObject prefab) where TConcrete : Component { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab) && !_container.AllowNullBindings) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider(new GameObjectTransientProviderFromPrefab <TConcrete>(_container, prefab))); }
// Note that concreteType here could be an interface as well public BindingConditionSetter ToSinglePrefab( Type concreteType, string concreteIdentifier, GameObject prefab) { if (!concreteType.DerivesFromOrEqual(ContractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), ContractType.Name())); } if (ZenUtil.IsNull(prefab)) { throw new ZenjectBindException( "Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } return(ToProvider( Container.SingletonProviderCreator.CreateProviderFromPrefab(concreteIdentifier, concreteType, prefab))); }
public BindingConditionSetter ToSingleFromPrefab <TConcrete>(string identifier, GameObject prefab) where TConcrete : Component { var concreteType = typeof(TConcrete); if (!concreteType.DerivesFromOrEqual(_contractType)) { throw new ZenjectBindException( "Invalid type given during bind command. Expected type '{0}' to derive from type '{1}'".Fmt(concreteType.Name(), _contractType.Name())); } // We have to cast to object otherwise we get SecurityExceptions when this function is run outside of unity if (ZenUtil.IsNull(prefab) && !_container.AllowNullBindings) { throw new ZenjectBindException("Received null prefab while binding type '{0}'".Fmt(concreteType.Name())); } var prefabSingletonMap = _container.Resolve <PrefabSingletonProviderMap>(); return(ToProvider( prefabSingletonMap.CreateProvider(identifier, typeof(TConcrete), prefab))); }
public BindingConditionSetter ToInstance <TConcrete>(TConcrete instance) where TConcrete : TContract { if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == typeof(TConcrete)) { message = "Received null instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), typeof(TConcrete).Name()); } throw new ZenjectBindException(message); } return(ToProvider(new InstanceProvider(typeof(TConcrete), instance))); }
public BindingConditionSetter ToSingleInstance <TConcrete>(string concreteIdentifier, TConcrete instance) where TConcrete : TContract { if (ZenUtil.IsNull(instance) && !_container.AllowNullBindings) { string message; if (_contractType == typeof(TConcrete)) { message = "Received null singleton instance during Bind command with type '{0}'".Fmt(_contractType.Name()); } else { message = "Received null singleton instance during Bind command when binding type '{0}' to '{1}'".Fmt(_contractType.Name(), typeof(TConcrete).Name()); } throw new ZenjectBindException(message); } return(ToProvider(_singletonMap.CreateProviderFromInstance(concreteIdentifier, instance))); }