当前位置:   article > 正文

unity做可视化音乐播放器_可视化音乐篇_unity音乐播放器的设计与实现实验总结

unity音乐播放器的设计与实现实验总结

using UnityEngine;  
using System.Collections;  


public class audioTest : MonoBehaviour {  


public float deep;
public AudioSource audio1;
public GameObject a;
    public Material Myobj;
// Use this for initialization  
void Start () {  
}  
// Update is called once per frame  
void Update () {  
//建立音谱数组,后面的三个参数我前面已经介绍过,这里是具体用法  


float[] spectrum = audio1.GetSpectrumData(256, 0, FFTWindow.Hamming);  
int i = 1;  
//我们控制物体所用到的数值  
float heght = 0;  
//以下内容是在scence中现实音谱内容  
while (i < 255)  
{  
Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);  
Debug.DrawLine(new Vector3(i - 1, Mathf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, Mathf.Log(spectrum[i]) + 10, 2), Color.cyan);  
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3(Mathf.Log(i), spectrum[i] - 10, 1), Color.green);  
Debug.DrawLine(new Vector3(Mathf.Log(i - 1), Mathf.Log(spectrum[i - 1]), 3), new Vector3(Mathf.Log(i), Mathf.Log(spectrum[i]), 3), Color.yellow);  
heght = heght + spectrum[i];  
i++;  
}  
//经过本人测试heght值最多为1点几,所以为了表示明显,我*10,但由于会有0影响效果,所以+1  
 
heght = heght * 10 + 1;  
//利用iTween插件变换图形,关于iTween我稍后做讲述  
//iTween.ScaleTo(a, new Vector3(0.4f,heght*10-deep,0.2f), 0f);  


this.gameObject.transform.localScale = new Vector3 (0.1f, heght-deep, 0.1f);
        
       
        






        print(heght); 
        if ((heght*10)>15f){
            
           
            iTween.ColorTo(a, new Color(0, -heght, 256 - heght), 0f); 


}


else if((heght*10)<13f) 
iTween.ColorTo(a, new Color(127, 255-deep, 0), 0f); 




}  
}

 

 

最后,生活那么苦,来看看沙雕视频欢乐下吧!

自家亲视频号,卑微在线求关注

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/118413
推荐阅读
相关标签
  

闽ICP备14008679号