Initial Commit

This commit is contained in:
2026-03-16 14:38:46 +02:00
commit b8f7327a21
2327 changed files with 253610 additions and 0 deletions
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5a0ec9eb479742940a10701ec8a1d087
folderAsset: yes
timeCreated: 1461708047
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,121 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using System.Linq;
using ModestTree;
using UnityEngine;
using Zenject.Internal;
namespace Zenject
{
[NoReflectionBaking]
public class AddToCurrentGameObjectComponentProvider : IProvider
{
readonly Type _componentType;
readonly DiContainer _container;
readonly List<TypeValuePair> _extraArguments;
readonly object _concreteIdentifier;
readonly Action<InjectContext, object> _instantiateCallback;
public AddToCurrentGameObjectComponentProvider(
DiContainer container, Type componentType,
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
Action<InjectContext, object> instantiateCallback)
{
Assert.That(componentType.DerivesFrom<Component>());
_extraArguments = extraArguments.ToList();
_componentType = componentType;
_container = container;
_concreteIdentifier = concreteIdentifier;
_instantiateCallback = instantiateCallback;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
protected DiContainer Container
{
get { return _container; }
}
protected Type ComponentType
{
get { return _componentType; }
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
Assert.That(context.ObjectType.DerivesFrom<Component>(),
"Object '{0}' can only be injected into MonoBehaviour's since it was bound with 'FromNewComponentSibling'. Attempted to inject into non-MonoBehaviour '{1}'",
context.MemberType, context.ObjectType);
object instance;
if (!_container.IsValidating || TypeAnalyzer.ShouldAllowDuringValidation(_componentType))
{
var gameObj = ((Component)context.ObjectInstance).gameObject;
var componentInstance = gameObj.GetComponent(_componentType);
instance = componentInstance;
// Use componentInstance so that it triggers unity's overloaded comparison operator
// So if the component is there but missing then it returns null
// (https://github.com/svermeulen/Zenject/issues/582)
if (componentInstance != null)
{
injectAction = null;
buffer.Add(instance);
return;
}
instance = gameObj.AddComponent(_componentType);
}
else
{
instance = new ValidationMarker(_componentType);
}
// Note that we don't just use InstantiateComponentOnNewGameObjectExplicit here
// because then circular references don't work
injectAction = () =>
{
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
extraArgs.AllocFreeAddRange(_extraArguments);
extraArgs.AllocFreeAddRange(args);
_container.InjectExplicit(instance, _componentType, extraArgs, context, _concreteIdentifier);
Assert.That(extraArgs.IsEmpty());
ZenPools.DespawnList(extraArgs);
if (_instantiateCallback != null)
{
_instantiateCallback(context, instance);
}
};
buffer.Add(instance);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 3b0521d85aeb9ee479dcb29ef4d88547
timeCreated: 1465651364
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,69 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
namespace Zenject
{
[NoReflectionBaking]
public class AddToExistingGameObjectComponentProvider : AddToGameObjectComponentProviderBase
{
readonly GameObject _gameObject;
public AddToExistingGameObjectComponentProvider(
GameObject gameObject, DiContainer container, Type componentType,
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
Action<InjectContext, object> instantiateCallback)
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
{
_gameObject = gameObject;
}
// This will cause [Inject] to be triggered after awake / start
// We could return true, but what if toggling active has other negative repercussions?
// For now let's just not do anything
protected override bool ShouldToggleActive
{
get { return false; }
}
protected override GameObject GetGameObject(InjectContext context)
{
return _gameObject;
}
}
[NoReflectionBaking]
public class AddToExistingGameObjectComponentProviderGetter : AddToGameObjectComponentProviderBase
{
readonly Func<InjectContext, GameObject> _gameObjectGetter;
public AddToExistingGameObjectComponentProviderGetter(
Func<InjectContext, GameObject> gameObjectGetter, DiContainer container, Type componentType,
List<TypeValuePair> extraArguments, object concreteIdentifier,
Action<InjectContext, object> instantiateCallback)
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
{
_gameObjectGetter = gameObjectGetter;
}
// This will cause [Inject] to be triggered after awake / start
// We could return true, but what if toggling active has other negative repercussions?
// For now let's just not do anything
protected override bool ShouldToggleActive
{
get { return false; }
}
protected override GameObject GetGameObject(InjectContext context)
{
var gameObj = _gameObjectGetter(context);
Assert.IsNotNull(gameObj, "Provided Func<InjectContext, GameObject> returned null value for game object when using FromComponentOn");
return gameObj;
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 669e8af5b17774d45acea73d348e6dca
timeCreated: 1461708051
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,142 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using System.Linq;
using ModestTree;
using UnityEngine;
using Zenject.Internal;
namespace Zenject
{
[NoReflectionBaking]
public abstract class AddToGameObjectComponentProviderBase : IProvider
{
readonly Type _componentType;
readonly DiContainer _container;
readonly List<TypeValuePair> _extraArguments;
readonly object _concreteIdentifier;
readonly Action<InjectContext, object> _instantiateCallback;
public AddToGameObjectComponentProviderBase(
DiContainer container, Type componentType,
IEnumerable<TypeValuePair> extraArguments, object concreteIdentifier,
Action<InjectContext, object> instantiateCallback)
{
Assert.That(componentType.DerivesFrom<Component>());
_extraArguments = extraArguments.ToList();
_componentType = componentType;
_container = container;
_concreteIdentifier = concreteIdentifier;
_instantiateCallback = instantiateCallback;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
protected DiContainer Container
{
get { return _container; }
}
protected Type ComponentType
{
get { return _componentType; }
}
protected abstract bool ShouldToggleActive
{
get;
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
object instance;
// We still want to make sure we can get the game object during validation
var gameObj = GetGameObject(context);
var wasActive = gameObj.activeSelf;
if (wasActive && ShouldToggleActive)
{
// We need to do this in some cases to ensure that [Inject] always gets
// called before awake / start
gameObj.SetActive(false);
}
if (!_container.IsValidating || TypeAnalyzer.ShouldAllowDuringValidation(_componentType))
{
if (_componentType == typeof(Transform))
// Treat transform as a special case because it's the one component that's always automatically added
// Otherwise, calling AddComponent below will fail and return null
// This is nice to allow doing things like
// Container.Bind<Transform>().FromNewComponentOnNewGameObject();
{
instance = gameObj.transform;
}
else
{
instance = gameObj.AddComponent(_componentType);
}
Assert.IsNotNull(instance);
}
else
{
instance = new ValidationMarker(_componentType);
}
injectAction = () =>
{
try
{
var extraArgs = ZenPools.SpawnList<TypeValuePair>();
extraArgs.AllocFreeAddRange(_extraArguments);
extraArgs.AllocFreeAddRange(args);
_container.InjectExplicit(instance, _componentType, extraArgs, context, _concreteIdentifier);
Assert.That(extraArgs.Count == 0);
ZenPools.DespawnList(extraArgs);
if (_instantiateCallback != null)
{
_instantiateCallback(context, instance);
}
}
finally
{
if (wasActive && ShouldToggleActive)
{
gameObj.SetActive(true);
}
}
};
buffer.Add(instance);
}
protected abstract GameObject GetGameObject(InjectContext context);
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d818f8110e5b31d4eb27001e5c5b3eb9
timeCreated: 1461708054
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,41 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Zenject
{
[NoReflectionBaking]
public class AddToNewGameObjectComponentProvider : AddToGameObjectComponentProviderBase
{
readonly GameObjectCreationParameters _gameObjectBindInfo;
public AddToNewGameObjectComponentProvider(
DiContainer container, Type componentType,
IEnumerable<TypeValuePair> extraArguments, GameObjectCreationParameters gameObjectBindInfo,
object concreteIdentifier,
Action<InjectContext, object> instantiateCallback)
: base(container, componentType, extraArguments, concreteIdentifier, instantiateCallback)
{
_gameObjectBindInfo = gameObjectBindInfo;
}
protected override bool ShouldToggleActive
{
get { return true; }
}
protected override GameObject GetGameObject(InjectContext context)
{
if (_gameObjectBindInfo.Name == null)
{
_gameObjectBindInfo.Name = ComponentType.Name;
}
return Container.CreateEmptyGameObject(_gameObjectBindInfo, context);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 6e1085d337c03dd42a1d5493c11d9d23
timeCreated: 1461708051
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,71 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
namespace Zenject
{
[NoReflectionBaking]
public class GetFromGameObjectComponentProvider : IProvider
{
readonly GameObject _gameObject;
readonly Type _componentType;
readonly bool _matchSingle;
// if concreteType is null we use the contract type from inject context
public GetFromGameObjectComponentProvider(
Type componentType, GameObject gameObject, bool matchSingle)
{
_componentType = componentType;
_matchSingle = matchSingle;
_gameObject = gameObject;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
injectAction = null;
if (_matchSingle)
{
var match = _gameObject.GetComponent(_componentType);
Assert.IsNotNull(match, "Could not find component with type '{0}' on prefab '{1}'",
_componentType, _gameObject.name);
buffer.Add(match);
return;
}
var allComponents = _gameObject.GetComponents(_componentType);
Assert.That(allComponents.Length >= 1,
"Expected to find at least one component with type '{0}' on prefab '{1}'",
_componentType, _gameObject.name);
buffer.AllocFreeAddRange(allComponents);
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 8d5cdba9f2e79364dbf4f3d242fd22da
timeCreated: 1529229722
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,81 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
namespace Zenject
{
[NoReflectionBaking]
public class GetFromGameObjectGetterComponentProvider : IProvider
{
readonly Func<InjectContext, GameObject> _gameObjectGetter;
readonly Type _componentType;
readonly bool _matchSingle;
// if concreteType is null we use the contract type from inject context
public GetFromGameObjectGetterComponentProvider(
Type componentType, Func<InjectContext, GameObject> gameObjectGetter, bool matchSingle)
{
_componentType = componentType;
_matchSingle = matchSingle;
_gameObjectGetter = gameObjectGetter;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
injectAction = null;
if (context.Container.IsValidating)
{
buffer.Add(new ValidationMarker(_componentType));
}
else
{
var gameObject = _gameObjectGetter(context);
if (_matchSingle)
{
var match = gameObject.GetComponent(_componentType);
Assert.IsNotNull(match, "Could not find component with type '{0}' on game object '{1}'",
_componentType, gameObject.name);
buffer.Add(match);
return;
}
var allComponents = gameObject.GetComponents(_componentType);
Assert.That(allComponents.Length >= 1,
"Expected to find at least one component with type '{0}' on prefab '{1}'",
_componentType, gameObject.name);
buffer.AllocFreeAddRange(allComponents);
}
}
}
}
#endif
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 766643a5935eb704a929da28681bf70e
timeCreated: 1529230207
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,74 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using ModestTree;
namespace Zenject
{
[NoReflectionBaking]
public class GetFromPrefabComponentProvider : IProvider
{
readonly IPrefabInstantiator _prefabInstantiator;
readonly Type _componentType;
readonly bool _matchSingle;
// if concreteType is null we use the contract type from inject context
public GetFromPrefabComponentProvider(
Type componentType,
IPrefabInstantiator prefabInstantiator, bool matchSingle)
{
_prefabInstantiator = prefabInstantiator;
_componentType = componentType;
_matchSingle = matchSingle;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
var gameObject = _prefabInstantiator.Instantiate(context, args, out injectAction);
// NOTE: Need to set includeInactive to true here, because prefabs are always
// instantiated as disabled until injection occurs, so that Awake / OnEnabled is executed
// after injection has occurred
if (_matchSingle)
{
var match = gameObject.GetComponentInChildren(_componentType, true);
Assert.IsNotNull(match, "Could not find component with type '{0}' on prefab '{1}'",
_componentType, _prefabInstantiator.GetPrefab(context).name);
buffer.Add(match);
return;
}
var allComponents = gameObject.GetComponentsInChildren(_componentType, true);
Assert.That(allComponents.Length >= 1,
"Expected to find at least one component with type '{0}' on prefab '{1}'",
_componentType, _prefabInstantiator.GetPrefab(context).name);
buffer.AllocFreeAddRange(allComponents);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e6a49432e004bd8409d3ddea6a45a3f8
timeCreated: 1461708054
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,54 @@
#if !NOT_UNITY3D
using System;
using System.Collections.Generic;
using ModestTree;
namespace Zenject
{
[NoReflectionBaking]
public class InstantiateOnPrefabComponentProvider : IProvider
{
readonly IPrefabInstantiator _prefabInstantiator;
readonly Type _componentType;
// if concreteType is null we use the contract type from inject context
public InstantiateOnPrefabComponentProvider(
Type componentType,
IPrefabInstantiator prefabInstantiator)
{
_prefabInstantiator = prefabInstantiator;
_componentType = componentType;
}
public bool IsCached
{
get { return false; }
}
public bool TypeVariesBasedOnMemberType
{
get { return false; }
}
public Type GetInstanceType(InjectContext context)
{
return _componentType;
}
public void GetAllInstancesWithInjectSplit(
InjectContext context, List<TypeValuePair> args, out Action injectAction, List<object> buffer)
{
Assert.IsNotNull(context);
var gameObject = _prefabInstantiator.Instantiate(context, args, out injectAction);
var component = gameObject.AddComponent(_componentType);
buffer.Add(component);
}
}
}
#endif
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e6836adf19243a045ba39e67ade6dd59
timeCreated: 1505729206
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: