{"id":246,"date":"2015-04-30T17:40:09","date_gmt":"2015-04-30T09:40:09","guid":{"rendered":"http:\/\/qxu1606620110.my3w.com\/?p=246"},"modified":"2016-10-11T09:33:50","modified_gmt":"2016-10-11T01:33:50","slug":"unity3d%e7%a0%94%e7%a9%b6%e4%b9%8b%e4%b8%a4%e7%a7%8d%e6%96%b9%e5%bc%8f%e6%92%ad%e6%94%be%e6%b8%b8%e6%88%8f%e8%a7%86%e9%a2%91","status":"publish","type":"post","link":"http:\/\/www.u3d8.com\/?p=246","title":{"rendered":"Unity3D\u7814\u7a76\u4e4b\u4e24\u79cd\u65b9\u5f0f\u64ad\u653e\u6e38\u620f\u89c6\u9891"},"content":{"rendered":"<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><span style=\"color: #ff0000;\">\u8f6c\u81ea\uff1a<a href=\"http:\/\/www.xuanyusong.com\/archives\/category\/unity\">http:\/\/www.xuanyusong.com\/archives\/category\/unity<\/a><\/span><\/p>\n<p><strong>\u00a0Unity3D\u4e2d\u64ad\u653e\u6e38\u620f\u89c6\u9891\u7684\u65b9\u5f0f\u6709\u4e24\u79cd\uff0c\u7b2c\u4e00\u79cd\u662f\u5728\u6e38\u620f\u5bf9\u8c61\u4e2d\u64ad\u653e\uff0c\u5c31\u597d\u6bd4\u5728\u6e38\u620f\u4e16\u754c\u4e2d\u521b\u5efa\u4e00\u4e2aPlane\u9762\u5bf9\u8c61\uff0c\u6444\u50cf\u673a\u76f4\u76f4\u7684\u7167\u5c04\u5728\u8fd9\u4e2a\u9762\u4e0a\u3002\u7b2c\u4e8c\u79cd\u662f\u5728GUI\u5c42\u9762\u4e0a\u64ad\u653e\u89c6\u9891\u3002\u64ad\u653e\u89c6\u9891\u5176\u5b9e\u548c\u8d34\u56fe\u975e\u5e38\u76f8\u50cf\uff0c\u56e0\u4e3a\u64ad\u653e\u89c6\u9891\u7528\u5230\u7684MovieTexture\u5c5e\u4e8e\u8d34\u56feTexture\u7684\u5b50\u7c7b\uff0c\u90a3\u4e48\u672c\u7ae0\u6211\u4eec\u5c31\u597d\u597d\u5b66\u4e60\u4e00\u4e0bUnity\u4e2d\u64ad\u653e\u89c6\u9891\u7684\u8fd9\u4e24\u79cd\u65b9\u5f0f\u3002\u54c7\u5494\u5494\uff5e<\/strong><\/p>\n<p><strong>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Unity\u652f\u6301\u7684\u64ad\u653e\u89c6\u9891\u683c\u5f0f\u6709.mov\u3001.mpg\u3001.mpeg\u3001.mp4\u3001.avi\u548c.asf\u3002\u53ea\u9700\u5c06\u5bf9\u5e94\u7684\u89c6\u9891\u6587\u4ef6\u62d6\u62fd\u5165Project\u89c6\u56fe\u5373\u53ef\uff0c\u5b83\u4f1a\u81ea\u52a8\u751f\u6210\u5bf9\u5e94\u7684MovieTexture\u5bf9\u8c61\u3002\u5982\u4e0b\u56fe\u6240\u793a\uff0cMOMO\u5c06default_video.mp4\u62d6\u62fd\u5165Project\u89c6\u56fe\u4e2d\uff0c\u5982\u679c\u89c6\u9891\u4e2d\u542b\u6709\u97f3\u9891\u7684\u8bdd\u4f1a\u5bf9\u5e94\u751f\u6210audio\u6587\u4ef6\uff0c\u56e0\u4e3a\u6211\u7684\u89c6\u9891\u6ca1\u6709\u97f3\u9891\u6240\u4ee5\u6ca1\u6709\u751f\u6210 audio\u6587\u4ef6\u3002\u63a5\u7740\u5728Hierarchy\u89c6\u56fe\u4e2d\u521b\u5efa\u4e00\u4e2aPlane\u5bf9\u8c61\u89c6\u9891\u5c06\u5728\u5b83\u4e4b\u4e0a\u64ad\u653e\uff0cDirectional light\u4e16\u754c\u5b9a\u5411\u5149\u7528\u4e8e\u7167\u4eae\u6574\u4e2a\u6e38\u620f\u573a\u666f\uff0c\u6700\u540eMain Camera\u5bf9\u8c61\u5c06\u76f4\u76f4\u7684\u7167\u5c04\u5728Plane\u5bf9\u8c61\u3002<\/strong><\/p>\n<p><strong>\u4f7f\u7528\u5bf9\u8c61\u62d6\u62fd\u7684\u5f62\u5f0f\u4e3aMov Texture\u5bf9\u8c61\u8d4b\u503c\uff0c\u90a3\u4e48\u5728\u811a\u672c\u4e2d\u5c31\u80fd\u76f4\u63a5\u4f7f\u7528\u5b83\u4e86\uff0c\u6211\u4eec\u770b\u770bTest.cs\u811a\u672c\u3002<\/strong><\/p>\n<p><strong>Test.cs<\/strong><\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\nusing System.Collections;\r\n \r\npublic class Test: MonoBehaviour\r\n{\r\n \r\n\t\/\/\u7535\u5f71\u7eb9\u7406\r\n\tpublic MovieTexture movTexture;\r\n \r\n\tvoid Start()\r\n\t{\r\n\t\t\/\/\u8bbe\u7f6e\u5f53\u524d\u5bf9\u8c61\u7684\u4e3b\u7eb9\u7406\u4e3a\u7535\u5f71\u7eb9\u7406\r\n\t\trenderer.material.mainTexture = movTexture;\r\n\t\t\/\/\u8bbe\u7f6e\u7535\u5f71\u7eb9\u7406\u64ad\u653e\u6a21\u5f0f\u4e3a\u5faa\u73af\r\n\t\tmovTexture.loop = true;\r\n\t}\r\n \r\n\tvoid OnGUI()\r\n\t{\r\n\t\tif(GUILayout.Button(\"\u64ad\u653e\/\u7ee7\u7eed\"))\r\n\t\t{\r\n\t\t\t\/\/\u64ad\u653e\/\u7ee7\u7eed\u64ad\u653e\u89c6\u9891\r\n\t\t\tif(!movTexture.isPlaying)\r\n\t\t\t{\r\n\t\t\t\tmovTexture.Play();\r\n\t\t\t}\r\n \r\n\t\t}\r\n \r\n\t\tif(GUILayout.Button(\"\u6682\u505c\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\t\/\/\u6682\u505c\u64ad\u653e\r\n\t\t\tmovTexture.Pause();\r\n\t\t}\r\n \r\n\t\tif(GUILayout.Button(\"\u505c\u6b62\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\t\/\/\u505c\u6b62\u64ad\u653e\r\n\t\t\tmovTexture.Stop();\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<p>\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u70b9\u51fb\u6309\u94ae\u540e\u8f7b\u677e\u7684\u5b9e\u73b0\u64ad\u653e\u3001\u6682\u505c\u3001\u505c\u6b62\u64cd\u4f5c\u3002\u9ed8\u8ba4\u89c6\u9891\u5927\u5c0f\u5927\u5bb6\u53ef\u5728\u7f16\u8f91\u5668\u76f4\u63a5\u7f29\u653ePlane\u5bf9\u8c61\u5e73\u9762\uff0c\u800c\u5982\u679c\u9700\u8981\u5728\u6e38\u620f\u8fd0\u884c\u4e2d\u52a8\u6001\u7684\u7f29\u653e\u5e73\u9762\u4f7f\u7528\u65b9\u6cd5:<\/p>\n<pre class=\"lang:c# decode:true\">transform.localScale = new Vector(1,1,1);\r\n<\/pre>\n<p><strong>\u6a21\u578b\u9ed8\u8ba4\u7f29\u653e\u7cfb\u6570\u4e3a1\uff0c\u8fd9\u91cc\u53ef\u4ee5\u8c03\u8282\u5e73\u9762X\u3001Y\u3001Z\u4e09\u4e2a\u65b9\u5411\u7684\u7f29\u653e\u7cfb\u6570\uff0c\u5e73\u9762\u7684\u5927\u5c0f\u4f1a\u968f\u4e4b\u6539\u53d8\uff0c\u5bf9\u5e94\u89c6\u9891\u7684\u5927\u5c0f\u4e5f\u4f1a\u968f\u4e4b\u6539\u53d8\u3002<\/strong><\/p>\n<p><strong>\u00a0\u7b2c\u4e8c\u79cd\u64ad\u653e\u89c6\u9891\u7684\u65b9\u5f0f\u57fa\u4e8eGUI\u3002\u5927\u5bb6\u53ef\u4ee5\u628a\u521a\u521a\u521b\u5efa\u7684Plane\u5bf9\u8c61\u4ee5\u53ca\u4e16\u754c\u5b9a\u5411\u5149\u5220\u9664\uff0c\u76f4\u63a5\u5c06\u811a\u672c\u7ed1\u5b9a\u5728\u6444\u50cf\u673a\u5bf9\u8c61\u4e2d\u5373\u53ef\uff0c\u63a5\u7740\u6211\u4eec\u7b80\u5355\u7684\u4fee\u6539\u4e00\u4e0b\u521a\u521a\u7684\u6e38\u620f\u811a\u672c\u3002<\/strong><\/p>\n<p><strong>Test.cs<\/strong><\/p>\n<pre class=\"lang:c# decode:true\">using UnityEngine;\r\nusing System.Collections;\r\n \r\npublic class Test: MonoBehaviour\r\n{\r\n \r\n\t\/\/\u7535\u5f71\u7eb9\u7406\r\n\tpublic MovieTexture movTexture;\r\n \r\n\tvoid Start()\r\n\t{\r\n\t\t\/\/\u8bbe\u7f6e\u7535\u5f71\u7eb9\u7406\u64ad\u653e\u6a21\u5f0f\u4e3a\u5faa\u73af\r\n\t\tmovTexture.loop = true;\r\n\t}\r\n \r\n\tvoid OnGUI()\r\n\t{\r\n\t\t\/\/\u7ed8\u5236\u7535\u5f71\u7eb9\u7406\r\n\t\tGUI.DrawTexture (new Rect (0,0, Screen.width, Screen.height),movTexture,ScaleMode.StretchToFill);  \r\n \r\n\t\tif(GUILayout.Button(\"\u64ad\u653e\/\u7ee7\u7eed\"))\r\n\t\t{\r\n\t\t\t\/\/\u64ad\u653e\/\u7ee7\u7eed\u64ad\u653e\u89c6\u9891\r\n\t\t\tif(!movTexture.isPlaying)\r\n\t\t\t{\r\n\t\t\t\tmovTexture.Play();\r\n\t\t\t}\r\n \r\n\t\t}\r\n \r\n\t\tif(GUILayout.Button(\"\u6682\u505c\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\t\/\/\u6682\u505c\u64ad\u653e\r\n\t\t\tmovTexture.Pause();\r\n\t\t}\r\n \r\n\t\tif(GUILayout.Button(\"\u505c\u6b62\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\t\/\/\u505c\u6b62\u64ad\u653e\r\n\t\t\tmovTexture.Stop();\r\n\t\t}\r\n\t}\r\n \r\n}<\/pre>\n<p><strong>\u5728GUI\u4e2d\u64ad\u653e\u89c6\u9891\u7684\u539f\u7406\u662f\u76f4\u63a5\u901a\u8fc7GUI\u8c03\u7528DrawTexture\u65b9\u6cd5\uff0c\u8fd9\u91cc\u548c\u7ed8\u5236\u8d34\u56fe\u5f88\u60f3\u4e86\u5427\u563f\u563f\uff5e \u76ee\u524d\u64ad\u653e\u89c6\u9891\u7684\u5927\u5c0f\u662f\u5c4f\u5e55\u7684\u5bbd\u9ad8\uff0c\u5982\u679c\u60f3\u52a8\u6001\u7684\u4fee\u6539\u89c6\u9891\u7684\u5bbd\u6216\u9ad8\u76f4\u63a5\u4fee\u6539new Rect\uff08\uff09 \u89c6\u9891\u663e\u793a\u533a\u57df\u5373\u53ef\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff0c\u89c6\u9891\u5df2\u7ecf\u6ee1\u6ee1\u7684\u586b\u5145\u5728\u6574\u4e2aGUI\u4e2d\u5566\u3002\u600e\u4e48\u6837Unity\u4e2d\u64ad\u653e\u89c6\u9891\u7b80\u5355\u5427\uff1f \u54c7\u5494\u5494\uff5e<\/strong><\/p>\n<p><strong>\u79fb\u52a8\u5e73\u53f0\u4e0a\u64ad\u653e\u89c6\u9891\u00a0<\/strong><\/p>\n<p><strong>\u7ecf\u6d4b\u8bd5\u4ee5\u4e0a\u7684\u65b9\u5f0f\u5728IOS\u548cAndroid\u8bbe\u5907\u4e2d\u662f\u65e0\u6cd5\u64ad\u653e\u89c6\u9891\u7684\uff0c\u5728\u79fb\u52a8\u8bbe\u5907\u4e0a\u6211\u4eec\u9700\u8981\u4f7f\u7528\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f\u6765\u64ad\u653e\u3002<\/strong><\/p>\n<pre class=\"lang:c# decode:true\">C#\r\nusing UnityEngine;\r\nusing System.Collections;\r\n \r\npublic class Test : MonoBehaviour {\r\n \r\n\tvoid OnGUI()\r\n\t{\r\n\t    if (GUI.Button (new Rect (20,10,200,50), \"PLAY ControlMode.CancelOnTouch\")) \r\n\t\t{\r\n    \t   \tHandheld.PlayFullScreenMovie(\"test.mp4\", Color.black, FullScreenMovieControlMode.CancelOnInput);\r\n\t\t}\r\n \r\n\t\tif (GUI.Button (new Rect (20,90,200,25), \"PLAY ControlMode.Full\")) \r\n\t\t{\r\n       \t\tHandheld.PlayFullScreenMovie(\"test.mp4\", Color.black, FullScreenMovieControlMode.Full);\r\n\t\t}\r\n \r\n\t\tif (GUI.Button (new Rect (20,170,200,25), \"PLAY ControlMode.Hidden\")) \r\n\t\t{\r\n       \t \tHandheld.PlayFullScreenMovie(\"test.mp4\", Color.black, FullScreenMovieControlMode.Hidden);\t\r\n\t\t}\r\n \r\n\t\tif (GUI.Button (new Rect (20,250,200,25), \"PLAY ControlMode.Minimal\")) \r\n\t\t{\r\n       \t\tHandheld.PlayFullScreenMovie(\"test.mp4\", Color.black, FullScreenMovieControlMode.Minimal);\r\n\t\t}\r\n \r\n\t}\r\n \r\n}<\/pre>\n<p><strong>1.\u89c6\u9891\u64ad\u653e\u65f6\u89e6\u6478\u5c4f\u5e55\u89c6\u9891\u5173\u95ed<\/strong><\/p>\n<p><strong>2.\u89c6\u9891\u64ad\u653e\u65f6\u5f39\u51faIOS\u9ad8\u7ea7\u63a7\u4ef6\uff0c\u63a7\u5236\u89c6\u9891\u6682\u505c\u64ad\u653e \u5168\u5c4f\u7b49\u7b49\u3002<\/strong><\/p>\n<p><strong>3.\u89c6\u9891\u64ad\u653e\u65f6\u65e0\u6cd5\u505c\u6b62\uff0c\u5f53\u5176\u64ad\u653e\u5b8c\u4e00\u6b21\u540e\u81ea\u52a8\u5173\u95ed<\/strong><\/p>\n<p><strong>4.\u89c6\u9891\u64ad\u653e\u65f6\u5f39\u51faIOS\u9ad8\u7ea7\u63a7\u4ef6\uff0c\u53ef\u63a7\u5236\u64ad\u653e\u8fdb\u5ea6\u3002<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u6ce8\u610f\uff1a\u5c06\u89c6\u9891\u6587\u4ef6\u653e\u7f6e\u5728Assets\/StreamingAssets\/\u8def\u5f84\u4e0b\uff0c\u7ecf\u6d4b\u8bd5.MP4\u53ef\u7528\u3002 \u5728IOS\u548cAndroid\u4e0a\u6d41\u7545\u64ad\u653e\u6e38\u620f\u89c6\u9891\u3002<\/strong><\/p>\n<p><strong>\u5de5\u7a0b\u4e0b\u8f7d\uff1a\u00a0<a href=\"http:\/\/vdisk.weibo.com\/s\/gb4Lx\">http:\/\/vdisk.weibo.com\/s\/gb4Lx<\/a><\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u89c6\u9891\u52a0\u901f\u64ad\u653e\uff08\u53ea\u9002\u7528\u4e8ePC\uff09<\/strong><\/p>\n<p><strong>\u4eca\u5929\u6709\u670b\u53cb\u95ee\u6211\uff0c\u600e\u4e48\u80fd\u8ba9\u89c6\u9891\u52a0\u5feb\u64ad\u653e\uff0c\u6211\u4e5f\u5b66\u4e86\u4e00\u4e0b\uff0c\u4e0d\u679c\u8001\u5916\u4eec\u90fd\u8bf4\u8fd9\u662f\u4e00\u4e2aBUG\u5475\u5475\u3002<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u811a\u672c\u7ed1\u5b9a\u5728\u6444\u50cf\u673a\u5bf9\u8c61\u4e0a\uff0c\u5e76\u4e14\u8981\u7ed9\u6444\u50cf\u673a\u6dfb\u52a0AudioSource\u7ec4\u4ef6\u3002<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4ee3\u7801\u6bd4\u8f83\u7b80\u5355\u6211\u5c31\u4e0d\u6ce8\u91ca\u4e86\u3002<\/strong><\/p>\n<pre class=\"lang:c# decode:true \">using UnityEngine;\r\nusing System.Collections;\r\n \r\npublic class NewBehaviourScript : MonoBehaviour \r\n{\r\n\tpublic MovieTexture mov;\r\n \r\n\tvoid Start()\r\n\t{\r\n\t\taudio.clip = mov.audioClip;\r\n\t\taudio.Play();\r\n\t\tmov.Play();\r\n \r\n\t}\r\n\tvoid OnGUI()\r\n\t{\r\n\t\tif(GUI.Button(new Rect ( 310,0,100,50),\"2\u500d\u901f\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\taudio.pitch = 2f;\r\n\t\t}\r\n \r\n\t\tif(GUI.Button(new Rect ( 410,0,100,50),\"1\u500d\u901f\u64ad\u653e\"))\r\n\t\t{\r\n\t\t\taudio.pitch = 1f;\r\n\t\t}\r\n \r\n\t\tGUI.DrawTexture(new Rect(0,0,300,300),mov);\r\n\t}\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u8f6c\u81ea\uff1ahttp:\/\/www.xuanyusong.com\/arch &hellip; <a href=\"http:\/\/www.u3d8.com\/?p=246\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[23],"tags":[59,58],"_links":{"self":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/246"}],"collection":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=246"}],"version-history":[{"count":8,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":748,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=\/wp\/v2\/posts\/246\/revisions\/748"}],"wp:attachment":[{"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.u3d8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}