【问题标题】:Video texture Unity 5视频纹理 Unity 5
【发布时间】:2015-09-22 23:02:01
【问题描述】:

我无法在 unity 5.2 个人版中显示视频纹理。我应用了一个带有无光照着色器的材质并将其指定为视频纹理。我还通过附加到具有视频纹理的对象的脚本调用特定的视频纹理。

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(AudioSource))]

    public class CallMovie : MonoBehaviour {
        public MovieTexture myMovie;

        // Use this for initialization
        void Start () {
            Debug.Log ("start intro");
            GetComponent<Renderer>().material.mainTexture = myMovie;// get movie
            myMovie.Play ();// shall play movie

        }
        void Update(){
            myMovie.loop =true;
        }
    }

当我统一点击播放按钮时,视频纹理保持黑色,屏幕上什么也没有发生,尽管程序说它在检查调试日志时运行了视频。

【问题讨论】:

  • 日志中是否显示“开始介绍”?

标签: unity3d


【解决方案1】:

由于我无法在您的首字母评论中发布问题,因此以下是我所知道的尝试回答。

在调试调用后的第一个语句中,您将实例材质的 maintexture 组件设置为 myMovie,这取决于着色器,这可能会或可能不会起作用,因为“mainTexture”可能没有引用您期望的纹理。

您可以确保使用以下方法达到所需的纹理

        //Note the diffrence between a material instance and the shared material
        //... dont forget to clean up instances if you make them which hapens when you call .material
        Material instancedMaterial = gameObject.GetComponent<Renderer>().material;
        Material sharedMaterial = gameObject.GetComponent<Renderer>().sharedMaterial;

        //_MainTex is the name of the main texture for most stock shaders ... but not all
        //You can select the shader by clicking the gear in the inspector of the material
        //this will display the shader in the inspector where you can see its properties by name
        instancedMaterial.SetTexture("_MainTex", movie);

以下代码来自我用来设置 Unity UI 对象 RawImage 以渲染电影的工作类对象。从我在您的示例中看到的情况来看,您的电影部分是正确的,我怀疑您的问题出在着色器参数上。

using UnityEngine;
using System.Collections;

public class RawImageMovePlayer : MonoBehaviour 
{
    public UnityEngine.UI.RawImage imageSource;

    public bool play;
    public bool isLoop = true;

    public MovieTexture movie;

    // Use this for initialization
    void Start () 
    {
        movie = (MovieTexture)imageSource.texture;
        movie.loop = isLoop;
    }

    // Update is called once per frame
    void Update () 
    {
        if (!movie.isPlaying && play)
            movie.Play();
    }

    public void ChangeMovie(MovieTexture movie)
    {
        imageSource.texture = movie;

        this.movie = (MovieTexture)imageSource.texture;
        this.movie.loop = isLoop;
    }

    public void OnDisable()
    {
        if (movie != null && movie.isPlaying)
            movie.Stop();
    }
}

【讨论】:

  • 非常感谢您的回答,我将对此进行测试。
猜你喜欢
  • 1970-01-01
  • 2018-07-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-31
  • 1970-01-01
  • 2011-09-23
相关资源
最近更新 更多