当前位置:网站首页>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();
}
}
}
边栏推荐
- A-Frame虚拟现实开发入门
- Eight year test old bird, some suggestions for 1-3 year programmers
- [common error] UART cannot receive data error
- 查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
- [prefix and notes] prefix and introduction and use
- 中电资讯-信贷业务数字化转型如何从星空到指尖?
- 我管你什么okr还是kpi,PPT轻松交给你
- Struct in linked list
- 查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
- PMP 考试常见工具与技术点总结
猜你喜欢

Analysis and solution of lazyinitializationexception

A-Frame虚拟现实开发入门

Sorry, Tencent I also refused

Introduction to unity shader essentials reading notes Chapter III unity shader Foundation

长文综述:大脑中的熵、自由能、对称性和动力学

A dichotomy of Valentine's Day

Function: store the strings entered in the main function in reverse order. For example, if you input the string "ABCDEFG", you should output "gfedcba".

Pytest unit test framework: simple and easy to use parameterization and multiple operation modes

【.NET+MQTT】.NET6 环境下实现MQTT通信,以及服务端、客户端的双边消息订阅与发布的代码演示

On covariance of array and wildcard of generic type
随机推荐
Analysis and solution of lazyinitializationexception
机器学习基础:用 Lasso 做特征选择
I don't care about you. OKR or KPI, PPT is easy for you
Swagger2 quick start and use
查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题
HackTheBox-baby breaking grad
Fundamentals of machine learning: feature selection with lasso
Interview script of Software Test Engineer
@EnableAsync @Async
Force deduction solution summary 1189- maximum number of "balloons"
Struct in linked list
It's OK to have hands-on 8 - project construction details 3-jenkins' parametric construction
Oracle database knowledge points that cannot be learned (II)
技术实践|线上故障分析及解决方法(上)
Makefile judge custom variables
be based on. NETCORE development blog project starblog - (14) realize theme switching function
2-Redis架构设计到使用场景-四种部署运行模式(下)
A-Frame虚拟现实开发入门
From functools import reduce -- see the use of reduce function from typical examples
Introduction to A-frame virtual reality development