zoukankan      html  css  js  c++  java
  • Multimedia&Network

    Multimedia&Network

    1、Unity3D共支持4种格式音乐文件:

    2、AudioSource用于指明音频源,被绑定在一个GameObject身上。光有AudioSource组件声音是无法听到的,因为在3D世界中,距离远的音频我们听不到或者声音小,而距离近的音频我们就能清楚地听到。这样的效果需要通过AudioListener来实现,AudioListener被绑定在Camera身上,因为在3D世界上,我们的位置与Camera的位置一致。

         只有AudioSource可以加载音乐文件,当代码中有AudioSource时,只能指向AudioSource,而非音乐源文件,如下:

     

    3、视频使用MovieTexture来播放。

     1     //电影纹理
     2     public MovieTexture movTexture;
     3     
     4     void Start()
     5     {
     6         //设置当前对象的主纹理为电影纹理
     7         renderer.material.mainTexture = movTexture;
     8         //设置电影纹理播放模式为循环
     9         movTexture.loop = true;
    10     }
    11     
    12     void OnGUI()
    13     {
    14         if(GUILayout.Button("播放/继续"))
    15         {
    16             //播放/继续播放视频
    17             if(!movTexture.isPlaying)
    18             {
    19                 movTexture.Play();
    20             }
    21             
    22         }
    23         
    24         if(GUILayout.Button("暂停播放"))
    25         {
    26             //暂停播放
    27             movTexture.Pause();
    28         }
    29         
    30         if(GUILayout.Button("停止播放"))
    31         {
    32             //停止播放
    33             movTexture.Stop();
    34         }
    35     }
    View Code

    4、也可以通过GUI.DrawTexture来播放视频。

     1     //电影纹理
     2     public MovieTexture movTexture;
     3     
     4     void Start()
     5     {
     6         //设置电影纹理播放模式为循环
     7         movTexture.loop = true;
     8     }
     9     
    10     void OnGUI()
    11     {
    12         //绘制电影纹理
    13         GUI.DrawTexture (new Rect (0,0, Screen.width, Screen.height),movTexture,ScaleMode.StretchToFill);  
    14         
    15         if(GUILayout.Button("播放/继续"))
    16         {
    17             //播放/继续播放视频
    18             if(!movTexture.isPlaying)
    19             {
    20                 movTexture.Play();
    21             }
    22             
    23         }
    24         
    25         if(GUILayout.Button("暂停播放"))
    26         {
    27             //暂停播放
    28             movTexture.Pause();
    29         }
    30         
    31         if(GUILayout.Button("停止播放"))
    32         {
    33             //停止播放
    34             movTexture.Stop();
    35         }
    36     }
    View Code

    5、使用WWW类获取网络数据。

     1     //本机下载的贴图
     2     private Texture tex0 ;
     3 
     4     //服务器下载贴图
     5     private Texture tex1;
     6         
     7     IEnumerator loadLocal () 
     8     {
     9         //本机下载
    10         if(tex0 == null)
    11         {
    12             //资源在本机的路径
    13             WWW date = new WWW("file://" + Application.dataPath + "/0.png"); 
    14             //等待下载完成
    15             yield return date; 
    16             //得到下载的贴图
    17             tex0 = date.texture;
    18         }
    19         //更换为下载的贴图
    20         renderer.material.mainTexture = tex0; 
    21 
    22     }
    23     
    24     IEnumerator loadNetWork () 
    25     {
    26         //服务器网页下载
    27         if(tex1 == null)
    28         {
    29             //资源的url服务器路径
    30             WWW date = new WWW("http://www.google.com.hk/intl/zh-CN/images/logo_cn.png"); 
    31             //等待下载完成
    32             yield return date; 
    33             //得到下载的贴图
    34             tex1 = date.texture;
    35         }
    36         //更换为下载的贴图
    37         renderer.material.mainTexture = tex1; 
    38     }
    39     
    40      void OnGUI()
    41     {
    42          if(GUILayout.Button("本机下载贴图"))
    43          {
    44                 StartCoroutine(loadLocal());
    45             }
    46     
    47     
    48          if(GUILayout.Button("服务器下载贴图"))
    49          {
    50               StartCoroutine(loadNetWork());
    51          } 
    52     }
    View Code

     6、使用Network类可以实现连接。Network.peerType的值为以下几种,可以用来判断网络状态。

      

      InitializeServer可创建服务器:

      

      通过connection属性可以获取连接的peer。

      

      通过connect方法可以连接至服务器:

      

      

  • 相关阅读:
    2012年6月30号PMP考试总结
    安装了VS2010 sp1 后再安装ASP.NET MVC 3.0的问题(Final Result: Installation failed with error code: (0x80070643), "安装时发生严重错误 " (Ela)
    黄光裕方面独家点评国美中报:领先优势即将丧失
    Asp.net 模板页(MasterPage)里的 js脚本路径
    Windows 7 Sp1 x64 无法安装英文语言包(已解决)
    The issue of vertical lines throughing the Report footer or the whole page in Crystal report 11
    Windows Server 2008 R2 with Service Pack 1
    垃圾农业银行网银https://www.95599.cn/PersonalBank/startUpHtmlSessionAction.ebf
    如何填写PMP审计表单,Audit注意事项
    被日军飞机炸毁的上海南火车站铁轨上拍摄了一个父母刚被炸死、正在铁轨上深哀啼号的婴儿
  • 原文地址:https://www.cnblogs.com/tekkaman/p/3537804.html
Copyright © 2011-2022 走看看