diff --git a/Documentation/Images/InstallerGameObjectsCollection.png b/Documentation/Images/InstallerGameObjectsCollection.png new file mode 100644 index 0000000..fdde2e7 Binary files /dev/null and b/Documentation/Images/InstallerGameObjectsCollection.png differ diff --git a/Framework/Binding/Implemantions/BindingFactory.cs b/Framework/Binding/Implemantions/BindingFactory.cs index f57bcd9..63fcb2a 100644 --- a/Framework/Binding/Implemantions/BindingFactory.cs +++ b/Framework/Binding/Implemantions/BindingFactory.cs @@ -68,10 +68,13 @@ public IBindingCondition AddBinding(object value, bool UseDefaultConstructor) return this.CreateBindingConditionFactoryProvider(binding); } - /// - public IBindingInjection AddFactoryInstance(Type type, IFactory factory) + /// + public IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance, object value = null) { - var binding = new BindingData(this.BindingType, factory, type, BindingInstanceType.Factory | BindingInstanceType.Instance); + var binding = new BindingData(this.BindingType, + factoryInstance, + value, + BindingInstanceType.Factory | BindingInstanceType.Instance); this.Binder.AddBinding(binding); return this.CreateBindingInjectionFactoryProvider(binding); diff --git a/Framework/Binding/Interfaces/IBindingFactory.cs b/Framework/Binding/Interfaces/IBindingFactory.cs index 01a7b12..5421e80 100644 --- a/Framework/Binding/Interfaces/IBindingFactory.cs +++ b/Framework/Binding/Interfaces/IBindingFactory.cs @@ -22,7 +22,7 @@ namespace EasyJection.Binding { using EasyJection.Types; - using Hooking; + #region Comment /// /// Contains the definitions of the binding factory. @@ -57,11 +57,11 @@ namespace EasyJection.Binding /// Binds the key type to a as a singleton. /// /// - /// + /// /// Binds the key type to a as a transient. /// /// - /// + /// /// Binds the key type to a type of as a transient. /// /// @@ -81,7 +81,7 @@ namespace EasyJection.Binding /// Binds the key type to an of a type which has implemented interface. /// /// - /// + /// /// Creates a binding. /// /// @@ -233,7 +233,8 @@ public interface IBindingFactory /// /// The type of instance that will be created by the factory. /// Factory creating instances + /// [Optional] Some value that can be used by the factory during instantiation. /// The binding injection object related to this binding. - IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance); + IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance, object value = null); } } diff --git a/Framework/CHANGELOG.md b/Framework/CHANGELOG.md index 7974524..58f4bf5 100644 --- a/Framework/CHANGELOG.md +++ b/Framework/CHANGELOG.md @@ -10,6 +10,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.2] - 2023-02-13 +- Fixed bugs with dependency resolution for instances created by the factory. +- Added support resolve for an array in field. + ## [1.0.1] - 2023-02-11 - Fixed a bug with injection to a default constructor. - Added the ability to bind a factory class without an inherited 'EasyJection.Types.IFactory' and specify the method for creating instances by method name. diff --git a/Framework/Resolving/Implementions/Resolver.cs b/Framework/Resolving/Implementions/Resolver.cs index 9cdd33c..351d519 100644 --- a/Framework/Resolving/Implementions/Resolver.cs +++ b/Framework/Resolving/Implementions/Resolver.cs @@ -105,7 +105,11 @@ public object Resolve(Type type, IDictionary scopedInstances) if (bindingData.InstanceType.HasFlag(BindingInstanceType.Instance)) { if (bindingData.InstanceType.HasFlag(BindingInstanceType.Factory)) - return bindingData.Factory.CreateInstance(bindingData); + { + var instValue = bindingData.Factory.CreateInstance(bindingData); + this.Inject(instValue); + return instValue; + } else return bindingData.Value; } @@ -132,6 +136,11 @@ public object Resolve(Type type, IDictionary scopedInstances) return instance; } + protected object Resolve(Type type) + { + return this.Resolve(type, null); + } + /// public object[] Resolve(object[] objects, Type[] types, IDictionary scopedInstances) { @@ -196,11 +205,17 @@ protected object Instantiate(Type instanceType, IBindingData bindingData, IDicti hookManager.Hook(); } - // Add an item to the scoped dictionary - scopedInstances.Add(bindingData.Type, instance); - - // Dependency Injection - this.Inject(instance, this.cache[instanceType], scopedInstances); + if (scopedInstances != null) + { + // Add an item to the scoped dictionary + scopedInstances.Add(bindingData.Type, instance); + // Dependency Injection + this.Inject(instance, this.cache[instanceType], scopedInstances); + } + else + { + this.Inject(instance); + } return instance; } @@ -232,7 +247,7 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++) { var field = fields[fieldIndex]; - + var fieldType = field.Type; var value = field.InvokeGetter(instance); // The Equals(null) comparison is used to ensure that null is evaluated correctly due to the null trick @@ -240,7 +255,7 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona { try { - var valueToSet = scopedInstances.ContainsKey(field.Type) ? scopedInstances[field.Type] : this.Resolve(field.Type, scopedInstances); + var valueToSet = scopedInstances.ContainsKey(fieldType) ? scopedInstances[fieldType] : this.Resolve(fieldType, scopedInstances); field.InvokeSetter(instance, valueToSet); } catch (Exception exception) @@ -249,6 +264,25 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona string.Format(Causes.UNABLE_TO_INJECT_ON_FIELD, field.Name, instance.GetType(), exception.Message), exception); } } + else if (fieldType.IsArray) + { + try + { + var elemType = fieldType.GetElementType(); + var array = (field.InvokeGetter(instance) as object[]); + for (int i = 0; i < array.Length; i++) + { + if (array[i] == null) + array[i] = this.Resolve(elemType); + } + scopedInstances.Add(fieldType, array); + } + catch (Exception exception) + { + throw new Exception( + string.Format(Causes.UNABLE_TO_INJECT_ON_FIELD, field.Name, instance.GetType(), exception.Message), exception); + } + } } } diff --git a/README.md b/README.md index 99cb064..dc2c8de 100644 --- a/README.md +++ b/README.md @@ -32,12 +32,14 @@ * [To Factory](#-to-factory) * [To Instance](#-to-instance) * [To Self](#-to-self) + * [To GameObject](#-to-gameobject) * [Injection Conditions](#injection-conditions) * [Constructor Injection](#-constructor-injection) * [Method Injection](#-method-injection) * [Non-return Method (MethodVoid)](#non-return-method-methodvoid) * [Method with result (MethodResult)](#method-with-result-methodresult) * [Passing Arguments](#passing-arguments) + * [Array Injection](#array-injection) * [Injection Notes](#injection-notes) * [Change Log](#-change-log) * [Contributing](#-contributing) @@ -561,7 +563,24 @@ container.Bind().ToSelf(UseDefaultConstructor: True | False); ``` Where: - *UseDefaultConstructor* — If True, the injection occurs each time the default constructor is called (from `new()`). - + +#### 🔘 To GameObject #### +The EasyJection framework allows you to create a binding to a Unity's gameobject that has a type of component you need. + +To bind to a gameobject, it must first be added to the installer's gameobjects collection: + + +The added prefab named `Cube` has a `Cube` component implementing a `ICube` interface and inherited from MonoBehaviour. + +After that the specified prefab named `Cube` can be used for binding as transient. + +```csharp +// "Cube" is the key name of the gameobject in the installer collection +Container.Bind().ToGameObject("Cube"); +// or so, in this case the type name is used (⚠️ a type name should match a key in the collection) +Container.Bind().ToGameObject(); +``` + ### Injection Conditions ### EasyJection provides injection through a constructor or method call. Constructor injection forces the dependency to only be resolved once, at instance creation, which is usually what you want. Inject methods are the recommended approach for MonoBehaviours (e.g. 'Awake' and 'Start' methods). Injection conditions are set by calling the `InjectionTo()` method. In order to specify a constructor or method for injection, you need to specify its signature. @@ -596,7 +615,6 @@ container.Bind() .Constructor(UseForInstantiation: True | False) .WithArguments(T1 arg1, T2 arg2 ... T9 arg9); ``` - Where: - *UseForInstantiation* — if True, the container will use this constructor to create an instance, otherwise it will use the default constructor. - ** — types of constructor parameters. @@ -628,6 +646,7 @@ container.Bind() .MethodVoid(methodName); .WithArguments(T1 arg1, T2 arg2 ... T9 arg9); ``` +Where: - *methodName* — the name of a non-return method - ** — types of constructor parameters. ##### Method with result (MethodResult) ##### @@ -655,6 +674,7 @@ container.Bind() .MethodResult(methodName); .WithArguments(T1 arg1, T2 arg2 ... T9 arg9); ``` +Where: - *methodName* — the name of a method. - ** — types of constructor parameters. - *TResult* — type of return value. @@ -700,8 +720,43 @@ Result: Where: - *UseForInstantiation* — if True, the container will use this constructor to create an instance, otherwise it will use the default constructor. +#### Array Injection #### +The EasyJection framework can inject and resolve all registered implementations for each array element in a field. + +```csharp + public class Foo + { + public ISomeInterface[] fieldArray; + + [MethodImpl(MethodImplOptions.NoInlining)] + // The array must be created before injection. + public SomeClass() + // the size of the array is 10 + : this(new ISomeInterface[10]) + { } + + [MethodImpl(MethodImplOptions.NoInlining)] + private SomeClass(ISomeInterface[] array) + { + this.fieldArray = array; + } + } + + ... + // Binding + var container = new Container(); + container.Bind().To(); + container.Bind().ToSelf(UseDefaultConstructor: true); + + ... + // So now the EasyJection framework creates and resolves 10 elements in a field named 'fieldArray' + var instance = new Foo(); +``` + #### Injection Notes #### +// TODO + ## 💾 Change Log ## All notable changes to this project will be documented in files: diff --git a/UnityPackage/CHANGELOG.md b/UnityPackage/CHANGELOG.md index 82e5eae..9be3617 100644 --- a/UnityPackage/CHANGELOG.md +++ b/UnityPackage/CHANGELOG.md @@ -11,6 +11,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.2] - 2023-02-13 +- Fixed bugs with dependency resolution for instances created by the factory. +- Added support resolve for an array in field. +- Added support for binding to GameObject. +- Updated samples and added new ones. + ## [1.0.1] - 2023-02-11 - Fixed a bug with injection to a default constructor. - Added the ability to bind a factory class without an inherited 'EasyJection.Types.IFactory' and specify the method for creating instances by method name. diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs new file mode 100644 index 0000000..7bc9697 --- /dev/null +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs @@ -0,0 +1,62 @@ +/* + * This file is part of the EasyJection Framework. + * Author: Max Karepin (http://github.com/imaxs/) + * + * Copyright © 2022 Max Karepin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WII || UNITY_IOS || UNITY_ANDROID || UNITY_PS4 || UNITY_XBOXONE || UNITY_TIZEN || UNITY_TVOS || UNITY_WSA || UNITY_WEBGL || UNITY_FACEBOOK +#define UNITY_ENGINE_AVAILABLE +#endif + +namespace EasyJection.Extensions +{ +#if UNITY_ENGINE_AVAILABLE + + using UnityEngine; + /// + /// Represents a prefab's binding. + /// + public class PrefabBinding + { + public string KeyName { get; private set; } + /// + /// The prefab to instantiate. + /// + public Object Prefab { get; set; } + + /// + /// The type that will be resolved from the prefab. + /// + public System.Type Type { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// The prefab to be instantiated. + /// The type that will be resolved from the prefab. + public PrefabBinding(string key, Object prefab, System.Type type) + { + this.KeyName = key; + this.Prefab = prefab; + this.Type = type; + } + + public PrefabBinding(string key, System.Type type) + : this(key, null, type) + { } + } +#endif +} diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs.meta b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs.meta new file mode 100644 index 0000000..d1cb9ec --- /dev/null +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/PrefabBinding.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4f1978e57e4c3f04484fc0472eb36aba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Binding/UnityEngineBinding.cs b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/UnityEngineBinding.cs index 045d8f7..5f93c0b 100644 --- a/UnityPackage/Runtime/Extensions/UnityEngine/Binding/UnityEngineBinding.cs +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Binding/UnityEngineBinding.cs @@ -42,7 +42,6 @@ public static class UnityEngineBinding public static Type TYPE_COMPONENT; private static IFactory GameObjectFactory; - private static IFactory ComponentFactory; static UnityEngineBinding() { @@ -50,140 +49,28 @@ static UnityEngineBinding() TYPE_COMPONENT = typeof(Component); TYPE_GAMEOBJECT = typeof(GameObject); GameObjectFactory = new UnityEngineGameObjectInstantiateFactory(); - ComponentFactory = new UnityEngineComponentInstantiateFactory(); } - #region Comment - /// - /// Creates a binding of the key type to the on a GameObject of a given as a singleton. - /// - /// - /// - /// Recommend binding only to that will not be destroyed in the scene to prevent references to destroyed objects. - /// - /// - /// 1️⃣ If the GameObject with the specified is not found on the game scene, it will be added. - /// - /// - /// 2️⃣ If the GameObject with the specified is not found on the GameObject, it will be added. - /// - /// - /// 3️⃣ If the is binds the key to the GameObject itself. - /// - /// - /// 4️⃣ If the is binds the key to an instance. - /// - /// - /// The original binding factory. - /// The component type. - /// The GameObject name. - /// The binding condition object related to this binding. - #endregion - public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory, Type type) + public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory) { - if (!Helper.IsAssignable(bindingFactory.BindingType, type)) - throw new Exception(Causes.TYPE_NOT_ASSIGNABLE); - if (type.IsInterface || type.IsAbstract) - throw new Exception(Causes.TYPE_NOT_IMPLEMENTED); - if (!Helper.IsAssignable(TYPE_GAMEOBJECT, type)) - throw new Exception(string.Format("The \"{0}\" type must be derived from UnityEngine.GameObject.", type.Name)); - - return bindingFactory.AddFactoryInstance(type, GameObjectFactory); + var type = typeof(T); + return bindingFactory.ToGameObject(type, type.Name); } - public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory) + public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory, string prefabKeyName) { - return bindingFactory.ToGameObject(bindingFactory.BindingType); + return bindingFactory.ToGameObject(typeof(T), prefabKeyName); } - public static IBindingInjection ToComponent(this IBindingFactory bindingFactory, Type type) + public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory, Type type, string gameobjectKey) { if (!Helper.IsAssignable(bindingFactory.BindingType, type)) throw new Exception(Causes.TYPE_NOT_ASSIGNABLE); if (type.IsInterface || type.IsAbstract) throw new Exception(Causes.TYPE_NOT_IMPLEMENTED); - if (!Helper.IsAssignable(TYPE_COMPONENT, type)) - throw new Exception(string.Format("The \"{0}\" type must be derived from UnityEngine.Component.", type.Name)); - - return bindingFactory.AddFactoryInstance(type, ComponentFactory); - } - - //public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory, Type type, string objectName = null) - //{ - - // GameObject instance = null; - - // if (string.IsNullOrEmpty(objectName)) - // instance = new GameObject(type.Name); - // else - // instance = GameObject.Find(objectName) ?? new GameObject(type.Name); - - // return CreateSingletonProvider(bindingFactory, instance, type, objectType); - //} - /* - #region Comment - /// - /// Creates a binding of the key type to the type on a GameObject of a given as a singleton. - /// - /// - /// - /// If the GameObject with the specified is not found on the GameObject, it will be added. - /// - /// - /// The component type. - /// The original binding factory. - /// The GameObject name. - /// The binding condition object related to this binding. - #endregion - public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory, string objectName) where T : Component - { - return bindingFactory.ToGameObject(typeof(T), objectName); - } - - #region Comment - /// - /// Creates a binding of the key type to the type on a new GameObject as a singleton. - /// - /// - /// - /// The component type. - /// The original binding factory. - /// The binding condition object related to this binding. - #endregion - public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory) where T : Component - { - return bindingFactory.ToGameObject(typeof(T)); - } - - #region Comment - /// - /// Creates a binding of the key type to itself on a new GameObject as a singleton. - /// ⚠ The key type must be derived either from or . - /// - /// - /// Recommend binding only to that will not be destroyed in the scene to prevent references to destroyed objects. - /// - /// The original binding factory. - /// The binding condition object related to this binding. - #endregion - public static IBindingInjection ToGameObject(this IBindingFactory bindingFactory) - { - return bindingFactory.ToGameObject(bindingFactory.BindingType); - } - - private static UnityEngineBindingCondition CreateSingletonProvider(IBindingFactory bindingFactory, GameObject gameObject, Type type, UnityEngineObjectType objectType) - { - if (gameObject == null) - throw new ArgumentNullException("The argument named 'gameObject' is null"); - - if (objectType == UnityEngineObjectType.GameObject) - return new UnityEngineBindingCondition(bindingFactory.AddBinding(gameObject, BindingInstanceType.Instance, false), gameObject.name); - - var component = gameObject.GetComponent(type) ?? gameObject.AddComponent(type); - return new UnityEngineBindingCondition(bindingFactory.AddBinding(component, BindingInstanceType.Instance, false), gameObject.name); + return bindingFactory.AddFactoryInstance(type, GameObjectFactory, new PrefabBinding(gameobjectKey, type)); } - */ } #endif } diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Install/MonoInstaller.cs b/UnityPackage/Runtime/Extensions/UnityEngine/Install/MonoInstaller.cs index cd909fc..c58010b 100644 --- a/UnityPackage/Runtime/Extensions/UnityEngine/Install/MonoInstaller.cs +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Install/MonoInstaller.cs @@ -25,11 +25,17 @@ namespace EasyJection { + using EasyJection.Extensions; + using System.Collections.Generic; #if UNITY_ENGINE_AVAILABLE using UnityEngine; + [DisallowMultipleComponent] public abstract class MonoInstaller : MonoBehaviour { + [SerializeField] + protected StringGameObjectPair[] gameObjects; + protected IContainer Container; protected abstract void InstallBindings(); @@ -42,6 +48,19 @@ protected MonoInstaller() this.InstallBindings(); } + protected void Awake() + { + if (gameObjects != null && gameObjects.Length > 0) + { + var dict = new Dictionary(); + + foreach (var pair in gameObjects) + dict.Add(pair.Key, pair.Object); + + Mono.SetDictionary(dict); + } + } + protected void OnDestroy() { if (Container != null) diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs b/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs new file mode 100644 index 0000000..d8a7f53 --- /dev/null +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs @@ -0,0 +1,60 @@ +/* + * This file is part of the EasyJection Framework. + * Author: Max Karepin (http://github.com/imaxs/) + * + * Copyright © 2022 Max Karepin + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WII || UNITY_IOS || UNITY_ANDROID || UNITY_PS4 || UNITY_XBOXONE || UNITY_TIZEN || UNITY_TVOS || UNITY_WSA || UNITY_WEBGL || UNITY_FACEBOOK + #define UNITY_ENGINE_AVAILABLE +#endif + +using System; +using System.Collections.Generic; + +namespace EasyJection.Extensions +{ +#if UNITY_ENGINE_AVAILABLE + using UnityEngine; + + [Serializable] + public class StringGameObjectPair + { + public string Key; + public GameObject Object; + } + + public static class Mono + { + private static IDictionary gameObjectsDict; + + public static void SetDictionary(Dictionary dict) + { + if (gameObjectsDict != null) + gameObjectsDict.Clear(); + + gameObjectsDict = dict; + } + + public static GameObject GetGameObjectByName(string key) + { + if (gameObjectsDict.ContainsKey(key)) + return gameObjectsDict[key]; + + return null; + } + } +#endif +} diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs.meta b/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs.meta new file mode 100644 index 0000000..86a56cc --- /dev/null +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Install/StringGameObjectPair.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 098b1d74399e97140bffa0a5144bcf57 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Runtime/Extensions/UnityEngine/Resolving/UnityEngineFactories.cs b/UnityPackage/Runtime/Extensions/UnityEngine/Resolving/UnityEngineFactories.cs index 83cdc0c..985b03b 100644 --- a/UnityPackage/Runtime/Extensions/UnityEngine/Resolving/UnityEngineFactories.cs +++ b/UnityPackage/Runtime/Extensions/UnityEngine/Resolving/UnityEngineFactories.cs @@ -34,15 +34,16 @@ public class UnityEngineGameObjectInstantiateFactory : IFactory { public object CreateInstance(IBindingData bindingData = null) { - return new GameObject((bindingData.Value as Type).Name); - } - } + var prefabBinding = bindingData.Value as PrefabBinding; + if (prefabBinding == null) + throw new Exception(string.Format("The \"{0}\" type must be a PrefabBinding.", bindingData.Value?.GetType())); - public class UnityEngineComponentInstantiateFactory : IFactory - { - public object CreateInstance(IBindingData bindingData = null) - { - return new GameObject((bindingData.Value as Type).Name); + if (prefabBinding.Prefab == null) + prefabBinding.Prefab = Mono.GetGameObjectByName(prefabBinding.KeyName); + + GameObject gameObject = (GameObject)MonoBehaviour.Instantiate(prefabBinding.Prefab); + + return gameObject.GetComponent(prefabBinding.Type); } } #endif diff --git a/UnityPackage/Runtime/Framework/Binding/Implemantions/BindingFactory.cs b/UnityPackage/Runtime/Framework/Binding/Implemantions/BindingFactory.cs index f57bcd9..63fcb2a 100644 --- a/UnityPackage/Runtime/Framework/Binding/Implemantions/BindingFactory.cs +++ b/UnityPackage/Runtime/Framework/Binding/Implemantions/BindingFactory.cs @@ -68,10 +68,13 @@ public IBindingCondition AddBinding(object value, bool UseDefaultConstructor) return this.CreateBindingConditionFactoryProvider(binding); } - /// - public IBindingInjection AddFactoryInstance(Type type, IFactory factory) + /// + public IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance, object value = null) { - var binding = new BindingData(this.BindingType, factory, type, BindingInstanceType.Factory | BindingInstanceType.Instance); + var binding = new BindingData(this.BindingType, + factoryInstance, + value, + BindingInstanceType.Factory | BindingInstanceType.Instance); this.Binder.AddBinding(binding); return this.CreateBindingInjectionFactoryProvider(binding); diff --git a/UnityPackage/Runtime/Framework/Binding/Interfaces/IBindingFactory.cs b/UnityPackage/Runtime/Framework/Binding/Interfaces/IBindingFactory.cs index 01a7b12..5421e80 100644 --- a/UnityPackage/Runtime/Framework/Binding/Interfaces/IBindingFactory.cs +++ b/UnityPackage/Runtime/Framework/Binding/Interfaces/IBindingFactory.cs @@ -22,7 +22,7 @@ namespace EasyJection.Binding { using EasyJection.Types; - using Hooking; + #region Comment /// /// Contains the definitions of the binding factory. @@ -57,11 +57,11 @@ namespace EasyJection.Binding /// Binds the key type to a as a singleton. /// /// - /// + /// /// Binds the key type to a as a transient. /// /// - /// + /// /// Binds the key type to a type of as a transient. /// /// @@ -81,7 +81,7 @@ namespace EasyJection.Binding /// Binds the key type to an of a type which has implemented interface. /// /// - /// + /// /// Creates a binding. /// /// @@ -233,7 +233,8 @@ public interface IBindingFactory /// /// The type of instance that will be created by the factory. /// Factory creating instances + /// [Optional] Some value that can be used by the factory during instantiation. /// The binding injection object related to this binding. - IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance); + IBindingInjection AddFactoryInstance(Type type, IFactory factoryInstance, object value = null); } } diff --git a/UnityPackage/Runtime/Framework/Resolving/Implementions/Resolver.cs b/UnityPackage/Runtime/Framework/Resolving/Implementions/Resolver.cs index 9cdd33c..351d519 100644 --- a/UnityPackage/Runtime/Framework/Resolving/Implementions/Resolver.cs +++ b/UnityPackage/Runtime/Framework/Resolving/Implementions/Resolver.cs @@ -105,7 +105,11 @@ public object Resolve(Type type, IDictionary scopedInstances) if (bindingData.InstanceType.HasFlag(BindingInstanceType.Instance)) { if (bindingData.InstanceType.HasFlag(BindingInstanceType.Factory)) - return bindingData.Factory.CreateInstance(bindingData); + { + var instValue = bindingData.Factory.CreateInstance(bindingData); + this.Inject(instValue); + return instValue; + } else return bindingData.Value; } @@ -132,6 +136,11 @@ public object Resolve(Type type, IDictionary scopedInstances) return instance; } + protected object Resolve(Type type) + { + return this.Resolve(type, null); + } + /// public object[] Resolve(object[] objects, Type[] types, IDictionary scopedInstances) { @@ -196,11 +205,17 @@ protected object Instantiate(Type instanceType, IBindingData bindingData, IDicti hookManager.Hook(); } - // Add an item to the scoped dictionary - scopedInstances.Add(bindingData.Type, instance); - - // Dependency Injection - this.Inject(instance, this.cache[instanceType], scopedInstances); + if (scopedInstances != null) + { + // Add an item to the scoped dictionary + scopedInstances.Add(bindingData.Type, instance); + // Dependency Injection + this.Inject(instance, this.cache[instanceType], scopedInstances); + } + else + { + this.Inject(instance); + } return instance; } @@ -232,7 +247,7 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona for (int fieldIndex = 0; fieldIndex < fields.Length; fieldIndex++) { var field = fields[fieldIndex]; - + var fieldType = field.Type; var value = field.InvokeGetter(instance); // The Equals(null) comparison is used to ensure that null is evaluated correctly due to the null trick @@ -240,7 +255,7 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona { try { - var valueToSet = scopedInstances.ContainsKey(field.Type) ? scopedInstances[field.Type] : this.Resolve(field.Type, scopedInstances); + var valueToSet = scopedInstances.ContainsKey(fieldType) ? scopedInstances[fieldType] : this.Resolve(fieldType, scopedInstances); field.InvokeSetter(instance, valueToSet); } catch (Exception exception) @@ -249,6 +264,25 @@ protected void InjectFields(object instance, AccessoriesInfo[] fields, IDictiona string.Format(Causes.UNABLE_TO_INJECT_ON_FIELD, field.Name, instance.GetType(), exception.Message), exception); } } + else if (fieldType.IsArray) + { + try + { + var elemType = fieldType.GetElementType(); + var array = (field.InvokeGetter(instance) as object[]); + for (int i = 0; i < array.Length; i++) + { + if (array[i] == null) + array[i] = this.Resolve(elemType); + } + scopedInstances.Add(fieldType, array); + } + catch (Exception exception) + { + throw new Exception( + string.Format(Causes.UNABLE_TO_INJECT_ON_FIELD, field.Name, instance.GetType(), exception.Message), exception); + } + } } } diff --git a/UnityPackage/Samples/1_Simple Binding/Cube.cs b/UnityPackage/Samples/1_Simple Binding/Cube.cs index c6b065a..7c1b0a7 100644 --- a/UnityPackage/Samples/1_Simple Binding/Cube.cs +++ b/UnityPackage/Samples/1_Simple Binding/Cube.cs @@ -2,21 +2,22 @@ using System.Runtime.CompilerServices; using UnityEngine; -public class BasicCube : MonoBehaviour +namespace EasyJection.Samples.SimpleBinding { - protected IRotate m_RotateSystem; -} - -public class Cube : BasicCube -{ - [MethodImpl(MethodImplOptions.NoInlining)] - public Cube() + public class BasicCube : MonoBehaviour { - UnityEngine.Debug.Log("Cube()"); + protected IRotate m_RotateSystem; } - private void Update() + public class Cube : BasicCube { - m_RotateSystem.DoRotate(0, 0.25f, 0); + [MethodImpl(MethodImplOptions.NoInlining)] + public Cube() + { } + + private void Update() + { + m_RotateSystem.DoRotate(0, 0.25f, 0); + } } } \ No newline at end of file diff --git a/UnityPackage/Samples/1_Simple Binding/IRotate.cs b/UnityPackage/Samples/1_Simple Binding/IRotate.cs index f6e5c9b..67fd421 100644 --- a/UnityPackage/Samples/1_Simple Binding/IRotate.cs +++ b/UnityPackage/Samples/1_Simple Binding/IRotate.cs @@ -1,7 +1,10 @@ // IRotate.cs using UnityEngine; -public interface IRotate +namespace EasyJection.Samples.SimpleBinding { - void DoRotate(float x, float y, float z); + public interface IRotate + { + void DoRotate(float x, float y, float z); + } } \ No newline at end of file diff --git a/UnityPackage/Samples/1_Simple Binding/Installer.cs b/UnityPackage/Samples/1_Simple Binding/Installer.cs index d7f800b..a32c35b 100644 --- a/UnityPackage/Samples/1_Simple Binding/Installer.cs +++ b/UnityPackage/Samples/1_Simple Binding/Installer.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using UnityEngine; -namespace EasyJection +namespace EasyJection.Samples.SimpleBinding { + [DefaultExecutionOrder(-800)] public class Installer : MonoInstaller { protected override void InstallBindings() diff --git a/UnityPackage/Samples/1_Simple Binding/Installer.cs.meta b/UnityPackage/Samples/1_Simple Binding/Installer.cs.meta index 94ba4f2..700fd2b 100644 --- a/UnityPackage/Samples/1_Simple Binding/Installer.cs.meta +++ b/UnityPackage/Samples/1_Simple Binding/Installer.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: -800 + executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: diff --git a/UnityPackage/Samples/1_Simple Binding/Rotate.cs b/UnityPackage/Samples/1_Simple Binding/Rotate.cs index d5ae4ad..a361e5f 100644 --- a/UnityPackage/Samples/1_Simple Binding/Rotate.cs +++ b/UnityPackage/Samples/1_Simple Binding/Rotate.cs @@ -1,13 +1,15 @@ // Rotate.cs -using System.Runtime.CompilerServices; using UnityEngine; -public class Rotate : IRotate +namespace EasyJection.Samples.SimpleBinding { - private Cube m_Cube; - - public void DoRotate(float x, float y, float z) + public class Rotate : IRotate { - m_Cube.transform.Rotate(x, y, z); + private Cube m_Cube; + + public void DoRotate(float x, float y, float z) + { + m_Cube.transform.Rotate(x, y, z); + } } } \ No newline at end of file diff --git a/UnityPackage/Samples/2_Binding Prefab.meta b/UnityPackage/Samples/2_Binding Prefab.meta new file mode 100644 index 0000000..46f027e --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6553fcdbcb68c0c4095ee09ac3207472 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity b/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity new file mode 100644 index 0000000..2674f87 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity @@ -0,0 +1,395 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &607730804 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 607730806} + - component: {fileID: 607730805} + m_Layer: 0 + m_Name: Installer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &607730805 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 607730804} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 1ebf9bcf6a14f04418506e5d24fbee6e, type: 3} + m_Name: + m_EditorClassIdentifier: + gameObjects: + - Key: Cube + Object: {fileID: 3855142852996578538, guid: 14eab43a4dbcbac48b2aa122eca392aa, type: 3} +--- !u!4 &607730806 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 607730804} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &935751130 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 935751133} + - component: {fileID: 935751132} + - component: {fileID: 935751131} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &935751131 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_Enabled: 1 +--- !u!20 &935751132 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &935751133 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_LocalRotation: {x: 0.30070576, y: 0, z: 0, w: 0.953717} + m_LocalPosition: {x: 0, y: 3.5, z: -7.5} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1428049839 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1428049841} + - component: {fileID: 1428049840} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &1428049840 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428049839} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1428049841 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428049839} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &1875808196 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1875808198} + - component: {fileID: 1875808197} + m_Layer: 0 + m_Name: Scripts + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1875808197 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1875808196} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c14bd9d0a9de36e4eac116b9729b3189, type: 3} + m_Name: + m_EditorClassIdentifier: + radius: 5 +--- !u!4 &1875808198 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1875808196} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity.meta b/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity.meta new file mode 100644 index 0000000..3b5dbef --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Binding Prefab.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 1472d9c1c50453c49b8c51a04a25250f +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs b/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs new file mode 100644 index 0000000..89e5bee --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs @@ -0,0 +1,68 @@ +using System.Collections; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefab +{ + public class CircleFormation : MonoBehaviour + { + private ICube[] array; + + private ICube cube_1; + private ICube cube_2; + private ICube cube_3; + private ICube cube_4; + private ICube cube_5; + private ICube cube_6; + private ICube cube_7; + private ICube cube_8; + private ICube cube_9; + private ICube cube_10; + private ICube cube_11; + private ICube cube_12; + private ICube cube_13; + private ICube cube_14; + private ICube cube_15; + + [SerializeField] + private float radius = 5f; + + [MethodImpl(MethodImplOptions.NoInlining)] + // Dependency injection occurs when the 'Awake' method is called. + private void Awake() + { } + + void Start() + { + // Push all 15 'iCube' objects into an array + array = new[] + { + cube_1, + cube_2, + cube_3, + cube_4, + cube_5, + cube_6, + cube_7, + cube_8, + cube_9, + cube_10, + cube_11, + cube_12, + cube_13, + cube_14, + cube_15 + }; + + for (int i = 0; i < array.Length; i++) + { + float angle = i * Mathf.PI * 2 / array.Length; + float x = Mathf.Cos(angle) * radius; + float z = Mathf.Sin(angle) * radius; + Vector3 pos = transform.position + new Vector3(x, 0, z); + array[i].SetPosition(pos); + } + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs.meta b/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs.meta new file mode 100644 index 0000000..3240f3a --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/CircleFormation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c14bd9d0a9de36e4eac116b9729b3189 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Installer.cs b/UnityPackage/Samples/2_Binding Prefab/Installer.cs new file mode 100644 index 0000000..22752bf --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Installer.cs @@ -0,0 +1,17 @@ +using EasyJection.Extensions; +using System; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefab +{ + [DefaultExecutionOrder(-800)] + public class Installer : MonoInstaller + { + protected override void InstallBindings() + { + Container.Bind().To(); + Container.Bind().ToGameObject("Cube"); + Container.Bind().ToSelf().InjectionTo().MethodVoid("Awake"); + } + } +} diff --git a/UnityPackage/Samples/2_Binding Prefab/Installer.cs.meta b/UnityPackage/Samples/2_Binding Prefab/Installer.cs.meta new file mode 100644 index 0000000..d89f485 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Installer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1ebf9bcf6a14f04418506e5d24fbee6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Materials.meta b/UnityPackage/Samples/2_Binding Prefab/Materials.meta new file mode 100644 index 0000000..7022967 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4db9bc231bd181a41b543a62eacb4b4d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat b/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat new file mode 100644 index 0000000..bed7454 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Block + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: 4ddeb52d7523a244f9d9b2d6b90fde5d, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 0.207 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat.meta b/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat.meta new file mode 100644 index 0000000..a42a98f --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Materials/Block.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7fab5d6ef25ea5c4e8c7e7313567dc6a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs.meta new file mode 100644 index 0000000..994ead2 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ef899eb11609d3847a7f83864033b639 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab new file mode 100644 index 0000000..236246b --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab @@ -0,0 +1,98 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3855142852996578538 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 383541141858110277} + - component: {fileID: 6429071897397168498} + - component: {fileID: 7415225873948093022} + - component: {fileID: 4281065709993433203} + m_Layer: 0 + m_Name: Cube + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &383541141858110277 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.99, y: 0.99, z: 0.99} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &6429071897397168498 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &7415225873948093022 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 7fab5d6ef25ea5c4e8c7e7313567dc6a, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!114 &4281065709993433203 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c5f9a3854683f9747a72d302b4f6b72c, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab.meta new file mode 100644 index 0000000..bb30b7c --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Cube.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 14eab43a4dbcbac48b2aa122eca392aa +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts.meta new file mode 100644 index 0000000..d8812fd --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8b232db67384dea4182046594dcaee09 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs new file mode 100644 index 0000000..66ed513 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs @@ -0,0 +1,30 @@ +// Cube.cs +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefab +{ + public interface ICube + { + void SetPosition(Vector3 positon); + void Update(); + } + + public class BasicCube : MonoBehaviour + { + protected IRotate m_RotateSystem; + } + + public class Cube : BasicCube, ICube + { + public void SetPosition(Vector3 positon) + { + transform.position = positon; + } + + public void Update() + { + m_RotateSystem.DoRotate(0, 0.25f, 0); + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs.meta new file mode 100644 index 0000000..de6fc2d --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Cube.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c5f9a3854683f9747a72d302b4f6b72c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs new file mode 100644 index 0000000..3f2e6e8 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs @@ -0,0 +1,10 @@ +// IRotate.cs +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefab +{ + public interface IRotate + { + void DoRotate(float x, float y, float z); + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs.meta new file mode 100644 index 0000000..190bcc9 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/IRotate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0b4b74473e34f9146ac2741b23c7299f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs new file mode 100644 index 0000000..3ae4238 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs @@ -0,0 +1,15 @@ +// Rotate.cs +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefab +{ + public class Rotate : IRotate + { + private Cube m_Cube; + + public void DoRotate(float x, float y, float z) + { + m_Cube.transform.Rotate(x, y, z); + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs.meta b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs.meta new file mode 100644 index 0000000..e8286cb --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Prefabs/Scripts/Rotate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a4ec97b3b8d0b148b68cf39de4a31d3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Textures.meta b/UnityPackage/Samples/2_Binding Prefab/Textures.meta new file mode 100644 index 0000000..b87de9f --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Textures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 950647fe65c35e04b9d10f1ddad1b75b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png b/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png new file mode 100644 index 0000000..da59b57 Binary files /dev/null and b/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png differ diff --git a/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png.meta b/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png.meta new file mode 100644 index 0000000..e26e401 --- /dev/null +++ b/UnityPackage/Samples/2_Binding Prefab/Textures/White Square.png.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: 4ddeb52d7523a244f9d9b2d6b90fde5d +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 7 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 16 + mipBias: -100 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array.meta b/UnityPackage/Samples/3_Binding Prefab Array.meta new file mode 100644 index 0000000..8bd648c --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 52d18b26c6b12094da3bec5ac9057637 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity b/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity new file mode 100644 index 0000000..c119652 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity @@ -0,0 +1,395 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 0 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 10304, guid: 0000000000000000f000000000000000, type: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 12 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 1 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 12 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_ExtractAmbientOcclusion: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 2 + m_BakeBackend: 1 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 512 + m_PVRBounces: 2 + m_PVREnvironmentSampleCount: 256 + m_PVREnvironmentReferencePointCount: 2048 + m_PVRFilteringMode: 1 + m_PVRDenoiserTypeDirect: 1 + m_PVRDenoiserTypeIndirect: 1 + m_PVRDenoiserTypeAO: 1 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVREnvironmentMIS: 1 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ExportTrainingData: 0 + m_TrainingDataDestination: TrainingData + m_LightProbeSampleCountMultiplier: 4 + m_LightingDataAsset: {fileID: 0} + m_LightingSettings: {fileID: 0} +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + maxJobWorkers: 0 + preserveTilesOutsideBounds: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &607730804 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 607730806} + - component: {fileID: 607730807} + m_Layer: 0 + m_Name: Installer + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &607730806 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 607730804} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &607730807 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 607730804} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 02204759aaad2784290fb6bd581f9bc1, type: 3} + m_Name: + m_EditorClassIdentifier: + gameObjects: + - Key: Cube + Object: {fileID: 3855142852996578538, guid: a1290b5302a43e94ea3777df0835fce4, type: 3} +--- !u!1 &935751130 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 935751133} + - component: {fileID: 935751132} + - component: {fileID: 935751131} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &935751131 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_Enabled: 1 +--- !u!20 &935751132 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_GateFitMode: 2 + m_FOVAxisMode: 0 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 0 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 1 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &935751133 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 935751130} + m_LocalRotation: {x: 0.30070576, y: 0, z: 0, w: 0.953717} + m_LocalPosition: {x: 0, y: 3.5, z: -7.5} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1428049839 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1428049841} + - component: {fileID: 1428049840} + m_Layer: 0 + m_Name: Directional Light + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!108 &1428049840 +Light: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428049839} + m_Enabled: 1 + serializedVersion: 10 + m_Type: 1 + m_Shape: 0 + m_Color: {r: 1, g: 0.95686275, b: 0.8392157, a: 1} + m_Intensity: 1 + m_Range: 10 + m_SpotAngle: 30 + m_InnerSpotAngle: 21.80208 + m_CookieSize: 10 + m_Shadows: + m_Type: 2 + m_Resolution: -1 + m_CustomResolution: -1 + m_Strength: 1 + m_Bias: 0.05 + m_NormalBias: 0.4 + m_NearPlane: 0.2 + m_CullingMatrixOverride: + e00: 1 + e01: 0 + e02: 0 + e03: 0 + e10: 0 + e11: 1 + e12: 0 + e13: 0 + e20: 0 + e21: 0 + e22: 1 + e23: 0 + e30: 0 + e31: 0 + e32: 0 + e33: 1 + m_UseCullingMatrixOverride: 0 + m_Cookie: {fileID: 0} + m_DrawHalo: 0 + m_Flare: {fileID: 0} + m_RenderMode: 0 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingLayerMask: 1 + m_Lightmapping: 4 + m_LightShadowCasterMode: 0 + m_AreaSize: {x: 1, y: 1} + m_BounceIntensity: 1 + m_ColorTemperature: 6570 + m_UseColorTemperature: 0 + m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} + m_UseBoundingSphereOverride: 0 + m_UseViewFrustumForShadowCasterCull: 1 + m_ShadowRadius: 0 + m_ShadowAngle: 0 +--- !u!4 &1428049841 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1428049839} + m_LocalRotation: {x: 0.40821788, y: -0.23456968, z: 0.10938163, w: 0.8754261} + m_LocalPosition: {x: 0, y: 3, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} +--- !u!1 &1875808196 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1875808198} + - component: {fileID: 1875808199} + m_Layer: 0 + m_Name: Scripts + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &1875808198 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1875808196} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1875808199 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1875808196} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0e71de8a4a0ac79448523d97720ea3ae, type: 3} + m_Name: + m_EditorClassIdentifier: + radius: 5 diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity.meta b/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity.meta new file mode 100644 index 0000000..2770aeb --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Binding Prefab Array.unity.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 0b13b8c28f9709343b62ad3ea4bc6279 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs b/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs new file mode 100644 index 0000000..e0bdecd --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs @@ -0,0 +1,38 @@ +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefabArray +{ + public class CircleFormation : MonoBehaviour + { + private ICube[] array; + + [SerializeField] + private float radius = 5f; + + private const int count = 20; + + [MethodImpl(MethodImplOptions.NoInlining)] + protected CircleFormation() + { + array = new ICube[count]; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + // Dependency injection occurs when the 'Awake' method is called. + private void Awake() + { } + + void Start() + { + for (int i = 0; i < array.Length; i++) + { + float angle = i * Mathf.PI * 2 / array.Length; + float x = Mathf.Cos(angle) * radius; + float z = Mathf.Sin(angle) * radius; + Vector3 pos = transform.position + new Vector3(x, 0, z); + array[i].SetPosition(pos); + } + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs.meta b/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs.meta new file mode 100644 index 0000000..8a5391e --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/CircleFormation.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0e71de8a4a0ac79448523d97720ea3ae +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs b/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs new file mode 100644 index 0000000..605c61d --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs @@ -0,0 +1,17 @@ +using EasyJection.Extensions; +using System; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefabArray +{ + [DefaultExecutionOrder(-800)] + public class Installer : MonoInstaller + { + protected override void InstallBindings() + { + Container.Bind().To(); + Container.Bind().ToGameObject("Cube"); + Container.Bind().ToSelf().InjectionTo().MethodVoid("Awake"); + } + } +} diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs.meta b/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs.meta new file mode 100644 index 0000000..dee8c32 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Installer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 02204759aaad2784290fb6bd581f9bc1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Materials.meta b/UnityPackage/Samples/3_Binding Prefab Array/Materials.meta new file mode 100644 index 0000000..692e4f6 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Materials.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8ade51c63e4138644a31c0f5b4023efd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat b/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat new file mode 100644 index 0000000..bed7454 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat @@ -0,0 +1,77 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Block + m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 2800000, guid: 4ddeb52d7523a244f9d9b2d6b90fde5d, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Floats: + - _BumpScale: 1 + - _Cutoff: 0.5 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _GlossMapScale: 0.207 + - _Glossiness: 0.5 + - _GlossyReflections: 1 + - _Metallic: 0 + - _Mode: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.02 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _UVSec: 0 + - _ZWrite: 1 + m_Colors: + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat.meta b/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat.meta new file mode 100644 index 0000000..dafc050 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Materials/Block.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 07a3472c56580b74e850d6e5d2f5d65a +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs.meta new file mode 100644 index 0000000..aa980c1 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 12fc023b3f67c7d4e9673685c9f71492 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab new file mode 100644 index 0000000..dc919f1 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab @@ -0,0 +1,98 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3855142852996578538 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 383541141858110277} + - component: {fileID: 6429071897397168498} + - component: {fileID: 7415225873948093022} + - component: {fileID: -7294551610445785730} + m_Layer: 0 + m_Name: Cube_2 + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &383541141858110277 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 0.99, y: 0.99, z: 0.99} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!33 &6429071897397168498 +MeshFilter: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} +--- !u!23 &7415225873948093022 +MeshRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 2 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: 7fab5d6ef25ea5c4e8c7e7313567dc6a, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 0 + m_SelectedEditorRenderState: 3 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 0 + m_SortingLayer: 0 + m_SortingOrder: 0 + m_AdditionalVertexStreams: {fileID: 0} +--- !u!114 &-7294551610445785730 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3855142852996578538} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7a5eea77a48f43648a20cca0f9b1d2b7, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab.meta new file mode 100644 index 0000000..f726115 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Cube_2.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a1290b5302a43e94ea3777df0835fce4 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts.meta new file mode 100644 index 0000000..55fae79 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eaabecde0f91bff469b1d100ebf929f6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs new file mode 100644 index 0000000..0a0c277 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs @@ -0,0 +1,30 @@ +// Cube.cs +using System.Runtime.CompilerServices; +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefabArray +{ + public interface ICube + { + void SetPosition(Vector3 positon); + void Update(); + } + + public class BasicCube : MonoBehaviour + { + protected IRotate m_RotateSystem; + } + + public class Cube : BasicCube, ICube + { + public void SetPosition(Vector3 positon) + { + transform.position = positon; + } + + public void Update() + { + m_RotateSystem.DoRotate(0, 0.25f, 0); + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs.meta new file mode 100644 index 0000000..77b8c4b --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Cube.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a5eea77a48f43648a20cca0f9b1d2b7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs new file mode 100644 index 0000000..8c8a85a --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs @@ -0,0 +1,10 @@ +// IRotate.cs +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefabArray +{ + public interface IRotate + { + void DoRotate(float x, float y, float z); + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs.meta new file mode 100644 index 0000000..16610f6 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/IRotate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 342dc47ef632c7c499acb22e1853c34f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs new file mode 100644 index 0000000..7909da4 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs @@ -0,0 +1,15 @@ +// Rotate.cs +using UnityEngine; + +namespace EasyJection.Samples.BindingPrefabArray +{ + public class Rotate : IRotate + { + private Cube m_Cube; + + public void DoRotate(float x, float y, float z) + { + m_Cube.transform.Rotate(x, y, z); + } + } +} \ No newline at end of file diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs.meta b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs.meta new file mode 100644 index 0000000..1a969ad --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Prefabs/Scripts/Rotate.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 03da5094381816b43b99b1838116b682 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Textures.meta b/UnityPackage/Samples/3_Binding Prefab Array/Textures.meta new file mode 100644 index 0000000..ba36b08 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Textures.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: bdc2d8e677219f2459d810fa94550a0d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png b/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png new file mode 100644 index 0000000..da59b57 Binary files /dev/null and b/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png differ diff --git a/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png.meta b/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png.meta new file mode 100644 index 0000000..8114288 --- /dev/null +++ b/UnityPackage/Samples/3_Binding Prefab Array/Textures/White Square.png.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: a6d404fd3d1ee0549b18fb6c429ca5ab +TextureImporter: + fileIDToRecycleName: {} + externalObjects: {} + serializedVersion: 7 + mipmaps: + mipMapMode: 0 + enableMipMap: 1 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 16 + mipBias: -100 + wrapU: -1 + wrapV: -1 + wrapW: -1 + nPOTScale: 1 + lightmap: 0 + compressionQuality: 50 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 0 + spriteTessellationDetail: -1 + textureType: 0 + textureShape: 1 + singleChannelComponent: 0 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + platformSettings: + - serializedVersion: 2 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + - serializedVersion: 2 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + vertices: [] + indices: + edges: [] + weights: [] + spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/UnityPackage/Tests/Editor/HookingTests.cs b/UnityPackage/Tests/Editor/HookingTests.cs index 778145d..02a353f 100644 --- a/UnityPackage/Tests/Editor/HookingTests.cs +++ b/UnityPackage/Tests/Editor/HookingTests.cs @@ -11,6 +11,20 @@ public class HookingTests { + [Test] + public void TestHook_Array() + { + var container = new Container(); + container.Bind().To(); + container.Bind().ToSelf(UseDefaultConstructor: true); + + var instance = new MockClassArrayField(); + + Assert.AreEqual(10, instance.fieldArray.Length); + + container.Dispose(); + } + [Test] public void TestHook_String() { diff --git a/UnityPackage/Tests/Editor/MockObjects.cs b/UnityPackage/Tests/Editor/MockObjects.cs index b0534ff..fb5fd13 100644 --- a/UnityPackage/Tests/Editor/MockObjects.cs +++ b/UnityPackage/Tests/Editor/MockObjects.cs @@ -151,6 +151,25 @@ public MockClassConstructArgument(IHeirMockInterface instance) } } + /// + /// Basic mock with an array. + /// + public class MockClassArrayField + { + public IMockClassInterface[] fieldArray; + + [MethodImpl(MethodImplOptions.NoInlining)] + public MockClassArrayField() + : this(new IMockClassInterface[10]) + { } + + [MethodImpl(MethodImplOptions.NoInlining)] + private MockClassArrayField(IMockClassInterface[] array) + { + this.fieldArray = array; + } + } + public class HeirMockClassFactory : Types.IFactory { public object CreateInstance(IBindingData bindingData = null) @@ -312,10 +331,10 @@ public int GetNumber_SecondMethod(int number) } } - public class OriginalMethod_3 - { - private string name; - private int number; + public class OriginalMethod_3 + { + private string name; + private int number; public OriginalMethod_3() : this(null, 0) diff --git a/UnityPackage/package.json b/UnityPackage/package.json index 71ed7a0..98bdcbb 100644 --- a/UnityPackage/package.json +++ b/UnityPackage/package.json @@ -1,10 +1,10 @@ { "name": "com.imaxs.easyjection", - "version": "1.0.1", + "version": "1.0.2", "displayName": "EasyJection", "description": "EasyJection is an easy-to-use Dependency Injection (DI) Framework for Unity Engine and beyond.", "documentationUrl": "https://github.com/imaxs/EasyJection/tree/main", - "changelogUrl": "https://github.com/imaxs/EasyJection/blob/main/UnityPackage/CHANGELOG.md", + "changelogUrl": "https://github.com/imaxs/EasyJection/blob/main/CHANGELOG.md", "licensesUrl": "https://github.com/imaxs/EasyJection/blob/main/LICENSE", "license": "Apache-2.0", "keywords": [ @@ -18,5 +18,6 @@ "name": "Max Karepin", "url": "https://www.linkedin.com/in/max-kv/" }, - "type": "library" -} + "type": "library", + "unity": "2020.1" +} \ No newline at end of file