IInstantiator.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. #if !NOT_UNITY3D
  4. using UnityEngine;
  5. #endif
  6. namespace Zenject
  7. {
  8. // You can optionally inject this interface into your classes/factories
  9. // rather than using DiContainer which contains many methods you might not need
  10. public interface IInstantiator
  11. {
  12. // Use this method to create any non-monobehaviour
  13. // Any fields marked [Inject] will be set using the bindings on the container
  14. // Any methods marked with a [Inject] will be called
  15. // Any constructor parameters will be filled in with values from the container
  16. T Instantiate<T>();
  17. T Instantiate<T>(IEnumerable<object> extraArgs);
  18. object Instantiate(Type concreteType);
  19. object Instantiate(Type concreteType, IEnumerable<object> extraArgs);
  20. #if !NOT_UNITY3D
  21. // Add new component to existing game object and fill in its dependencies
  22. // NOTE: Gameobject here is not a prefab prototype, it is an instance
  23. TContract InstantiateComponent<TContract>(GameObject gameObject)
  24. where TContract : Component;
  25. TContract InstantiateComponent<TContract>(
  26. GameObject gameObject, IEnumerable<object> extraArgs)
  27. where TContract : Component;
  28. Component InstantiateComponent(
  29. Type componentType, GameObject gameObject);
  30. Component InstantiateComponent(
  31. Type componentType, GameObject gameObject, IEnumerable<object> extraArgs);
  32. T InstantiateComponentOnNewGameObject<T>()
  33. where T : Component;
  34. T InstantiateComponentOnNewGameObject<T>(string gameObjectName)
  35. where T : Component;
  36. T InstantiateComponentOnNewGameObject<T>(IEnumerable<object> extraArgs)
  37. where T : Component;
  38. T InstantiateComponentOnNewGameObject<T>(string gameObjectName, IEnumerable<object> extraArgs)
  39. where T : Component;
  40. // Create a new game object from a prefab and fill in dependencies for all children
  41. GameObject InstantiatePrefab(UnityEngine.Object prefab);
  42. GameObject InstantiatePrefab(
  43. UnityEngine.Object prefab, Transform parentTransform);
  44. GameObject InstantiatePrefab(
  45. UnityEngine.Object prefab, Vector3 position, Quaternion rotation, Transform parentTransform);
  46. // Create a new game object from a resource path and fill in dependencies for all children
  47. GameObject InstantiatePrefabResource(string resourcePath);
  48. GameObject InstantiatePrefabResource(
  49. string resourcePath, Transform parentTransform);
  50. GameObject InstantiatePrefabResource(
  51. string resourcePath, Vector3 position, Quaternion rotation, Transform parentTransform);
  52. // Same as InstantiatePrefab but returns a component after it's initialized
  53. // and optionally allows extra arguments for the given component type
  54. T InstantiatePrefabForComponent<T>(UnityEngine.Object prefab);
  55. T InstantiatePrefabForComponent<T>(
  56. UnityEngine.Object prefab, IEnumerable<object> extraArgs);
  57. T InstantiatePrefabForComponent<T>(
  58. UnityEngine.Object prefab, Transform parentTransform);
  59. T InstantiatePrefabForComponent<T>(
  60. UnityEngine.Object prefab, Transform parentTransform, IEnumerable<object> extraArgs);
  61. T InstantiatePrefabForComponent<T>(
  62. UnityEngine.Object prefab, Vector3 position, Quaternion rotation, Transform parentTransform);
  63. T InstantiatePrefabForComponent<T>(
  64. UnityEngine.Object prefab, Vector3 position, Quaternion rotation, Transform parentTransform, IEnumerable<object> extraArgs);
  65. object InstantiatePrefabForComponent(
  66. Type concreteType, UnityEngine.Object prefab, Transform parentTransform, IEnumerable<object> extraArgs);
  67. // Same as InstantiatePrefabResource but returns a component after it's initialized
  68. // and optionally allows extra arguments for the given component type
  69. T InstantiatePrefabResourceForComponent<T>(string resourcePath);
  70. T InstantiatePrefabResourceForComponent<T>(
  71. string resourcePath, IEnumerable<object> extraArgs);
  72. T InstantiatePrefabResourceForComponent<T>(
  73. string resourcePath, Transform parentTransform);
  74. T InstantiatePrefabResourceForComponent<T>(
  75. string resourcePath, Transform parentTransform, IEnumerable<object> extraArgs);
  76. T InstantiatePrefabResourceForComponent<T>(
  77. string resourcePath, Vector3 position, Quaternion rotation, Transform parentTransform);
  78. T InstantiatePrefabResourceForComponent<T>(
  79. string resourcePath, Vector3 position, Quaternion rotation, Transform parentTransform, IEnumerable<object> extraArgs);
  80. object InstantiatePrefabResourceForComponent(
  81. Type concreteType, string resourcePath, Transform parentTransform, IEnumerable<object> extraArgs);
  82. T InstantiateScriptableObjectResource<T>(string resourcePath)
  83. where T : ScriptableObject;
  84. T InstantiateScriptableObjectResource<T>(
  85. string resourcePath, IEnumerable<object> extraArgs)
  86. where T : ScriptableObject;
  87. object InstantiateScriptableObjectResource(
  88. Type scriptableObjectType, string resourcePath);
  89. object InstantiateScriptableObjectResource(
  90. Type scriptableObjectType, string resourcePath, IEnumerable<object> extraArgs);
  91. GameObject CreateEmptyGameObject(string name);
  92. #endif
  93. }
  94. }