コード例 #1
0
ファイル: MenuPartsBase.cs プロジェクト: mliuzailin/GitGame
    /// <summary>
    /// Pivotが中央でないとうまく調整されない
    /// </summary>
    /// <param name="_pos">Anchored Position</param>
    /// <param name="_size">Size Delta</param>
    public void SetPositionAjustStatusBar(Vector2 _pos, Vector2 _size)
    {
        RectTransform trans = GetComponent <RectTransform>();

        if (trans == null)
        {
            return;
        }

        float bar_height         = 0.0f;
        float bar_height_half    = 0.0f;
        float bottom_height      = 0.0f;
        float bottom_height_half = 0.0f;

        if (SafeAreaControl.HasInstance)
        {
            float bottom_space_height = SafeAreaControl.Instance.bottom_space_height;
            bar_height         = (float)(SafeAreaControl.Instance.bar_height * -1);
            bar_height_half    = bar_height * 0.5f;
            bottom_height      = (float)(bottom_space_height * -1);
            bottom_height_half = bottom_height * 0.5f;
        }

        if (trans.pivot.x == 1.0f &&
            trans.pivot.y == 1.0f)
        {
            CanvasSetting _setting = GetComponentInParent <CanvasSetting>();
            if (_setting != null)
            {
                trans.anchoredPosition = new Vector2(_pos.x + _setting.GetAddWidth() / 2.0f, _pos.y + bar_height);
                trans.sizeDelta        = new Vector2(_size.x + _setting.GetAddWidth(), _size.y + bar_height + bottom_height);
            }
            else
            {
                trans.anchoredPosition = new Vector2(_pos.x, _pos.y + bar_height);
                trans.sizeDelta        = new Vector2(_size.x, _size.y + bar_height + bottom_height);
            }
        }
        else
        {
            trans.anchoredPosition = new Vector2(_pos.x, _pos.y + bar_height_half - bottom_height_half);

            CanvasSetting _setting = GetComponentInParent <CanvasSetting>();
            if (_setting != null)
            {
                trans.sizeDelta = new Vector2(_size.x + _setting.GetAddWidth(), _size.y + bar_height + bottom_height);
            }
            else
            {
                trans.sizeDelta = new Vector2(_size.x, _size.y + bar_height + bottom_height);
            }
        }
    }
コード例 #2
0
ファイル: AutoUVSetting.cs プロジェクト: mliuzailin/GitGame
    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
    }
コード例 #3
0
ファイル: MenuPartsBase.cs プロジェクト: mliuzailin/GitGame
    public void SetSizeParfect(Vector2 _size)
    {
        RectTransform trans = GetComponent <RectTransform>();

        if (trans == null)
        {
            return;
        }
        CanvasSetting _setting = GetComponentInParent <CanvasSetting>();

        if (_setting != null)
        {
            trans.sizeDelta = new Vector2(_size.x + _setting.GetAddWidth(), _size.y);
        }
        else
        {
            trans.sizeDelta = new Vector2(_size.x, _size.y);
        }
    }
コード例 #4
0
ファイル: MenuPartsBase.cs プロジェクト: mliuzailin/GitGame
    public void SetPosition(Vector2 _pos, Vector2 _size, bool Ignore = false)
    {
        RectTransform trans = GetComponent <RectTransform>();

        if (trans == null)
        {
            return;
        }
        trans.anchoredPosition = new Vector2(_pos.x, _pos.y);

        CanvasSetting _setting = GetComponentInParent <CanvasSetting>();

        if (_setting != null &&
            Ignore == false)
        {
            trans.sizeDelta = new Vector2(_size.x + _setting.GetAddWidth(), _size.y);
        }
        else
        {
            trans.sizeDelta = new Vector2(_size.x, _size.y);
        }
    }