Ejemplo n.º 1
0
        public unsafe void LoadSoundClipFromDisk(EntityManager mgr, Entity e, string filePath)
        {
            DynamicBuffer <AudioClipCompressed> audioClipCompressed = mgr.GetBuffer <AudioClipCompressed>(e);

            if (audioClipCompressed.Length > 0)
            {
                return;
            }

#if UNITY_ANDROID
            var op = IOService.RequestAsyncRead(filePath);
            while (op.GetStatus() <= AsyncOp.Status.InProgress)
            {
                ;
            }

            op.GetData(out byte *data, out int sizeInBytes);
            audioClipCompressed.ResizeUninitialized(sizeInBytes);
            byte *audioClipCompressedBytes = (byte *)audioClipCompressed.GetUnsafePtr();
            for (int i = 0; i < sizeInBytes; i++)
            {
                audioClipCompressedBytes[i] = data[i];
            }

            op.Dispose();
#else
            FixedString512          filePathFixedString = new FixedString512(filePath);
            Baselib_ErrorState      errorState          = new Baselib_ErrorState();
            Baselib_FileIO_SyncFile fileHandle          = Baselib_FileIO_SyncOpen(filePathFixedString.GetUnsafePtr(), Baselib_FileIO_OpenFlags.Read, &errorState);
            if (errorState.code != Baselib_ErrorCode.Success)
            {
                return;
            }

            UInt64 fileSize = Baselib_FileIO_SyncGetFileSize(fileHandle, &errorState);
            if (fileSize > Int32.MaxValue)
            {
                Baselib_FileIO_SyncClose(fileHandle, &errorState);
                return;
            }

            audioClipCompressed.ResizeUninitialized((int)fileSize);
            UInt64 bytesRead = Baselib_FileIO_SyncRead(fileHandle, 0, (IntPtr)audioClipCompressed.GetUnsafePtr(), (ulong)audioClipCompressed.Length, &errorState);
            Baselib_FileIO_SyncClose(fileHandle, &errorState);
#endif
        }
Ejemplo n.º 2
0
 public unsafe void Draw(FixedString512 text, Matrix4x4 transform, Color color) => Draw(text.GetUnsafePtr(), text.Length, transform, color);