コード例 #1
0
ファイル: ViewService.cs プロジェクト: OlegGelezcov/boscs
        public GameObject Show(string name, ViewData data = null)
        {
            NamedView namedView = null;

            if (namedViewInstances.ContainsKey(name))
            {
                var instance = namedViewInstances[name];
                instance.Setup(data);
                namedView = instance;
            }
            else
            {
                var prefab = namedViewPrefabs.GetPrefab(name);
                if (prefab != null)
                {
                    GameObject instance = GameObject.Instantiate <GameObject>(prefab);
                    namedView = instance.GetComponentInChildren <NamedView>();
                    if (namedView != null)
                    {
                        namedViewInstances[name] = namedView;
                        instance.transform.SetParent(GetCanvasTransform(namedView.CanvasType), false);
                        if (data != null && data.ViewDepth.HasValue)
                        {
                            namedView.SetViewDepth(data.ViewDepth.Value);
                        }
                        SortByDepth(namedView.CanvasType);
                        namedView.AnimIn();
                        namedView.Setup(data);
                    }
                    else
                    {
                        throw new UnityException($"Not found NamedView on view => {name}");
                    }
                }
                else
                {
                    throw new UnityException($"Prefab for view name => {name} not founded");
                }
            }
            return(namedView?.gameObject ?? null);
        }
コード例 #2
0
ファイル: ViewService.cs プロジェクト: OlegGelezcov/boscs
 public bool Remove(string name, float delay = 0.0f)
 {
     if (namedViewInstances.ContainsKey(name))
     {
         NamedView view = namedViewInstances[name];
         namedViewInstances.Remove(name);
         if (view && view.gameObject)
         {
             if (Mathf.Approximately(delay, 0.0f))
             {
                 view.OnViewRemove();
                 Destroy(view.gameObject);
             }
             else
             {
                 StartCoroutine(RemoveImpl(view, delay));
             }
             return(true);
         }
     }
     return(false);
 }