Exemple #1
0
        public static NativeArray <T> FromRawBytes <T>(byte[] bytes, Allocator allocator) where T : struct
        {
            int structSize = UnsafeUtility.SizeOf <T>();

            UnityEngine.Debug.Assert(bytes.Length % structSize == 0);

            int length = bytes.Length / UnsafeUtility.SizeOf <T>();
            var arr    = new NativeArray <T>(length, allocator);

            arr.CopyFromRawBytes(bytes);
            return(arr);
        }
        static void Arr2Byte <T>(T[] arr) where T : struct
        {
            var arr1  = new NativeArray <T>(arr, Allocator.Temp);
            var bytes = arr1.ToRawBytes();

            Assert.AreEqual(bytes.Length, arr.Length * UnsafeUtility.SizeOf <T>());

            var arr2 = new NativeArray <T>(arr.Length, Allocator.Temp);

            arr2.CopyFromRawBytes(bytes);

            AreDeepEqual(arr1, arr2);
        }
Exemple #3
0
            public override void GetBoundary(
                UnityTrackableId trackableId,
                Allocator allocator,
                ref NativeArray <Vector2> boundary)
            {
                var plane = ARKitReceiver.Instance?.Plane;

                byte[] rawBytes;
                if (plane == null || !plane.meshes.TryGetValue(trackableId, out rawBytes))
                {
                    CreateOrResizeNativeArrayIfNecessary(0, allocator, ref boundary);
                    return;
                }

                int size = rawBytes.Length / UnsafeUtility.SizeOf <Vector2>();

                CreateOrResizeNativeArrayIfNecessary(size, allocator, ref boundary);
                boundary.CopyFromRawBytes(rawBytes);
            }