/// <summary>
        /// 切り取ったバイト配列を新規で確保したメモリにコピーし、それを文字列用のポインタとして返す
        /// </summary>
        /// <param name="source">ソース</param>
        /// <param name="start">切り取り開始位置</param>
        /// <param name="length">データの長さ</param>
        /// <param name="allocator">Allocator</param>
        /// <returns>文字列のポインタ</returns>
        StringPtr SliceToStringPtr(NativeArray <byte> source, int start, int length, Allocator allocator)
        {
            var   slice  = new NativeSlice <byte>(source, start, length);
            byte *arrPtr = (byte *)UnsafeUtility.Malloc(length, UnsafeUtility.AlignOf <byte>(), allocator);

            UnsafeUtility.MemClear(arrPtr, length);
            UnsafeUtility.MemCpy(arrPtr, NativeSliceUnsafeUtility.GetUnsafePtr(slice), length);
            return(new StringPtr {
                Data = arrPtr, Length = length
            });
        }
Exemple #2
0
        /// <summary>
        /// Reads a frame of input to the file.
        /// </summary>
        /// <param name="inputs">a frame of input to read.</param>
        public unsafe void ReadInputs(NativeSlice <PlayerInput> inputs)
        {
            Assert.IsTrue(inputs.Length == _config.PlayerCount);
            var   ptr      = (byte *)NativeSliceUnsafeUtility.GetUnsafePtr(inputs);
            int   size     = _config.PlayerCount * UnsafeUtility.SizeOf <PlayerInput>();
            ulong checksum = _reader.ReadULong();

            _reader.ReadBytes(ptr, size);
            ulong hash = XXHash.Hash64(ptr, size);

            Assert.AreEqual(checksum, hash);
        }