当前位置:网站首页>Audio resource settings for U3D resource management
Audio resource settings for U3D resource management
2022-07-04 01:05:00 【Art is cTRlC】
This article realizes the function of batch setting of audio resources ( Lazy style )
The mind map is as follows

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class AudioSettingManager
{
static bool btFirst = true;//true Priority for inclusion size (false Performance first )
static string[] AudioType = new string[] { ".mp3", ".wav", ".ogg" };
static void AddFileList(List<string> filePaths, string path)
{
for (int j = 0; j < AudioType.Length; ++j)
{
if (AudioType[j] == Path.GetExtension(path))
{
filePaths.Add(path);
}
}
}
const string AudioLazySettingTag = "Assets/Audio Tool/ Optimize audio file settings ( Lazy style )";
[MenuItem(AudioLazySettingTag,false,64)]
public static void AudioLazySetting()
{
string[] assetGUIDArray = Selection.assetGUIDs;
if (assetGUIDArray.Length > 0)
{
List<string> filePaths = new List<string>();
for (int i = 0; i < assetGUIDArray.Length; ++i)
{
string assetPath = AssetDatabase.GUIDToAssetPath(assetGUIDArray[i]);
if (Directory.Exists(assetPath))
{
string[] folder = new string[] { assetPath };
// Select all the resources under the folder as the selected resources
string[] paths = AssetDatabase.FindAssets(null, folder);
foreach (var p in paths)
{
string ppath = AssetDatabase.GUIDToAssetPath(p);
if (!Directory.Exists(ppath))
{
AddFileList(filePaths, ppath);
}
}
}
else
{
AddFileList(filePaths, assetPath);
}
}
var count = 0;
AudioClipLoadType loadtype = AudioClipLoadType.DecompressOnLoad;
AudioCompressionFormat audioCompressionFormat = AudioCompressionFormat.Vorbis;
EditorUtility.DisplayProgressBar("3.Set Audio ", "3.Set Audio ...", 0);
foreach (string path in filePaths)
{
count++;
EditorUtility.DisplayProgressBar("3.Set Audio " + "(" + count + "/" + filePaths.Count + ")", path, count / (float)filePaths.Count);
AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
AudioClip audio = AssetDatabase.LoadAssetAtPath<AudioClip>(path);
audioImporter.forceToMono = true;
AudioImporterSampleSettings generalSettings = new AudioImporterSampleSettings();
if (audio.samples / audio.length > 22050)
{
Debug.Log(audio.samples / audio.length);
generalSettings.sampleRateSetting = AudioSampleRateSetting.OverrideSampleRate;
generalSettings.sampleRateOverride = 22050;
}
if (audio.length >= 5)
{
loadtype = AudioClipLoadType.Streaming;
audioCompressionFormat = AudioCompressionFormat.Vorbis;
}
else if(audio.length < 1)
{
loadtype = AudioClipLoadType.DecompressOnLoad;
audioCompressionFormat = AudioCompressionFormat.ADPCM;
}
else
{
loadtype = AudioClipLoadType.CompressedInMemory;
audioCompressionFormat = AudioCompressionFormat.ADPCM;
}
generalSettings.loadType = loadtype;
if (btFirst)
{
generalSettings.compressionFormat = AudioCompressionFormat.Vorbis;
}
else
{
generalSettings.compressionFormat = audioCompressionFormat;
}
generalSettings.quality = 0.5f;
audioImporter.defaultSampleSettings = generalSettings;
//audioImporter.SetOverrideSampleSettings("Android", androidSettings);
//audioImporter.SetOverrideSampleSettings("IOS", iOSSettings);
AssetDatabase.ImportAsset(path);
}
EditorUtility.ClearProgressBar();
}
}
}
边栏推荐
- AI helps make new breakthroughs in art design plagiarism retrieval! Professor Liu Fang's team paper was employed by ACM mm, a multimedia top-level conference
- 2-Redis架构设计到使用场景-四种部署运行模式(下)
- Decompile and modify the non source exe or DLL with dnspy
- Future source code view -juc series
- [prefix and notes] prefix and introduction and use
- Eight year test old bird, some suggestions for 1-3 year programmers
- 2-redis architecture design to use scenarios - four deployment and operation modes (Part 2)
- QML add gradient animation during state transition
- Swagger2 quick start and use
- 功能:求出菲波那契数列的前一项与后一项之比的极限的 近似值。例如:当误差为0.0001时,函数值为0.618056。
猜你喜欢

1-Redis架构设计到使用场景-四种部署运行模式(上)

Eight year test old bird, some suggestions for 1-3 year programmers

Characteristics of ginger

Makefile judge custom variables

功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。
![[common error] custom IP instantiation error](/img/de/d3f90cd224274d87fcf153bb9244d7.jpg)
[common error] custom IP instantiation error
![[common error] UART cannot receive data error](/img/77/6ba56ce6e64beeb73a77d04af5bd0f.jpg)
[common error] UART cannot receive data error

It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction

MPLS experiment

Employees' turnover intention is under the control of the company. After the dispute, the monitoring system developer quietly removed the relevant services
随机推荐
Pair
使用dnSpy对无源码EXE或DLL进行反编译并且修改
Since the "epidemic", we have adhered to the "no closing" of data middle office services
Makefile judge custom variables
删除所有值为y的元素。数组元素中的值和y的值由主函数通过键盘输入。
It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
Msp32c3 board connection MSSQL method
MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
All in one 1407: stupid monkey
gslb(global server load balance)技术的一点理解
GUI 应用:socket 网络聊天室
Thinkphp6 integrated JWT method and detailed explanation of generation, removal and destruction
How to be a professional software testing engineer? Listen to the byte five year old test
不得不会的Oracle数据库知识点(二)
CLP information - how does the digital transformation of credit business change from star to finger?
查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
be based on. NETCORE development blog project starblog - (14) realize theme switching function
Who moved my code!
功能:将主函数中输入的字符串反序存放。例如:输入字符串“abcdefg”,则应输出“gfedcba”。
功能:求5行5列矩阵的主、副对角线上元素之和。注意, 两条对角线相交的元素只加一次。例如:主函数中给出的矩阵的两条对角线的和为45。