├── Assets ├── Scenes.meta ├── Scenes │ ├── SampleScene.unity │ └── SampleScene.unity.meta ├── Scripts.meta └── Scripts │ ├── BinkPlayer.cs │ └── BinkPlayer.cs.meta ├── LICENSE └── README.md /Assets/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0b0a0d2f1f42b3d4e846ef79d3d9f20e 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scenes/SampleScene.unity: -------------------------------------------------------------------------------- 1 | %YAML 1.1 2 | %TAG !u! tag:unity3d.com,2011: 3 | --- !u!29 &1 4 | OcclusionCullingSettings: 5 | m_ObjectHideFlags: 0 6 | serializedVersion: 2 7 | m_OcclusionBakeSettings: 8 | smallestOccluder: 5 9 | smallestHole: 0.25 10 | backfaceThreshold: 100 11 | m_SceneGUID: 00000000000000000000000000000000 12 | m_OcclusionCullingData: {fileID: 0} 13 | --- !u!104 &2 14 | RenderSettings: 15 | m_ObjectHideFlags: 0 16 | serializedVersion: 9 17 | m_Fog: 0 18 | m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} 19 | m_FogMode: 3 20 | m_FogDensity: 0.01 21 | m_LinearFogStart: 0 22 | m_LinearFogEnd: 300 23 | m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} 24 | m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} 25 | m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} 26 | m_AmbientIntensity: 1 27 | m_AmbientMode: 3 28 | m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} 29 | m_SkyboxMaterial: {fileID: 0} 30 | m_HaloStrength: 0.5 31 | m_FlareStrength: 1 32 | m_FlareFadeSpeed: 3 33 | m_HaloTexture: {fileID: 0} 34 | m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} 35 | m_DefaultReflectionMode: 0 36 | m_DefaultReflectionResolution: 128 37 | m_ReflectionBounces: 1 38 | m_ReflectionIntensity: 1 39 | m_CustomReflection: {fileID: 0} 40 | m_Sun: {fileID: 0} 41 | m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} 42 | m_UseRadianceAmbientProbe: 0 43 | --- !u!157 &3 44 | LightmapSettings: 45 | m_ObjectHideFlags: 0 46 | serializedVersion: 11 47 | m_GIWorkflowMode: 1 48 | m_GISettings: 49 | serializedVersion: 2 50 | m_BounceScale: 1 51 | m_IndirectOutputScale: 1 52 | m_AlbedoBoost: 1 53 | m_EnvironmentLightingMode: 0 54 | m_EnableBakedLightmaps: 0 55 | m_EnableRealtimeLightmaps: 0 56 | m_LightmapEditorSettings: 57 | serializedVersion: 12 58 | m_Resolution: 2 59 | m_BakeResolution: 40 60 | m_AtlasSize: 1024 61 | m_AO: 0 62 | m_AOMaxDistance: 1 63 | m_CompAOExponent: 1 64 | m_CompAOExponentDirect: 0 65 | m_ExtractAmbientOcclusion: 0 66 | m_Padding: 2 67 | m_LightmapParameters: {fileID: 0} 68 | m_LightmapsBakeMode: 1 69 | m_TextureCompression: 1 70 | m_FinalGather: 0 71 | m_FinalGatherFiltering: 1 72 | m_FinalGatherRayCount: 256 73 | m_ReflectionCompression: 2 74 | m_MixedBakeMode: 2 75 | m_BakeBackend: 0 76 | m_PVRSampling: 1 77 | m_PVRDirectSampleCount: 32 78 | m_PVRSampleCount: 500 79 | m_PVRBounces: 2 80 | m_PVREnvironmentSampleCount: 500 81 | m_PVREnvironmentReferencePointCount: 2048 82 | m_PVRFilteringMode: 2 83 | m_PVRDenoiserTypeDirect: 0 84 | m_PVRDenoiserTypeIndirect: 0 85 | m_PVRDenoiserTypeAO: 0 86 | m_PVRFilterTypeDirect: 0 87 | m_PVRFilterTypeIndirect: 0 88 | m_PVRFilterTypeAO: 0 89 | m_PVREnvironmentMIS: 0 90 | m_PVRCulling: 1 91 | m_PVRFilteringGaussRadiusDirect: 1 92 | m_PVRFilteringGaussRadiusIndirect: 5 93 | m_PVRFilteringGaussRadiusAO: 2 94 | m_PVRFilteringAtrousPositionSigmaDirect: 0.5 95 | m_PVRFilteringAtrousPositionSigmaIndirect: 2 96 | m_PVRFilteringAtrousPositionSigmaAO: 1 97 | m_ExportTrainingData: 0 98 | m_TrainingDataDestination: TrainingData 99 | m_LightProbeSampleCountMultiplier: 4 100 | m_LightingDataAsset: {fileID: 0} 101 | m_UseShadowmask: 1 102 | --- !u!196 &4 103 | NavMeshSettings: 104 | serializedVersion: 2 105 | m_ObjectHideFlags: 0 106 | m_BuildSettings: 107 | serializedVersion: 2 108 | agentTypeID: 0 109 | agentRadius: 0.5 110 | agentHeight: 2 111 | agentSlope: 45 112 | agentClimb: 0.4 113 | ledgeDropHeight: 0 114 | maxJumpAcrossDistance: 0 115 | minRegionArea: 2 116 | manualCellSize: 0 117 | cellSize: 0.16666667 118 | manualTileSize: 0 119 | tileSize: 256 120 | accuratePlacement: 0 121 | debug: 122 | m_Flags: 0 123 | m_NavMeshData: {fileID: 0} 124 | --- !u!1 &110728280 125 | GameObject: 126 | m_ObjectHideFlags: 0 127 | m_CorrespondingSourceObject: {fileID: 0} 128 | m_PrefabInstance: {fileID: 0} 129 | m_PrefabAsset: {fileID: 0} 130 | serializedVersion: 6 131 | m_Component: 132 | - component: {fileID: 110728282} 133 | - component: {fileID: 110728281} 134 | - component: {fileID: 110728283} 135 | m_Layer: 0 136 | m_Name: GameObject (1) 137 | m_TagString: Untagged 138 | m_Icon: {fileID: 0} 139 | m_NavMeshLayer: 0 140 | m_StaticEditorFlags: 0 141 | m_IsActive: 0 142 | --- !u!114 &110728281 143 | MonoBehaviour: 144 | m_ObjectHideFlags: 0 145 | m_CorrespondingSourceObject: {fileID: 0} 146 | m_PrefabInstance: {fileID: 0} 147 | m_PrefabAsset: {fileID: 0} 148 | m_GameObject: {fileID: 110728280} 149 | m_Enabled: 1 150 | m_EditorHideFlags: 0 151 | m_Script: {fileID: 11500000, guid: 87ffce2fdffa4a24c854a589a9ccd291, type: 3} 152 | m_Name: 153 | m_EditorClassIdentifier: 154 | --- !u!4 &110728282 155 | Transform: 156 | m_ObjectHideFlags: 0 157 | m_CorrespondingSourceObject: {fileID: 0} 158 | m_PrefabInstance: {fileID: 0} 159 | m_PrefabAsset: {fileID: 0} 160 | m_GameObject: {fileID: 110728280} 161 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 162 | m_LocalPosition: {x: 0, y: 0, z: 0} 163 | m_LocalScale: {x: 100, y: 100, z: 1} 164 | m_Children: [] 165 | m_Father: {fileID: 0} 166 | m_RootOrder: 2 167 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 168 | --- !u!212 &110728283 169 | SpriteRenderer: 170 | m_ObjectHideFlags: 0 171 | m_CorrespondingSourceObject: {fileID: 0} 172 | m_PrefabInstance: {fileID: 0} 173 | m_PrefabAsset: {fileID: 0} 174 | m_GameObject: {fileID: 110728280} 175 | m_Enabled: 1 176 | m_CastShadows: 0 177 | m_ReceiveShadows: 0 178 | m_DynamicOccludee: 1 179 | m_MotionVectors: 1 180 | m_LightProbeUsage: 1 181 | m_ReflectionProbeUsage: 1 182 | m_RayTracingMode: 0 183 | m_RenderingLayerMask: 1 184 | m_RendererPriority: 0 185 | m_Materials: 186 | - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} 187 | m_StaticBatchInfo: 188 | firstSubMesh: 0 189 | subMeshCount: 0 190 | m_StaticBatchRoot: {fileID: 0} 191 | m_ProbeAnchor: {fileID: 0} 192 | m_LightProbeVolumeOverride: {fileID: 0} 193 | m_ScaleInLightmap: 1 194 | m_ReceiveGI: 1 195 | m_PreserveUVs: 0 196 | m_IgnoreNormalsForChartDetection: 0 197 | m_ImportantGI: 0 198 | m_StitchLightmapSeams: 1 199 | m_SelectedEditorRenderState: 0 200 | m_MinimumChartSize: 4 201 | m_AutoUVMaxDistance: 0.5 202 | m_AutoUVMaxAngle: 89 203 | m_LightmapParameters: {fileID: 0} 204 | m_SortingLayerID: 0 205 | m_SortingLayer: 0 206 | m_SortingOrder: 0 207 | m_Sprite: {fileID: 0} 208 | m_Color: {r: 1, g: 1, b: 1, a: 1} 209 | m_FlipX: 0 210 | m_FlipY: 0 211 | m_DrawMode: 0 212 | m_Size: {x: 1, y: 1} 213 | m_AdaptiveModeThreshold: 0.5 214 | m_SpriteTileMode: 0 215 | m_WasSpriteAssigned: 0 216 | m_MaskInteraction: 0 217 | m_SpriteSortPoint: 0 218 | --- !u!1 &519420028 219 | GameObject: 220 | m_ObjectHideFlags: 0 221 | m_CorrespondingSourceObject: {fileID: 0} 222 | m_PrefabInstance: {fileID: 0} 223 | m_PrefabAsset: {fileID: 0} 224 | serializedVersion: 6 225 | m_Component: 226 | - component: {fileID: 519420032} 227 | - component: {fileID: 519420031} 228 | - component: {fileID: 519420029} 229 | m_Layer: 0 230 | m_Name: Main Camera 231 | m_TagString: MainCamera 232 | m_Icon: {fileID: 0} 233 | m_NavMeshLayer: 0 234 | m_StaticEditorFlags: 0 235 | m_IsActive: 1 236 | --- !u!81 &519420029 237 | AudioListener: 238 | m_ObjectHideFlags: 0 239 | m_CorrespondingSourceObject: {fileID: 0} 240 | m_PrefabInstance: {fileID: 0} 241 | m_PrefabAsset: {fileID: 0} 242 | m_GameObject: {fileID: 519420028} 243 | m_Enabled: 1 244 | --- !u!20 &519420031 245 | Camera: 246 | m_ObjectHideFlags: 0 247 | m_CorrespondingSourceObject: {fileID: 0} 248 | m_PrefabInstance: {fileID: 0} 249 | m_PrefabAsset: {fileID: 0} 250 | m_GameObject: {fileID: 519420028} 251 | m_Enabled: 1 252 | serializedVersion: 2 253 | m_ClearFlags: 2 254 | m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} 255 | m_projectionMatrixMode: 1 256 | m_GateFitMode: 2 257 | m_FOVAxisMode: 0 258 | m_SensorSize: {x: 36, y: 24} 259 | m_LensShift: {x: 0, y: 0} 260 | m_FocalLength: 50 261 | m_NormalizedViewPortRect: 262 | serializedVersion: 2 263 | x: 0 264 | y: 0 265 | width: 1 266 | height: 1 267 | near clip plane: 0.3 268 | far clip plane: 1000 269 | field of view: 60 270 | orthographic: 1 271 | orthographic size: 5 272 | m_Depth: -1 273 | m_CullingMask: 274 | serializedVersion: 2 275 | m_Bits: 4294967295 276 | m_RenderingPath: -1 277 | m_TargetTexture: {fileID: 0} 278 | m_TargetDisplay: 0 279 | m_TargetEye: 0 280 | m_HDR: 1 281 | m_AllowMSAA: 0 282 | m_AllowDynamicResolution: 0 283 | m_ForceIntoRT: 0 284 | m_OcclusionCulling: 0 285 | m_StereoConvergence: 10 286 | m_StereoSeparation: 0.022 287 | --- !u!4 &519420032 288 | Transform: 289 | m_ObjectHideFlags: 0 290 | m_CorrespondingSourceObject: {fileID: 0} 291 | m_PrefabInstance: {fileID: 0} 292 | m_PrefabAsset: {fileID: 0} 293 | m_GameObject: {fileID: 519420028} 294 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 295 | m_LocalPosition: {x: 0, y: 0, z: -10} 296 | m_LocalScale: {x: 1, y: 1, z: 1} 297 | m_Children: [] 298 | m_Father: {fileID: 0} 299 | m_RootOrder: 0 300 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 301 | --- !u!1 &1450604232 302 | GameObject: 303 | m_ObjectHideFlags: 0 304 | m_CorrespondingSourceObject: {fileID: 0} 305 | m_PrefabInstance: {fileID: 0} 306 | m_PrefabAsset: {fileID: 0} 307 | serializedVersion: 6 308 | m_Component: 309 | - component: {fileID: 1450604236} 310 | - component: {fileID: 1450604233} 311 | - component: {fileID: 1450604234} 312 | m_Layer: 0 313 | m_Name: GameObject 314 | m_TagString: Untagged 315 | m_Icon: {fileID: 0} 316 | m_NavMeshLayer: 0 317 | m_StaticEditorFlags: 0 318 | m_IsActive: 1 319 | --- !u!114 &1450604233 320 | MonoBehaviour: 321 | m_ObjectHideFlags: 0 322 | m_CorrespondingSourceObject: {fileID: 0} 323 | m_PrefabInstance: {fileID: 0} 324 | m_PrefabAsset: {fileID: 0} 325 | m_GameObject: {fileID: 1450604232} 326 | m_Enabled: 1 327 | m_EditorHideFlags: 0 328 | m_Script: {fileID: 11500000, guid: e2b90ac5bccb99b4d9efc71ef1a26936, type: 3} 329 | m_Name: 330 | m_EditorClassIdentifier: 331 | --- !u!212 &1450604234 332 | SpriteRenderer: 333 | m_ObjectHideFlags: 0 334 | m_CorrespondingSourceObject: {fileID: 0} 335 | m_PrefabInstance: {fileID: 0} 336 | m_PrefabAsset: {fileID: 0} 337 | m_GameObject: {fileID: 1450604232} 338 | m_Enabled: 1 339 | m_CastShadows: 0 340 | m_ReceiveShadows: 0 341 | m_DynamicOccludee: 1 342 | m_MotionVectors: 1 343 | m_LightProbeUsage: 1 344 | m_ReflectionProbeUsage: 1 345 | m_RayTracingMode: 0 346 | m_RenderingLayerMask: 1 347 | m_RendererPriority: 0 348 | m_Materials: 349 | - {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0} 350 | m_StaticBatchInfo: 351 | firstSubMesh: 0 352 | subMeshCount: 0 353 | m_StaticBatchRoot: {fileID: 0} 354 | m_ProbeAnchor: {fileID: 0} 355 | m_LightProbeVolumeOverride: {fileID: 0} 356 | m_ScaleInLightmap: 1 357 | m_ReceiveGI: 1 358 | m_PreserveUVs: 0 359 | m_IgnoreNormalsForChartDetection: 0 360 | m_ImportantGI: 0 361 | m_StitchLightmapSeams: 1 362 | m_SelectedEditorRenderState: 0 363 | m_MinimumChartSize: 4 364 | m_AutoUVMaxDistance: 0.5 365 | m_AutoUVMaxAngle: 89 366 | m_LightmapParameters: {fileID: 0} 367 | m_SortingLayerID: 0 368 | m_SortingLayer: 0 369 | m_SortingOrder: 0 370 | m_Sprite: {fileID: 0} 371 | m_Color: {r: 1, g: 1, b: 1, a: 1} 372 | m_FlipX: 0 373 | m_FlipY: 0 374 | m_DrawMode: 0 375 | m_Size: {x: 1, y: 1} 376 | m_AdaptiveModeThreshold: 0.5 377 | m_SpriteTileMode: 0 378 | m_WasSpriteAssigned: 0 379 | m_MaskInteraction: 0 380 | m_SpriteSortPoint: 0 381 | --- !u!224 &1450604236 382 | RectTransform: 383 | m_ObjectHideFlags: 0 384 | m_CorrespondingSourceObject: {fileID: 0} 385 | m_PrefabInstance: {fileID: 0} 386 | m_PrefabAsset: {fileID: 0} 387 | m_GameObject: {fileID: 1450604232} 388 | m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} 389 | m_LocalPosition: {x: 0, y: 0, z: 0} 390 | m_LocalScale: {x: 1, y: 1, z: 1} 391 | m_Children: [] 392 | m_Father: {fileID: 0} 393 | m_RootOrder: 1 394 | m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} 395 | m_AnchorMin: {x: 0.5, y: 0.5} 396 | m_AnchorMax: {x: 0.5, y: 0.5} 397 | m_AnchoredPosition: {x: 0, y: 0} 398 | m_SizeDelta: {x: 100, y: 100} 399 | m_Pivot: {x: 0.5, y: 0.5} 400 | -------------------------------------------------------------------------------- /Assets/Scenes/SampleScene.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2cda990e2423bbf4892e6590ba056729 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8af222921ed86bd45888a6b9ba519818 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts/BinkPlayer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Runtime.InteropServices; 6 | using UnityEngine; 7 | using UnityEngine.UI; 8 | 9 | public class BinkPlayer : MonoBehaviour 10 | { 11 | 12 | internal static class BinkNativeMethods 13 | { 14 | //======================================================================= 15 | 16 | public const ulong BINKOLDFRAMEFORMAT = 0x00008000L; // using the old Bink frame format (internal use only) 17 | public const ulong BINKCUSTOMCOLORSPACE = 0x00010000L; // file contains a custom colorspace matrix (only internal now) 18 | 19 | public const ulong BINKNOYPLANE = 0x00000200L; // Don't decompress the Y plane (internal flag) 20 | public const ulong BINKWILLLOOP = 0x00000080L; // You are planning to loop this Bink. 21 | 22 | public const ulong BINKYCRCBNEW = 0x00000010L; // File uses the new ycrcb colorspace (usually Bink 2) 23 | public const ulong BINKHDR = 0x00000004L; // Video is an HDR video 24 | public const ulong BINK_SLICES_2 = 0x00000000L; // Bink 2 file has two slices 25 | public const ulong BINK_SLICES_3 = 0x00000001L; // Bink 2 file has three slices 26 | public const ulong BINK_SLICES_4 = 0x00000002L; // Bink 2 file has four slices 27 | public const ulong BINK_SLICES_8 = 0x00000003L; // Bink 2 file has eight slices 28 | public const ulong BINK_SLICES_MASK = 0x00000003L; // mask against openflags to get the slice flags 29 | 30 | [DllImport("bink2w64")] 31 | internal static extern void BinkClose(IntPtr Bink); 32 | 33 | [DllImport("bink2w64")] 34 | internal static extern IntPtr BinkOpen(string name, BINK_OPEN_FLAGS flags); 35 | 36 | [DllImport("bink2w64")] 37 | internal static extern string BinkGetError(); 38 | 39 | [DllImport("bink2w64")] 40 | internal static extern IntPtr BinkDoFrame(IntPtr Bink); 41 | 42 | [DllImport("bink2w64")] 43 | internal static extern int BinkWait(IntPtr bink); 44 | 45 | [DllImport("bink2w64")] 46 | internal static extern void BinkNextFrame(IntPtr bink); 47 | 48 | [DllImport("bink2w64")] 49 | internal static extern int BinkCopyToBuffer(IntPtr bink, byte[] dest_addr, int dest_pitch, uint dest_height, uint dest_x, uint dest_y, BINK_COPY_FLAGS copy_flags); 50 | 51 | public struct BINK 52 | { 53 | public int Width; 54 | public int Height; 55 | public uint Frames; 56 | public uint FrameNum; 57 | public uint FrameRate; 58 | public uint FrameRateDiv; 59 | public uint ReadError; 60 | public BINK_OPEN_FLAGS OpenFlags; 61 | public BINKRECT FrameRects; 62 | public uint NumRects; 63 | public uint FrameChangePercent; 64 | }; 65 | 66 | public struct BINKRECT 67 | { 68 | public int Left; 69 | public int Top; 70 | public int Width; 71 | public int Height; 72 | }; 73 | 74 | public enum BINK_OPEN_FLAGS : ulong 75 | { 76 | BINKFILEOFFSET = 0x00000020L, // Use file offset specified by BinkSetFileOffset 77 | BINKFILEHANDLE = 0x00800000L, // Use when passing in a file handle 78 | BINKFROMMEMORY = 0x04000000L, // Use when passing in a pointer to the file 79 | BINKNOFRAMEBUFFERS = 0x00000400L, // Don't allocate internal frame buffers - application must call BinkRegisterFrameBuffers 80 | BINKUSETRIPLEBUFFERING = 0x00000008L, // Use triple buffering in the framebuffers 81 | BINKSNDTRACK = 0x00004000L, // Set the track number to play 82 | BINKDONTCLOSETHREADS = 0x00000040L, // Don't close threads on BinkClose (call BinkFreeGlobals to close threads) 83 | BINKGPU = 0x00000100L, // Open Bink in GPU mode 84 | BINKNOSKIP = 0x00080000L, // Don't skip frames if falling behind 85 | BINKPRELOADALL = 0x00002000L, // Preload the entire animation 86 | BINKALPHA = 0x00100000L, // Decompress alpha plane (if present) 87 | BINKGRAYSCALE = 0x00020000L, // Force Bink to use grayscale 88 | BINKFRAMERATE = 0x00001000L, // Override fr (call BinkFrameRate first) 89 | BINKSIMULATE = 0x00400000L, // Simulate the speed (call BinkSim first) 90 | BINKIOSIZE = 0x01000000L, // Set an io size (call BinkIOSize first) 91 | BINKNOFILLIOBUF = 0x00200000L, // Don't Fill the IO buffer (in BinkOpen and BinkCopyTo) 92 | BINKIOPROCESSOR = 0x02000000L, // Set an io processor (call BinkIO first) 93 | BINKNOTHREADEDIO = 0x08000000L // Don't use a background thread for IO 94 | } 95 | 96 | public enum BINK_COPY_FLAGS : ulong 97 | { 98 | BINKSURFACE32BGRx = 3, 99 | BINKSURFACE32RGBx = 4, 100 | BINKSURFACE32BGRA = 5, 101 | BINKSURFACE32RGBA = 6, 102 | BINKSURFACE5551 = 8, 103 | BINKSURFACE555 = 9, 104 | BINKSURFACE565 = 10, 105 | BINKSURFACE32ARGB = 12, 106 | BINKSURFACEMASK = 15, 107 | BINKGRAYSCALE = 0x00020000L, // Force Bink to use grayscale 108 | BINKNOSKIP = 0x00080000L, // Don't skip frames if falling behind 109 | BINKYAINVERT = 0x00000800L // Reverse Y and A planes when blitting (for debugging) 110 | } 111 | } 112 | 113 | string BinkAnimation = "topper.bk2"; 114 | BinkNativeMethods.BINK bk; 115 | Texture2D texture; 116 | IntPtr bink; 117 | byte[] buffer; 118 | // Start is called before the first frame update 119 | void Start() 120 | { 121 | bink = BinkNativeMethods.BinkOpen(BinkAnimation, 0); 122 | 123 | bk = Marshal.PtrToStructure(bink); 124 | 125 | texture = new Texture2D(bk.Width, bk.Height, TextureFormat.RGBA32, false); 126 | var renderer = GetComponent(); 127 | renderer.sprite = Sprite.Create(texture, new Rect(0, 0, bk.Width, bk.Height), Vector2.zero); 128 | buffer = new byte[bk.Width * 4 * bk.Height]; 129 | } 130 | 131 | private void Update() 132 | { 133 | if (bink != IntPtr.Zero && BinkNativeMethods.BinkWait(bink) == 0) 134 | { 135 | BinkNativeMethods.BinkDoFrame(bink); 136 | // do you stuff here 137 | BinkNativeMethods.BinkCopyToBuffer(bink, buffer, bk.Width * 3, (uint)bk.Height, 0, 0, BinkNativeMethods.BINK_COPY_FLAGS.BINKSURFACE32RGBA); 138 | 139 | texture.LoadRawTextureData(buffer); 140 | texture.Apply(); 141 | BinkNativeMethods.BinkNextFrame(bink); 142 | } 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /Assets/Scripts/BinkPlayer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e2b90ac5bccb99b4d9efc71ef1a26936 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 nickdu088 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bink-Unity-Player 2 | 3 | I have been asked to play a bink video in Unity. I googled a lot and couldn’t find any solution. Then I decided to write my own one and here is my solution to integrate Bink video into Unity. 4 | --------------------------------------------------------------------------------