Translate() public method

public Translate ( float x, float y ) : Matrix2x3,
x float
y float
return Matrix2x3,
Exemplo n.º 1
0
    public Matrix2x3 ViewBoxTransform()
    {
        if (_cachedViewBoxTransform == null)
        {
            Matrix2x3 matrix = new Matrix2x3();

            float x = 0.0f, y = 0.0f, w, h, attrWidth = _width.value, attrHeight = _height.value;

            if (!string.IsNullOrEmpty(_attrList.GetValue("viewBox")))
            {
                Rect r = _viewport;
                x += -r.x;
                y += -r.y;
                w  = r.width;
                h  = r.height;
            }
            else
            {
                w = attrWidth;
                h = attrHeight;
            }

            float x_ratio = attrWidth / w, y_ratio = attrHeight / h;

            matrix = matrix.ScaleNonUniform(x_ratio, y_ratio);
            matrix = matrix.Translate(x, y);
            _cachedViewBoxTransform = matrix;
        }
        return(_cachedViewBoxTransform);
    }
    public void SetCurrentNavType(NavType nav_type)
    {
        CurrentNavType = nav_type;
        AnchorCell     = NavTypeHelper.GetAnchorCell(nav_type, Grid.PosToCell(this));
        NavGrid.NavTypeData    navTypeData = NavGrid.GetNavTypeData(CurrentNavType);
        KBatchedAnimController component   = GetComponent <KBatchedAnimController>();
        Vector2 one = Vector2.one;

        if (navTypeData.flipX)
        {
            one.x = -1f;
        }
        if (navTypeData.flipY)
        {
            one.y = -1f;
        }
        component.navMatrix = Matrix2x3.Translate(navTypeData.animControllerOffset * 200f) * Matrix2x3.Rotate(navTypeData.rotation) * Matrix2x3.Scale(one);
    }
Exemplo n.º 3
0
    public override Matrix2x3 GetTransformMatrix()
    {
        Vector3 v = base.PositionIncludingOffset;

        v.z = 0f;
        Vector2 scale = new Vector2(animScale * animWidth, (0f - animScale) * animHeight);

        if (materialType == KAnimBatchGroup.MaterialType.UI)
        {
            rt = GetComponent <RectTransform>();
            if ((UnityEngine.Object)rootCanvas == (UnityEngine.Object)null)
            {
                rootCanvas = GetRootCanvas();
            }
            if ((UnityEngine.Object)scaler == (UnityEngine.Object)null && (UnityEngine.Object)rootCanvas != (UnityEngine.Object)null)
            {
                scaler = rootCanvas.GetComponent <CanvasScaler>();
            }
            if ((UnityEngine.Object)rootCanvas == (UnityEngine.Object)null)
            {
                screenOffset.x = (float)(Screen.width / 2);
                screenOffset.y = (float)(Screen.height / 2);
            }
            else
            {
                screenOffset.x = rootCanvas.rectTransform().rect.width / 2f;
                screenOffset.y = rootCanvas.rectTransform().rect.height / 2f;
            }
            float d = 1f;
            if ((UnityEngine.Object)scaler != (UnityEngine.Object)null)
            {
                d = 1f / scaler.scaleFactor;
            }
            v = (rt.localToWorldMatrix.MultiplyPoint(rt.pivot) + offset) * d - screenOffset;
            float num  = animWidth * animScale;
            float num2 = animHeight * animScale;
            if (setScaleFromAnim && curAnim != null)
            {
                float   num3 = num;
                Vector2 size = rt.rect.size;
                num = num3 * (size.x / curAnim.unScaledSize.x);
                float   num4  = num2;
                Vector2 size2 = rt.rect.size;
                num2 = num4 * (size2.y / curAnim.unScaledSize.y);
            }
            else
            {
                float   num5  = num;
                Vector2 size3 = rt.rect.size;
                num = num5 * (size3.x / animOverrideSize.x);
                float   num6  = num2;
                Vector2 size4 = rt.rect.size;
                num2 = num6 * (size4.y / animOverrideSize.y);
            }
            Vector3 lossyScale  = rt.lossyScale;
            float   x           = lossyScale.x * num;
            Vector3 lossyScale2 = rt.lossyScale;
            float   y           = (0f - lossyScale2.y) * num2;
            Vector3 lossyScale3 = rt.lossyScale;
            scale = new Vector3(x, y, lossyScale3.z);
            pivot = rt.pivot;
        }
        Matrix2x3 n  = Matrix2x3.Scale(scale);
        Matrix2x3 n2 = Matrix2x3.Scale(new Vector2((!flipX) ? 1f : (-1f), (!flipY) ? 1f : (-1f)));

        if (rotation == 0f)
        {
            Matrix2x3 m = Matrix2x3.TRS(v, base.transform.rotation, base.transform.localScale);
            return(m * n * navMatrix * n2);
        }
        Matrix2x3 n3 = Matrix2x3.Translate(-pivot);
        Matrix2x3 n4 = Matrix2x3.Rotate(rotation * 0.0174532924f);
        Matrix2x3 m2 = Matrix2x3.Translate(pivot);
        Matrix2x3 n5 = m2 * n4 * n3;
        Matrix2x3 m3 = Matrix2x3.TRS(v, base.transform.rotation, base.transform.localScale);

        return(m3 * n5 * n * navMatrix * n2);
    }
Exemplo n.º 4
0
    public Matrix2x3 ViewBoxTransform()
    {
        if(_cachedViewBoxTransform == null) {
          Matrix2x3 matrix = new Matrix2x3();

          float x = 0.0f, y = 0.0f, w, h, attrWidth = _width.value, attrHeight = _height.value;

          if(!string.IsNullOrEmpty(_attrList.GetValue("viewBox"))) {
        Rect r = _viewport;
        x += -r.x;
        y += -r.y;
        w = r.width;
        h = r.height;
          } else {
        w = attrWidth;
        h = attrHeight;
          }

          float x_ratio = attrWidth / w, y_ratio = attrHeight / h;

          matrix = matrix.ScaleNonUniform(x_ratio, y_ratio);
          matrix = matrix.Translate(x, y);
          _cachedViewBoxTransform = matrix;
        }
        return _cachedViewBoxTransform;
    }