Search Unity

Cast Rect to Vector4 ?

Discussion in 'Scripting' started by pabsmultiplayer, Jul 31, 2020.

Thread Status:
Not open for further replies.
  1. pabsmultiplayer

    pabsmultiplayer

    Joined:
    Sep 5, 2019
    Posts:
    11
    Is possible to cast Rect values to a vector4 ?
    Im using PackTextures , which is returning Rect but is complaining when i try to cast it

    Code (CSharp):
    1.   _uvs = (Vector4)_packedTexture.PackTextures(textures, 0, _textureResolution);
     
  2. bobisgod234

    bobisgod234

    Joined:
    Nov 15, 2016
    Posts:
    1,042
    There is no implicit way to cast a Rect to a Vector4.

    Store the Rect in a temporary variable, and construct a new Vector4.
     
  3. pabsmultiplayer

    pabsmultiplayer

    Joined:
    Sep 5, 2019
    Posts:
    11
  4. Owen-Reynolds

    Owen-Reynolds

    Joined:
    Feb 15, 2012
    Posts:
    1,997
    The issue, I assume, is there are 2 ways to define a Unity Rect. One is xLow, xHigh, yLow, yHigh; the other is xLow, yLow, width, height. You can use both on the same Rect. A cast couldn't know which one you wanted.
     
    Bunny83 and Joe-Censored like this.
  5. scr_x

    scr_x

    Joined:
    Jul 3, 2023
    Posts:
    1
    Vector4[] rectVectors = new Vector4[rect.Length];
    for (int i = 0; i < rect.Length; i++)
    {
    rectVectors = new Vector4(rect.x, rect.y, rect.width, rect.height);
    }
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,455
Thread Status:
Not open for further replies.