{"id":101,"date":"2019-11-09T00:59:08","date_gmt":"2019-11-08T16:59:08","guid":{"rendered":"http:\/\/www.blinkedu.cn\/?p=101"},"modified":"2019-11-11T11:42:29","modified_gmt":"2019-11-11T03:42:29","slug":"unity%ef%bc%9a%e9%9f%b3%e9%a2%91%e5%8f%af%e8%a7%86%e5%8c%96%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/www.blinkedu.cn\/index.php\/2019\/11\/09\/unity%ef%bc%9a%e9%9f%b3%e9%a2%91%e5%8f%af%e8%a7%86%e5%8c%96%e5%ae%9e%e7%8e%b0\/","title":{"rendered":"Unity\uff1a\u97f3\u9891\u53ef\u89c6\u5316\u5b9e\u73b0"},"content":{"rendered":"<h2>\u5b9e\u73b0\u8fc7\u7a0b<\/h2>\n<ol>\n<li>\u521b\u5efa\u5de5\u7a0b\uff0c\u65b0\u5efa\u4e00\u4e2a\u573a\u666f\uff0c\u5728\u573a\u666f\u4e2d\u5efa\u4e00\u4e2a\u7a7a\u7269\u4f53\uff0c\u6dfb\u52a0\u4e00\u4e2aAudioSource\u7ec4\u4ef6\u7528\u6765\u64ad\u653e\u97f3\u4e50<br \/>\n<a href=\"https:\/\/i.loli.net\/2019\/11\/09\/39c2lsuyEknVhG7.png\" target=\"_blank\"  rel=\"nofollow\" ><img decoding=\"async\" layer-src=\"https:\/\/i.loli.net\/2019\/11\/09\/39c2lsuyEknVhG7.png\" src=\"https:\/\/i.loli.net\/2019\/11\/09\/39c2lsuyEknVhG7.png\" alt=\"\u300aUnity\uff1a\u97f3\u9891\u53ef\u89c6\u5316\u5b9e\u73b0\u300b\"><\/a><\/li>\n<li>Cube\u521b\u5efa\u4e00\u4e2aCube\u4f5c\u4e3a\u9884\u5236\u4f53\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u6750\u8d28\u7403\uff0c\u5e76\u52fe\u9009\u81ea\u53d1\u5149\uff0c\u5c06Cube\u7684\u6750\u8d28\u6307\u5b9a\u4e3a\u8be5\u6750\u8d28\u7403<br \/>\n<img decoding=\"async\" layer-src=\"https:\/\/i.loli.net\/2019\/11\/09\/SK2eqOm3v6lkcHY.png\" src=\"https:\/\/i.loli.net\/2019\/11\/09\/SK2eqOm3v6lkcHY.png\" alt=\"\u300aUnity\uff1a\u97f3\u9891\u53ef\u89c6\u5316\u5b9e\u73b0\u300b\"><\/li>\n<li>\u521b\u5efa\u811a\u672c\uff0c\u5e76\u5c06\u811a\u672c\u6302\u8f7d\u5230\u7a7a\u7269\u4f53\u4e0a\uff0c\u5e76\u62d6\u62fd\u8d4b\u503c\u76f8\u5e94\u7684\u7ec4\u4ef6<\/li>\n<\/ol>\n<h2>\u4ee3\u7801<\/h2>\n<pre><code class=\"language-csharp line-numbers\">using System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\n\npublic class MusicSpectrum : MonoBehaviour\n{\n    public AudioSource AudioSource;\n    public GameObject Prefab;\n\n    private const int LENGHT = 512;\n    \/\/ \u5b58\u50a8\u9891\u8c31\u6570\u636e\u7684\u6570\u7ec4\uff08\u6ce8\u610f\u6570\u7ec4\u7684\u957f\u5ea6\u5fc5\u987b\u4e3a2\u7684\u6b21\u65b9\uff09\n    private float[] m_Samples = new float[LENGHT];\n    \/\/ \u5b58\u50a8\u5b9e\u4f8b\u5316\u7684\u9884\u5236\u4f53\uff0c\u7528\u6765\u663e\u793a\u9891\u8c31\n    private GameObject[] m_Gos = new GameObject[LENGHT];\n    \/\/ \u9891\u8c31\u5206\u6790\u7c7b\u578b\n    private FFTWindow m_FFT = FFTWindow.Rectangular;\n\n    private void Start()\n    {\n        \/\/ \u5b9e\u4f8b\u5316\u9884\u5236\u4f53\n        for (int i = 0; i &lt; LENGHT; i++)\n        {\n            m_Gos[i] = GameObject.Instantiate(Prefab, new Vector3((LENGHT \/ 2f) * (-0.12f) + i * 0.12f, 1f, 1f), Quaternion.identity, transform);\n        }\n    }\n\n    private int m_Index = 0;\n    private void Update()\n    {\n        \/\/ \u83b7\u53d6\u9891\u8c31\u6570\u636e\n        AudioSource.GetSpectrumData(m_Samples, 0, m_FFT);\n        \/\/ \u901a\u8fc7\u8bbe\u7f6e\u9884\u5236\u4f53\u7684\u7f29\u653e\u8fdb\u884c\u663e\u793a\n        for (int i = 0; i &lt; m_Samples.Length; i++)\n        {\n            m_Gos[i].transform.localScale = new Vector3(0.1f, 0.1f + m_Samples[i] * 250, 1);\n        }\n\n        \/\/ \u6309Q\u952e\u5207\u6362\u9891\u8c31\u5206\u6790\u7c7b\u578b\n        if (Input.GetKeyDown(KeyCode.Q))\n        {\n            m_Index++;\n            if (m_Index &gt; 5)\n                m_Index = 0;\n            m_FFT = (FFTWindow)m_Index;\n        }\n    }\n\n    private void OnGUI()\n    {\n        GUIStyle style = new GUIStyle\n        {\n            fontSize = 45\n        };\n        style.normal.textColor = Color.red;\n        GUILayout.Label(m_FFT.ToString(),style);\n    }\n}\n<\/code><\/pre>\n<h2>\u6548\u679c<\/h2>\n<p><a href=\"https:\/\/i.loli.net\/2019\/11\/09\/kuGRFWagsBHxTDV.gif\" target=\"_blank\"  rel=\"nofollow\" ><img decoding=\"async\" layer-src=\"https:\/\/i.loli.net\/2019\/11\/09\/kuGRFWagsBHxTDV.gif\" src=\"https:\/\/i.loli.net\/2019\/11\/09\/kuGRFWagsBHxTDV.gif\" alt=\"\u300aUnity\uff1a\u97f3\u9891\u53ef\u89c6\u5316\u5b9e\u73b0\u300b\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u73b0\u8fc7\u7a0b \u521b\u5efa\u5de5\u7a0b\uff0c\u65b0\u5efa\u4e00\u4e2a\u573a\u666f\uff0c\u5728\u573a\u666f\u4e2d\u5efa\u4e00\u4e2a\u7a7a\u7269\u4f53\uff0c\u6dfb\u52a0\u4e00\u4e2aAudioSource\u7ec4\u4ef6\u7528\u6765\u64ad\u653e\u97f3\u4e50 Cube\u521b\u5efa\u4e00\u4e2aCube\u4f5c\u4e3a\u9884\u5236\u4f53\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u6750\u8d28\u7403\uff0c\u5e76\u52fe\u9009\u81ea\u53d1\u5149\uff0c\u5c06Cube\u7684\u6750\u8d28\u6307\u5b9a\u4e3a\u8be5\u6750\u8d28\u7403 \u521b\u5efa\u811a\u672c\uff0c\u5e76\u5c06\u811a\u672c\u6302\u8f7d\u5230\u7a7a\u7269\u4f53\u4e0a\uff0c\u5e76\u62d6\u62fd\u8d4b\u503c\u76f8\u5e94\u7684\u7ec4\u4ef6 \u4ee3\u7801 using System.Collections; using Syste\u2026\u2026<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-unity"],"_links":{"self":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts\/101"}],"collection":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":0,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.blinkedu.cn\/index.php\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}