Esempio n. 1
0
        public static GameObjectFinder CreateFinder(GameObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            GameObjectFinder finder = null;

            if (IsUsingCache)
            {
                int id = obj.GetInstanceID();
                if (!_cacheDict.TryGetValue(id, out finder))
                {
                    finder = new GameObjectFinder(obj);
                    _cacheDict.Add(id, finder);
                }
            }
            else
            {
                finder = new GameObjectFinder(obj);
            }

            return(finder);
        }
Esempio n. 2
0
        private void DetachHost()
        {
            if (_hostObject != null)
            {
                if (_canDestroyHost)
                {
                    GameObjectFinder.DestroyFinder(_objFinder);
                    UnityEngine.Object.Destroy(_hostObject);
                }
                _view       = null;
                _hostObject = null;
                _objFinder  = null;
            }
            else
            {
                // TODO:
                //visible = false;
                if (_behaviour != null)
                {
                    UnityEngine.Object.Destroy(_behaviour);
                    _behaviour = null;
                }
            }

            //UnloadAssets();
        }
Esempio n. 3
0
 public static void DestroyFinder(GameObjectFinder finder)
 {
     if (!IsUsingCache)
     {
         finder.DetachHost();
     }
     else if (finder._hostObject != null)
     {
         int id = finder._hostObject.GetInstanceID();
         finder.DetachHost();
         _cacheDict.Remove(id);
     }
 }
Esempio n. 4
0
        private static void AddUILayer(UILayer layer, ref GameObjectFinder finder, float z)
        {
            var name          = System.Enum.GetName(layer.GetType(), layer);
            var rectTransform = finder.GetComponent <RectTransform>(name);

            if (rectTransform == null)
            {
                Debug.LogErrorFormat("{0} doesn't exist.", layer);
                return;
            }
            FitScreen(rectTransform);
            _layers[layer] = rectTransform;
            rectTransform.anchoredPosition3D = new Vector3(0f, 0f, z);
        }
Esempio n. 5
0
        protected void AttachHost(GameObject host, bool beClone = true, bool canDestroyHost = true)
        {
            if (_destroyed)
            {
                return;
            }

            _canDestroyHost = canDestroyHost;

            bool isFirstCreated = _hostObject == null;

            if (isFirstCreated)
            {
                _hostObject = beClone ? UnityEngine.Object.Instantiate(host) : host;
                _view       = _hostObject.transform;
                _objFinder  = GameObjectFinder.CreateFinder(_hostObject);
            }

            if (_behaviour == null)
            {
                _behaviour      = _hostObject.AddComponent <ViewBehaviour>();
                _behaviour.View = this;
                //_behaviour.enabled = enabled;
            }
            else if (!_behaviour.enabled)
            {
                _behaviour.enabled = true;
            }

            UpdateParent();

            // TODO:
            ////场景激活后才能够打开托管类型view
            //if (Main.currentScene != null && !(this is IRender)) {
            //    if (_visible && destroyType != ViewInstanceType.MANUAL_DISPOSE && Main.currentScene.statu < SceneProcessStatu.CREATIONCOMPLETE) {
            //        Main.currentScene.AddActiveView(this);
            //    }
            //}

            if (isFirstCreated)
            {
                OnAttachHost();
            }

            _hostObject.SetActive(false);

            ShowView();
        }
Esempio n. 6
0
        public static void Init()
        {
            if (_uiRoot != null)
            {
                return;
            }

            _uiRoot = GameObject.Find("GameApp/UIRoot");

            GameObjectFinder finder = GameObjectFinder.CreateFinder(_uiRoot);

            #region Camera
            _uiCamera = finder.GetComponent <Camera>("UICamera");
            if (_uiCamera != null)
            {
                _uiCamera.clearFlags              = CameraClearFlags.Depth;
                _uiCamera.farClipPlane            = 10000;
                _uiCamera.transform.localPosition = new Vector3(0f, 0f, -50000);
            }
            #endregion

            #region EventSystem
            _eventSystem = finder.GetComponent <EventSystem>("EventSystem");
            if (_eventSystem != null)
            {
            }
            #endregion

            #region Layer
            AddUILayer(UILayer.BaseLayer, ref finder, 0f);
            AddUILayer(UILayer.WindowLayer, ref finder, -10000f);
            AddUILayer(UILayer.TopLayer, ref finder, -20000f);
            AddUILayer(UILayer.ModalLayer, ref finder, -30000f);
            AddUILayer(UILayer.SystemLayer, ref finder, -40000f);
            #endregion
        }