Search Unity

ArrayBuffer and Uint32Array issues

Discussion in 'Scripting' started by biggsthecat, Jun 16, 2016.

  1. biggsthecat

    biggsthecat

    Joined:
    Nov 1, 2013
    Posts:
    9
    Hi,

    I've been given a script written in actual Javascript that makes use of ArrayBuffer and Uint32Array. I've managed to convert a good chunk of the script to UnityScript but can't find any way to get Unity to make use of ArrayBuffer or Uint8Array.

    Is there some way I can import a file or dll such as Systems.Data.DataView or similar to get it to work? Or is there a way I can mimic their type? Is there a UnityScript version of these JavaScript types I could use instead?

    Thanks for any help or information.
     
  2. Errorsatz

    Errorsatz

    Joined:
    Aug 8, 2012
    Posts:
    555
    If I'm understanding the documentation correctly, ArrayBuffer is just a block of bytes that can be treated as different types of array by using different views?

    If that's the case, and you're just using it with uint32, then List<uint> should work as a substitute. Or List<byte> if you want 8-bit values.

    If you want the functionality of treating the same memory block as both 32-bit and 8-bit values, that's not something that's encouraged in C#, but you basically want reinterpret_cast, so that's a good term to look for.
    For example: http://stackoverflow.com/questions/479705/reinterpret-cast-in-c-sharp
     
    Last edited: Jun 16, 2016
  3. biggsthecat

    biggsthecat

    Joined:
    Nov 1, 2013
    Posts:
    9
    Thanks for replying Error, I'll give a proper read through the link and see what I can use from it. Definitely got me on the right track though, sound.