Exemplo n.º 1
0
        void Cache()
        {
            if (CachedGameObject == null)
            {
                CachedGameObject = this.gameObject;
            }
            if (CachedTransform == null)
            {
                CachedTransform = this.transform;
            }
            if (CachedRectTransform == null)
            {
                CachedRectTransform = CachedGameObject.GetComponent <RectTransform>();
            }

            if (canvas == null)
            {
                canvas = GetComponent <Canvas>();
            }
            if (uiCamera == null)
            {
                uiCamera = FindInChild <Camera>(CachedTransform, "UICamera");
            }
            if (sceneRoot == null)
            {
                sceneRoot = FindInChild <RectTransform>(CachedTransform, "SceneRoot");
            }
            if (windowRoot == null)
            {
                windowRoot = FindInChild <RectTransform>(CachedTransform, "WindowRoot");
            }
            if (popupRoot == null)
            {
                popupRoot = FindInChild <RectTransform>(CachedTransform, "PopupRoot");
            }
            if (otherRoot == null)
            {
                otherRoot = FindInChild <RectTransform>(CachedTransform, "OtherRoot");
            }
            if (maskRoot == null)
            {
                maskRoot = FindInChild <RectTransform>(CachedTransform, "MaskRoot");
            }

            if (fullScreenMask == null)
            {
                fullScreenMask = FindInChild <Image>(CachedTransform, "mask");
            }

            fullScreenMask.gameObject.GetComponent <Button>().onClick.AddListener(OnClickMask);

            // find EventSystem
        }
    public T ForceGet <T>() where T : Component
    {
        Component component;

        if (_cachedExtraComponents.TryGetValue(typeof(T), out component))
        {
            return((T)component);
        }
        else
        {
            component = CachedGameObject.GetComponent <T>();
            if (component == null)
            {
                component = CachedGameObject.AddComponent <T>();
            }
            _cachedExtraComponents.Add(typeof(T), component);
            return((T)component);
        }
    }