/// <summary>
        /// Initializes this UI Frame. Initialization consists of initializing both the Panel and Window layers.
        /// Although literally all the cases I've had to this day were covered by the "Window and Panel" approach,
        /// I made it virtual in case you ever need additional layers or other special initialization.
        /// </summary>
        public virtual void Initialize()
        {
            if (panelLayer == null)
            {
                panelLayer = gameObject.GetComponentInChildren <PanelUILayer>(true);
                if (panelLayer == null)
                {
                    Debug.LogError("[UI Frame] UI Frame lacks Panel Layer!");
                }
                else
                {
                    panelLayer.Initialize();
                }
            }

            if (windowLayer == null)
            {
                windowLayer = gameObject.GetComponentInChildren <WindowUILayer>(true);
                if (panelLayer == null)
                {
                    Debug.LogError("[UI Frame] UI Frame lacks Window Layer!");
                }
                else
                {
                    windowLayer.Initialize();
                    windowLayer.RequestScreenBlock   += OnRequestScreenBlock;
                    windowLayer.RequestScreenUnblock += OnRequestScreenUnblock;
                }
            }

            graphicRaycaster = MainCanvas.GetComponent <GraphicRaycaster>();
        }
Exemplo n.º 2
0
    private void updateUV()
    {
        if (TargetImage.texture == null)
        {
            return;
        }

        //テクスチャサイズ
        float tw = TargetImage.texture.width;
        float th = TargetImage.texture.height;
        //float tw_half = tw * 0.5f;
        float th_half = th * 0.5f;
        //オブジェクト位置
        RectTransform rectObjTrans = GetComponent <RectTransform>();
        Vector2       o_pos        = RectTransformUtility.WorldToScreenPoint(MainCamera, rectObjTrans.position);
        //オブジェクトサイズ
        float ow      = rectObjTrans.sizeDelta.x;
        float oh      = rectObjTrans.sizeDelta.y;
        float ow_half = ow * 0.5f;
        float oh_half = oh * 0.5f;
        //スクリーンサイズ
        float sw = MainCamera.pixelWidth;
        float sh = MainCamera.pixelHeight;
        //float sw_half = sw * 0.5f;
        float sh_half = sh * 0.5f;

        CanvasSetting canvasSetting = MainCanvas.GetComponent <CanvasSetting>();

        if (!canvasSetting.IsHeightReference)
        {
            float rate = DefaultCanvasSizeX / sw;

            o_pos *= rate;

            float   tmp0     = (sh_half * rate) - th_half;
            Vector2 o_pos_lu = new Vector2(o_pos.x - ow_half, o_pos.y - oh_half - tmp0);

            TargetImage.uvRect = new Rect(o_pos_lu.x / tw, o_pos_lu.y / th, ow / tw, oh / th);
        }
        else
        {
            float rate = DefaultCanvasSizeY / sh;

            o_pos *= rate;

            float   tmp0     = (sh_half * rate) - th_half;
            Vector2 o_pos_lu = new Vector2(o_pos.x - ow_half, o_pos.y - oh_half - tmp0);

            TargetImage.uvRect = new Rect((o_pos_lu.x + (canvasSetting.GetAddWidth() * 0.5f)) / tw, o_pos_lu.y / th, ow / tw, oh / th);
        }
#if UNITY_EDITOR
        TargetImage.OnRebuildRequested();
#endif
    }
Exemplo n.º 3
0
 public AnnounceWindow()
 {
     MainCanvas = UnityEngine.Object.Instantiate(Resources.Load("Prefabs/AnnounceWindow") as GameObject).GetComponent <Canvas>();
     raycaster  = MainCanvas.GetComponent <GraphicRaycaster>();
     TryGetControl(out scrollContent, "Content");
     TryGetControl(out input, "TMPName");
     toggles     = new List <Toggle>(50);
     toggleCodes = new Dictionary <Transform, CardData>(50);
     input.onSubmit.AddListener(OnSubmit);
     pdata          = new PointerEventData(MainGame.Instance.EventSystem);
     raycastResults = new List <RaycastResult>();
 }
Exemplo n.º 4
0
        private static void CheckCanvas()
        {
            var scaler = MainCanvas.GetComponent <CanvasScaler>();

            if (scaler != null)
            {
                CanvasSize = scaler.referenceResolution;
            }
            else
            {
                CanvasSize = new Vector2(Screen.width, Screen.height);
            }
        }
Exemplo n.º 5
0
    public Canvas GetCopyOfCanvas(string name = "New Canvas")
    {
        CanvasScaler mainCanvasCaler = MainCanvas.GetComponent <CanvasScaler>();

        GameObject   newCanvasObj    = new GameObject(name, typeof(RectTransform));
        Canvas       newCanvas       = newCanvasObj.AddComponent <Canvas>();
        CanvasScaler newCanvasScaler = newCanvasObj.AddComponent <CanvasScaler>();

        newCanvas.renderMode               = MainCanvas.renderMode;
        newCanvas.sortingOrder             = MainCanvas.sortingOrder;
        newCanvas.pixelPerfect             = MainCanvas.pixelPerfect;
        newCanvas.additionalShaderChannels = MainCanvas.additionalShaderChannels;

        newCanvasScaler.uiScaleMode            = mainCanvasCaler.uiScaleMode;
        newCanvasScaler.referenceResolution    = mainCanvasCaler.referenceResolution;
        newCanvasScaler.screenMatchMode        = mainCanvasCaler.screenMatchMode;
        newCanvasScaler.matchWidthOrHeight     = mainCanvasCaler.matchWidthOrHeight;
        newCanvasScaler.referencePixelsPerUnit = mainCanvasCaler.referencePixelsPerUnit;

        return(newCanvas);
    }
Exemplo n.º 6
0
 public static void AsyncLoad <T>(System.Action loadingDelegate = null, string sceneName = "") where T : UILayer
 {
     MainCanvas.GetComponent <UILayer>().StartCoroutine(LoadingUIEnumerator <T>(loadingDelegate, sceneName));
 }