Пример #1
0
        private IEnumerator ShowImpl(ViewType viewType, System.Func <bool> whenShow, System.Action <GameObject> onShowed = null, ViewData data = null)
        {
            WaitUntil waitUntil = new WaitUntil(whenShow);

            yield return(waitUntil);

            if (typedViewInstances.ContainsKey(viewType))
            {
                var instance = typedViewInstances[viewType];
                instance.Setup(data);
                if (instance.gameObject)
                {
                    onShowed?.Invoke(instance.gameObject);
                }
            }
            else
            {
                var prefab = typedViewPrefabs.GetPrefab(viewType);
                if (prefab != null)
                {
                    GameObject instance  = GameObject.Instantiate <GameObject>(prefab);
                    TypedView  typedView = instance.GetComponentInChildren <TypedView>();
                    if (typedView != null)
                    {
                        typedViewInstances[viewType] = typedView;
                        instance.transform.SetParent(GetCanvasTransform(typedView.CanvasType), false);
                        if (data != null && data.ViewDepth.HasValue)
                        {
                            typedView.SetViewDepth(data.ViewDepth.Value);
                        }
                        SortByDepth(typedView.CanvasType);
                        typedView.AnimIn();
                        typedView.Setup(data);
                        onShowed?.Invoke(typedView.gameObject);
                        GameEvents.OnViewShowed(viewType);
                    }
                    else
                    {
                        throw new UnityException($"Not found TypedView on view => {viewType}");
                    }
                }
                else
                {
                    throw new UnityException($"Prefab for view type => {viewType} not founded");
                }
            }
        }
Пример #2
0
        public GameObject Show(ViewType viewType, ViewData data = null)
        {
            TypedView typedView = null;

            if (typedViewInstances.ContainsKey(viewType))
            {
                var instance = typedViewInstances[viewType];
                instance.Setup(data);
                typedView = instance;
            }
            else
            {
                var prefab = typedViewPrefabs.GetPrefab(viewType);
                if (prefab != null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(prefab);
                    typedView = instance.GetComponentInChildren <TypedView>();
                    if (typedView != null)
                    {
                        typedViewInstances[viewType] = typedView;
                        instance.transform.SetParent(GetCanvasTransform(typedView.CanvasType), false);
                        if (data != null && data.ViewDepth.HasValue)
                        {
                            typedView.SetViewDepth(data.ViewDepth.Value);
                        }
                        SortByDepth(typedView.CanvasType);
                        typedView.AnimIn();
                        typedView.Setup(data);
                        GameEvents.OnViewShowed(viewType);
                    }
                    else
                    {
                        throw new UnityException($"Not found TypedView on view => {viewType}");
                    }
                }
                else
                {
                    throw new UnityException($"Prefab for view type => {viewType} not founded");
                }
            }

            OpenedStack.Push(CurrentOpen);
            CurrentOpen = viewType;
            return(typedView?.gameObject ?? null);
        }