private MovieMaterial() { this.advance = true; this.loopCount = 1; this.playSpeed = 1f; this.scanDuration = true; this.m_nativeContext = IntPtr.Zero; this.m_nativeTextureContext = IntPtr.Zero; this.m_ChannelTextures = new Texture2D[3]; this.m_hasFinished = true; this.currentFPS = -1.0; this.currentDuration = -1.0; this.Width = 0; this.Height = 0; try { MobileMovieManager.NativeGraphicsInitialize(); this.m_nativeContext = MovieMaterial.CreateContext(); } catch (Exception arg) { global::Debug.Log("[Movie.MovieMaterial.GLPlugin] Error when creating a native context more info: " + arg); throw; } if (this.m_nativeContext == IntPtr.Zero) { global::Debug.Log("[Movie.MovieMaterial.GLPlugin] Unable to create Mobile Movie Texture native context"); throw new Exception("[Movie.MovieMaterial.GLPlugin] Unable to create Mobile Movie Texture native context"); } }
public void Destroy() { if (this.hasStream) { this.Stop(); } this.DestroyTextures(); MovieMaterial.DestroyContext(this.m_nativeContext); }
private void Open() { Int64 num = 0L; Int64 num2 = 0L; RuntimePlatform platform = Application.platform; String text; switch (platform) { case RuntimePlatform.WindowsEditor: text = AssetManagerUtil.GetStreamingAssetsPath() + "/ma/" + this.MovieFile; break; case RuntimePlatform.IPhonePlayer: text = AssetManagerUtil.GetStreamingAssetsPath() + "/ma/" + this.MovieFile; break; case RuntimePlatform.PS3: case RuntimePlatform.XBOX360: IL_2A: if (platform != RuntimePlatform.WindowsPlayer) { throw new Exception("[Movie.MovieMaterial.GLPlugin] Platform: " + Application.platform + " Not supported."); } text = AssetManagerUtil.GetStreamingAssetsPath() + "/ma/" + this.MovieFile; break; case RuntimePlatform.Android: text = Application.dataPath; if (!AssetStream.GetZipFileOffsetLength(Application.dataPath, "ma/" + this.MovieFile, out num, out num2)) { throw new Exception("[Movie.MovieMaterial.GLPlugin] Error opening movie via AssetStream"); } break; default: goto IL_2A; } this.isFMV = this.MovieFile.StartsWith("FMV"); if (this.m_nativeContext != IntPtr.Zero && MovieMaterial.OpenStream(this.m_nativeContext, text, (Int32)num, (Int32)num2, false, this.scanDuration, 16)) { this.Width = MovieMaterial.GetPicWidth(this.m_nativeContext); this.Height = MovieMaterial.GetPicHeight(this.m_nativeContext); this.m_picX = MovieMaterial.GetPicX(this.m_nativeContext); this.m_picY = MovieMaterial.GetPicY(this.m_nativeContext); this.m_yStride = MovieMaterial.GetYStride(this.m_nativeContext); this.m_yHeight = MovieMaterial.GetYHeight(this.m_nativeContext); this.m_uvStride = MovieMaterial.GetUVStride(this.m_nativeContext); this.m_uvHeight = MovieMaterial.GetUVHeight(this.m_nativeContext); this.currentFPS = this.FPS; this.currentDuration = MovieMaterial.GetDuration(this.m_nativeContext); this.CalculateUVScaleOffset(); return; } throw new FileLoadException("Error opening movie during stream opening at path: " + text); }
public void Stop() { if (!this.hasStream) { return; } this.Transparency = 0f; MovieMaterial.CloseStream(this.m_nativeContext); this.m_hasFinished = true; this.hasStream = false; SoundLib.StopMovieMusic(this.movieKey, false); }
public static MovieMaterial New(MovieMaterialProcessor processor) { if (processor == (UnityEngine.Object)null) { throw new NullReferenceException("MovieMaterialProcessor cannot be null"); } Material material = AssetManager.Load <Material>("EmbeddedAsset/Shaders/Movie/Movie", false); if (material == (UnityEngine.Object)null) { throw new ArgumentException("Failed to load material Movie/Movie"); } material.SetColor("_TintColor", Color.clear); MovieMaterial movieMaterial = new MovieMaterial { Material = material }; processor.MovieMaterial = movieMaterial; return(movieMaterial); }
private void AllocateTexures() { this.m_ChannelTextures[0] = Texture2D.CreateExternalTexture(this.m_yStride, this.m_yHeight, TextureFormat.Alpha8, false, false, MovieMaterial.GetNativeHandle(this.m_nativeContext, 0)); this.m_ChannelTextures[1] = Texture2D.CreateExternalTexture(this.m_uvStride, this.m_uvHeight, TextureFormat.Alpha8, false, false, MovieMaterial.GetNativeHandle(this.m_nativeContext, 1)); this.m_ChannelTextures[2] = Texture2D.CreateExternalTexture(this.m_uvStride, this.m_uvHeight, TextureFormat.Alpha8, false, false, MovieMaterial.GetNativeHandle(this.m_nativeContext, 2)); this.m_ChannelTextures[0].wrapMode = TextureWrapMode.Clamp; this.m_ChannelTextures[1].wrapMode = TextureWrapMode.Clamp; this.m_ChannelTextures[2].wrapMode = TextureWrapMode.Clamp; if (this.Material != (UnityEngine.Object)null) { this.SetTextures(this.Material); } }
public void Update() { if (this.m_nativeContext != IntPtr.Zero && !this.m_hasFinished) { IntPtr nativeTextureContext = MovieMaterial.GetNativeTextureContext(this.m_nativeContext); if (nativeTextureContext != this.m_nativeTextureContext) { this.DestroyTextures(); this.AllocateTexures(); this.m_nativeTextureContext = nativeTextureContext; } this.m_hasFinished = MovieMaterial.HasFinished(this.m_nativeContext); if (!this.m_hasFinished) { if (this.advance) { double elapsedTime = this.m_elapsedTime; float num = Mathf.Max(this.playSpeed, 0f); bool flag = false; flag |= this.isFMV; if (flag) { if (this.preciseTimeCycleCounter == 0) { this.m_elapsedTime += 0.066 * (double)this.playSpeed; } else { this.m_elapsedTime += 0.067 * (double)this.playSpeed; } if (this.preciseTimeCycleCounter == 2) { this.preciseTimeCycleCounter = 0; } else { this.preciseTimeCycleCounter++; } } else { this.m_elapsedTime += (double)(Mathf.Min(Time.deltaTime, 0.067f) * num); } if (this.shouldSync) { SoundLib.SeekMovieAudio(this.movieKey, this.PlayPosition); this.shouldSync = false; } if (this.playSpeed > 1f) { this.syncElapsed += Time.deltaTime; if (this.syncElapsed >= 4f) { SoundLib.SeekMovieAudio(this.movieKey, this.PlayPosition); this.syncElapsed = 0f; } } } } else { if (this.loopCount - 1 <= 0 && this.loopCount != -1) { SoundLib.StopMovieMusic(this.movieKey, false); if (this.OnFinished != null) { this.m_elapsedTime = MovieMaterial.GetDecodedFrameTime(this.m_nativeContext); this.OnFinished(); } return; } if (this.loopCount != -1) { this.loopCount--; } this.m_elapsedTime %= MovieMaterial.GetDecodedFrameTime(this.m_nativeContext); MovieMaterial.Seek(this.m_nativeContext, 0.0, false); this.m_hasFinished = false; } MovieMaterial.SetTargetDisplayDecodeTime(this.m_nativeContext, this.m_elapsedTime); if (!this.getFirstFrame) { double uploadedFrameTime = MovieMaterial.GetUploadedFrameTime(this.m_nativeContext); double num2 = 0.066666666666666666; if (uploadedFrameTime > num2) { this.m_elapsedTime = 0.0; this.preciseTimeCycleCounter = 0; this.getFirstFrame = true; if (this.Material != null) { this.Material.SetColor("_TintColor", this.tintColor); } if (this.advance) { SoundLib.PlayMovieMusic(this.movieKey, 0); } } } } }