Ejemplo n.º 1
0
        public bool Remove(ViewType viewType, float delay = 0.0f)
        {
            if (typedViewInstances.ContainsKey(viewType))
            {
                TypedView view = typedViewInstances[viewType];
                typedViewInstances.Remove(viewType);

                if (OpenedStack.Any())
                {
                    CurrentOpen = OpenedStack.Pop();
                }

                if (view && view.gameObject)
                {
                    if (Mathf.Approximately(delay, 0.0f))
                    {
                        view.OnViewRemove();
                        Destroy(view.gameObject);
                        GameEvents.OnViewHided(viewType);
                    }
                    else
                    {
                        StartCoroutine(RemoveImpl(view, delay));
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
 public T FindView <T>(ViewType type) where T : TypedView
 {
     if (typedViewInstances.ContainsKey(type))
     {
         TypedView inst = typedViewInstances[type];
         return(inst as T);
     }
     return(null);
 }
Ejemplo n.º 3
0
 private bool IsModal(ViewType viewType)
 {
     if (typedViewInstances.ContainsKey(viewType))
     {
         TypedView instance = typedViewInstances[viewType];
         if (instance)
         {
             return(instance.IsModal);
         }
     }
     return(false);
 }
Ejemplo n.º 4
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");
                }
            }
        }
Ejemplo n.º 5
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);
        }