#if !NOT_UNITY3D using System; using System.Collections.Generic; using System.Linq; using ModestTree; using UnityEngine; using Zenject.Internal; namespace Zenject { [NoReflectionBaking] public class ScriptableObjectInstanceProvider : IProvider { readonly DiContainer _container; readonly Type _resourceType; readonly List _extraArguments; readonly bool _createNew; readonly object _concreteIdentifier; readonly Action _instantiateCallback; readonly UnityEngine.Object _resource; public ScriptableObjectInstanceProvider( UnityEngine.Object resource, Type resourceType, DiContainer container, IEnumerable extraArguments, bool createNew, object concreteIdentifier, Action instantiateCallback) { _container = container; Assert.DerivesFromOrEqual(resourceType); _resource = resource; _extraArguments = extraArguments.ToList(); _resourceType = resourceType; _createNew = createNew; _concreteIdentifier = concreteIdentifier; _instantiateCallback = instantiateCallback; } public bool IsCached { get { return false; } } public bool TypeVariesBasedOnMemberType { get { return false; } } public Type GetInstanceType(InjectContext context) { return _resourceType; } public void GetAllInstancesWithInjectSplit( InjectContext context, List args, out Action injectAction, List buffer) { Assert.IsNotNull(context); if (_createNew) { buffer.Add(UnityEngine.ScriptableObject.Instantiate(_resource)); } else { buffer.Add(_resource); } injectAction = () => { for (int i = 0; i < buffer.Count; i++) { var obj = buffer[i]; var extraArgs = ZenPools.SpawnList(); extraArgs.AllocFreeAddRange(_extraArguments); extraArgs.AllocFreeAddRange(args); _container.InjectExplicit( obj, _resourceType, extraArgs, context, _concreteIdentifier); ZenPools.DespawnList(extraArgs); if (_instantiateCallback != null) { _instantiateCallback(context, obj); } } }; } } } #endif