Exemplo n.º 1
0
        /// <summary>
        /// Binds a view controller to the container.
        /// </summary>
        /// <param name="binder">The binder.</param>
        /// <param name="onInstantiated">The callback when the view controller is instantiated.</param>
        /// <returns></returns>
        public static ScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentAsViewController(this FromBinder binder, Action <InjectContext, object> onInstantiated = null)
        {
            var go = new GameObject("ViewController");

            go.gameObject.SetActive(false);
            var raycaster        = go.AddComponent <CanvasContainer.DummyRaycaster>();
            var componentBinding = binder.FromNewComponentOn(go);

            raycaster.enabled = false;

            componentBinding.OnInstantiated((ctx, obj) =>
            {
                if (obj is ViewController vc)
                {
                    var cc = ctx.Container.Resolve <CanvasContainer>();
                    Clone(vc.gameObject, cc.CurvedCanvasTemplate);

                    var newRaycaster = go.AddComponent <VRGraphicRaycaster>();
                    UnityEngine.Object.Destroy(raycaster);

                    var cache = ctx.Container.Resolve <PhysicsRaycasterWithCache>();
                    newRaycaster.SetField("_physicsRaycaster", cache);

                    go.name = vc.GetType().Name;
                    vc.rectTransform.anchorMin        = new Vector2(0f, 0f);
                    vc.rectTransform.anchorMax        = new Vector2(1f, 1f);
                    vc.rectTransform.sizeDelta        = new Vector2(0f, 0f);
                    vc.rectTransform.anchoredPosition = new Vector2(0f, 0f);
                }
                onInstantiated?.Invoke(ctx, obj);
            });
            return(componentBinding);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new component on a new GameObject
 /// </summary>
 /// <param name="binder">The preceding binder.</param>
 /// <param name="name">The name of the GameObject.</param>
 /// <returns></returns>
 public static ScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOnNewGameObject(this FromBinder binder, string name = "GameObject")
 {
     if (name == nameof(GameObject))
     {
         name = binder.BindInfo.ToTypes.FirstOrDefault()?.Name ?? nameof(GameObject);
     }
     return(binder.FromNewComponentOn(new GameObject(name)));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates a new component on a new GameObject
 /// </summary>
 /// <param name="binder">The preceding binder.</param>
 /// <param name="name">The name of the GameObject.</param>
 /// <returns></returns>
 public static ScopeConcreteIdArgConditionCopyNonLazyBinder FromNewComponentOnNewGameObject(this FromBinder binder, string name = "GameObject")
 {
     return(binder.FromNewComponentOn(new GameObject(name)));
 }