Update Project

This commit is contained in:
2026-03-20 13:04:43 +02:00
parent 9b587e6cba
commit beae2dea89
2295 changed files with 251259 additions and 33 deletions
@@ -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: