当前位置:网站首页>Unity audio visualization scheme
Unity audio visualization scheme
2022-06-23 07:44:00 【goose leaves a mark】
unity Method of extracting spectrum data from audio components :GetSpectrumData
So review ui Layout :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class Visualizer : MonoBehaviour
{
public AudioClip clip;
public RectTransform imagePrefab = null;
public FFTWindow windowType = FFTWindow.Rectangular;
[Space(10)]
public Transform labelPrefab;
public Transform labelRoot;
public int minHeight = 5;
public int maxHeight = 540;
public AudioSource audioSource;
[Space(20),Range(64,8192)]
public int dataLen = 64;
/** Number of bands displayed */
public int showLen = 80;
public RectTransform[] cubes = { };
// Start is called before the first frame update
void Start()
{
audioSource = new GameObject("Audio Source").AddComponent<AudioSource>();
if(!clip)
{
return;
}
audioSource.clip = clip;
audioSource.Play();
//vis = GetComponentsInChildren<VisualObject>();
initCubes();
}
private void initCubes() {
cubes = new RectTransform[showLen];
for(int i = 0; i < showLen; i++)
{
RectTransform cube = Instantiate(imagePrefab, transform);
cube.gameObject.SetActive(true);
cubes[i] = cube;
}
for (int i = 0; i < showLen; i++)
{
Transform cube = Instantiate(labelPrefab, labelRoot);
TextMeshProUGUI text = cube.GetComponent<TextMeshProUGUI>();
cube.gameObject.SetActive(true);
RectTransform t = cube.GetComponent<RectTransform>();
text.text = i + "";
text.fontSize = 5;
//t.sizeDelta = new Vector2();
}
}
// Update is called once per frame
void Update()
{
float[] spectrumDatas = new float[dataLen];
audioSource.GetSpectrumData(spectrumDatas,0,windowType);
for(int i = 0; i < cubes.Length; i++)
{
Rect rect = cubes[i].GetComponent<RectTransform>().rect;
Vector2 size = rect.size;
rect.y = Mathf.Lerp(size.y,minHeight + (maxHeight - minHeight) * spectrumDatas[i] * 2,0.1f);
Vector2 newSize = new Vector2(rect.x,rect.y);
cubes[i].GetComponent<RectTransform>().sizeDelta = newSize;
}
}
}
unity visualization
边栏推荐
- [Planet selection] how to efficiently build fine-grained two-way links between roam and thebrain?
- Console Application
- Test APK exception control nettraffic attacker development
- Download the OSS file and modify the file name
- 链游飞船开发 农民世界链游开发 土地链游开发
- [pit stepping record] a pit where the database connection is not closed and resources are released
- HCIP之路第八次实验
- Judge black production based on CDN and client slow log characteristics
- Realization of rolling broadcast effect
- 快速排序 + 冒泡排序 + 插入排序 + 选择排序
猜你喜欢

Yan's DP analysis

vs在连接SQL时出现的问题myconn.OPen();无法运行

聊聊服务治理中的路由设计
![[veusz] import 2D data in CSV](/img/22/467139f5a83ce9e88a57ced732d4d6.png)
[veusz] import 2D data in CSV

传智教育 | 项目发布前如何打tag标签及标签命名规范

《一周的朋友》

3dmax插件开发环境配置及FileExport和Utilities模板测试

Here comes the dry goods | PAAS collection to see first ~

Solutions to abnormal network connection of Xiaoai speakers

Product axure9 (English version), prototype design and production pull-down secondary menu
随机推荐
小爱音箱连接网络异常解决办法
Pseudocode specification, pseudocode online editor,
论文写作之WPS安装Mathtype插件编写数学公式
[pit stepping record] a pit where the database connection is not closed and resources are released
Sstable details
Ldconfig command
[markdown] markdown tutorial summary
Operation on a bit of binary
【markdown】markdown 教程大归纳
快速排序 + 冒泡排序 + 插入排序 + 選擇排序
MySQL (VIII) - explain
传智教育 | 多人协作开发出现代码冲突,如何合并代码?
快速删除代码里面的node_modules
Design of temperature detection and alarm system based on 51 single chip microcomputer
数学知识:快速幂—快速幂
YGG Spain subdao Ola GG officially established
Deploy kubersphere in kubernetes
Product axure9 (English version), prototype design background dynamic secondary menu display content
Left multiply right multiply matrix problem
G++ compilation command use