Created
October 28, 2016 22:47
-
-
Save mikamikem/156d9bb2a0d4fe7a101697d051027b65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Reflection; | |
using UMP; | |
public class UMPFixup : MonoBehaviour { | |
public UniversalMediaPlayer PlayerInst = null; | |
public StandaloneMediaPlayer MediaPlayerInst = null; | |
[System.Serializable] | |
public class TextureSettings | |
{ | |
public MeshRenderer RendererInst; | |
public int MaterialIndex = 0; | |
public string TextureName = "_MainTex"; | |
} | |
public List<TextureSettings> Textures = new List<TextureSettings>(); | |
public Texture2D LastTex = null; | |
private FieldInfo MediaPlayerTextureField = null; | |
public virtual StandaloneMediaPlayer SetMediaPlayerInst() | |
{ | |
if(PlayerInst != null) | |
{ | |
FieldInfo MediaPlayerField = typeof(UniversalMediaPlayer).GetField("_mediaPlayer", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); | |
if(MediaPlayerField != null) | |
{ | |
MediaPlayerInst = (UMP.StandaloneMediaPlayer)MediaPlayerField.GetValue(PlayerInst); | |
} | |
} | |
return MediaPlayerInst; | |
} | |
public virtual FieldInfo SetTextureProperty() | |
{ | |
if(MediaPlayerInst != null || SetMediaPlayerInst() != null) | |
{ | |
MediaPlayerTextureField = typeof(UMP.StandaloneMediaPlayer).GetField("_videoTexture", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public); | |
} | |
return MediaPlayerTextureField; | |
} | |
public virtual void Update() | |
{ | |
if(MediaPlayerTextureField != null || SetTextureProperty() != null) | |
{ | |
if(MediaPlayerTextureField.GetValue(MediaPlayerInst) != LastTex) | |
{ | |
LastTex = (Texture2D)MediaPlayerTextureField.GetValue(MediaPlayerInst); | |
for(int CurrentTexture = 0; CurrentTexture < Textures.Count; ++CurrentTexture) | |
{ | |
try | |
{ | |
if(Textures[CurrentTexture].RendererInst != null) | |
{ | |
Material CurrentMaterial = Textures[CurrentTexture].RendererInst.materials[Textures[CurrentTexture].MaterialIndex]; | |
if(CurrentMaterial != null) | |
{ | |
CurrentMaterial.SetTexture(Textures[CurrentTexture].TextureName, LastTex); | |
} | |
} | |
} | |
catch(MissingReferenceException) | |
{ | |
Textures.RemoveAt(CurrentTexture); | |
--CurrentTexture; | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment