u3d加载外部视屏

u3d的外部加载视屏,采用www方式,可以使用gui播放,也可以绑定到gameobject上作为动态材质使用,不过目前只支持。ogg格式,需要转。。。

using UnityEngine;
using System.Collections;

public class movie : MonoBehaviour
{
    private MovieTexture movTexture;

    private string movPath;

    void Start()
    {
        movPath = "file://" + Application.dataPath + "/1.ogg";
        StartCoroutine(LoadMoview());

    }
    public void LoadRes()
    {
        movPath = "file://" + Application.dataPath + "/1.ogg";
        StartCoroutine(LoadMoview());
    }
    IEnumerator LoadMoview()
    {
        WWW wwwDate = new WWW(movPath);

        yield return wwwDate;
        movTexture = wwwDate.movie;//得到下载的贴图
        movTexture.loop = true;
        movTexture.Play();
    }

    // Update is called once per frame
    void Update()
    {
        // GUI.DrawTexture(new Rect(0 + 100, 0 + 100, Screen.width - 100, Screen.height - 100), movTexture, ScaleMode.ScaleToFit);
        


        this.renderer.material.mainTexture = movTexture;  
    }

    void OnGUI()
    {
     
       
    }
}


 下面是给一个gameobject加上这个脚本

using UnityEngine;
using System.Collections;

public class Init : MonoBehaviour
{
    private GameObject m_ObjCube;
    // Use this for initialization
    void Start () 
    {
        m_ObjCube = GameObject.Find("ECube");
        m_ObjCube.AddComponent<movie>();
        //m_ObjCube.GetComponent<movie>().LoadRes();
    }
    
    // Update is called once per frame
    void Update () {
    
    }
}

 

posted on 2014-08-19 14:33  c_dragon  阅读(371)  评论(0编辑  收藏  举报

导航