You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.8 KiB
106 lines
2.8 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
[ExecuteInEditMode]
|
|
[RequireComponent(typeof(MoviePlayerBase))]
|
|
public class MovieTextureApply : MonoBehaviour {
|
|
public enum Target
|
|
{
|
|
RawImage,
|
|
Image,
|
|
Material
|
|
}
|
|
|
|
public Target target = Target.Image;
|
|
public List<Material> materials = new List<Material>();
|
|
public string attributeName;
|
|
Texture oddVideTexture;
|
|
Dictionary<Target, Action> updater_map = new Dictionary<Target, Action>();
|
|
//bool inited = false;
|
|
public bool autoSize = false;
|
|
Action updater = null;
|
|
|
|
// Use this for initialization
|
|
void Start () {
|
|
|
|
updater_map = new Dictionary<Target, Action>() {
|
|
{ Target.RawImage, UpdateRawImage },
|
|
{ Target.Material, UpdateMaterial },
|
|
{ Target.Image, UpdateImage },
|
|
};
|
|
|
|
if(updater_map.ContainsKey(target))
|
|
updater = updater_map[target];
|
|
|
|
//Debug.LogWarning("Implement editor code for better usage.");
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update () {
|
|
if (updater != null)
|
|
updater();
|
|
}
|
|
|
|
void UpdateRawImage()
|
|
{
|
|
//if(inited == false)
|
|
{
|
|
MoviePlayerBase movie = GetComponent<MoviePlayerBase>();
|
|
RawImage img = GetComponent<RawImage>();
|
|
if(movie.Texture != oddVideTexture)
|
|
{
|
|
img.texture = oddVideTexture = movie.Texture;
|
|
if (autoSize)
|
|
GetComponent<RectTransform>().sizeDelta = new Vector2(oddVideTexture.width, oddVideTexture.height);
|
|
//inited = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool showWarnning()
|
|
{
|
|
if (GetComponent<Image>() == null || target != Target.Image)
|
|
return false;
|
|
|
|
if (GetComponent<Image>().material.name != "Default UI Material")
|
|
return true;
|
|
|
|
return false;
|
|
}
|
|
|
|
void UpdateImage()
|
|
{
|
|
MoviePlayerBase movie = GetComponent<MoviePlayerBase>();
|
|
Image img = GetComponent<Image>();
|
|
if (movie.Texture != oddVideTexture && movie.Texture != null)
|
|
{
|
|
img.material.mainTexture = oddVideTexture = movie.Texture;
|
|
if (autoSize)
|
|
GetComponent<RectTransform>().sizeDelta = new Vector2(oddVideTexture.width, oddVideTexture.height);
|
|
}
|
|
}
|
|
|
|
|
|
void UpdateMaterial()
|
|
{
|
|
//if (inited == false)
|
|
{
|
|
MoviePlayerBase movie = GetComponent<MoviePlayerBase>();
|
|
if (movie.Texture != oddVideTexture)
|
|
{
|
|
oddVideTexture = movie.Texture;
|
|
foreach (var m in materials)
|
|
{
|
|
m.SetTexture(attributeName, movie.Texture);
|
|
}
|
|
//inited = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|