当前位置:网站首页>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();
}
}
}
边栏推荐
- Since the "epidemic", we have adhered to the "no closing" of data middle office services
- MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
- Regular expression of shell script value
- Function: find the approximate value of the limit of the ratio of the former term to the latter term of Fibonacci sequence. For example, when the error is 0.0001, the function value is 0.618056.
- Sequence list and linked list
- Struct in linked list
- Thinkphp6 integrated JWT method and detailed explanation of generation, removal and destruction
- Print diamond pattern
- Oracle database knowledge points (I)
- Wechat official account and synchronization assistant
猜你喜欢

Thinkphp6 integrated JWT method and detailed explanation of generation, removal and destruction
![[error record] configure NDK header file path in Visual Studio](/img/9f/89f68c037dcf68a31a2de064dd8471.jpg)
[error record] configure NDK header file path in Visual Studio

From functional testing to automated testing, how did I successfully transform my salary to 15K +?

Fundamentals of machine learning: feature selection with lasso

A dichotomy of Valentine's Day

The FISCO bcos console calls the contract and reports an error does not exist

打印菱形图案

技术实践|线上故障分析及解决方法(上)

Future源码一观-JUC系列

Avoid playing with super high conversion rate in material minefields
随机推荐
8. Go implementation of string conversion integer (ATOI) and leetcode
Function: find the approximate value of the limit of the ratio of the former term to the latter term of Fibonacci sequence. For example, when the error is 0.0001, the function value is 0.618056.
All in one 1412: binary classification
[prefix and notes] prefix and introduction and use
1-redis architecture design to use scenarios - four deployment and operation modes (Part 1)
All in one 1407: stupid monkey
A little understanding of GSLB (global server load balance) technology
Decompile and modify the non source exe or DLL with dnspy
PMP 考试常见工具与技术点总结
For loop
Is it really possible that the monthly salary is 3K and the monthly salary is 15K?
2-Redis架构设计到使用场景-四种部署运行模式(下)
Wechat official account and synchronization assistant
Sequence list and linked list
Fundamentals of machine learning: feature selection with lasso
MySQL uses the view to report an error, explain/show can not be issued; lacking privileges for underlying table
From functools import reduce -- see the use of reduce function from typical examples
GUI 应用:socket 网络聊天室
Since the "epidemic", we have adhered to the "no closing" of data middle office services
老姜的特点