Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Feedback Deconstruct method for Vectors

Discussion in 'Experimental Scripting Previews' started by ErnestSurys, Oct 24, 2020.

  1. ErnestSurys

    ErnestSurys

    Joined:
    Jan 18, 2018
    Posts:
    94
    Hi

    Since we can use tuples now can we get deconstruct methods for Vector types?

    MS-Docs

    Code (CSharp):
    1. public static void Deconstruct(this Vector2 v, out float x, out float y) => (x, y) = (v.x,v.y);
    2.  
    3. void UseExample(Vector2 v)
    4. {
    5.     var (min, max) = v;
    6.     // ...
    7. }
    Edit: Tuple serialization would also be nice :)
     
    Last edited: Oct 24, 2020
  2. print_helloworld

    print_helloworld

    Joined:
    Nov 14, 2016
    Posts:
    231
    an implicit operator would be magnificent, and serializing tuples would be sick but we cant even serialize generics like the way everyone would like to, so maybe that one first.
     
  3. ErnestSurys

    ErnestSurys

    Joined:
    Jan 18, 2018
    Posts:
    94
    We can serialize generics since 2020
     
    phobos2077 likes this.
  4. JesseSTG

    JesseSTG

    Joined:
    Jan 10, 2019
    Posts:
    236
    This library of Deconstruct extension methods will do what you need. If not, you can always base your own implementation on it.
     
    JoNax97 likes this.