当前位置:网站首页>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();
}
}
}
边栏推荐
- [prefix and notes] prefix and introduction and use
- [common error] custom IP instantiation error
- gslb(global server load balance)技术的一点理解
- Future源码一观-JUC系列
- The difference between fetchtype lazy and eagle in JPA
- It is worthy of "Alibaba internal software test interview notes" from beginning to end, all of which are essence
- Eight year test old bird, some suggestions for 1-3 year programmers
- 机器学习基础:用 Lasso 做特征选择
- 不得不会的Oracle数据库知识点(二)
- [common error] UART cannot receive data error
猜你喜欢
AI 助力艺术设计抄袭检索新突破!刘芳教授团队论文被多媒体顶级会议ACM MM录用
Pytest unit test framework: simple and easy to use parameterization and multiple operation modes
On covariance of array and wildcard of generic type
[error record] configure NDK header file path in Visual Studio
HackTheBox-baby breaking grad
Weekly open source project recommendation plan
Analysis and solution of lazyinitializationexception
Sequence list and linked list
What is the future of software testing industry? Listen to the test veterans' answers
Regular expression of shell script value
随机推荐
Data mining vs Machine Learning: what is the difference between them? Which is more suitable for you to learn
Fundamentals of machine learning: feature selection with lasso
基于.NetCore开发博客项目 StarBlog - (14) 实现主题切换功能
How to use AHAS to ensure the stability of Web services?
Oracle database knowledge points (I)
Eight year test old bird, some suggestions for 1-3 year programmers
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.
Cloud dial test helps Weidong cloud education to comprehensively improve the global user experience
Summary of common tools and technical points of PMP examination
Force deduction solution summary 1189- maximum number of "balloons"
The difference between fetchtype lazy and eagle in JPA
MySQL -- Introduction and use of single line functions
Oracle database knowledge points (IV)
Introduction to thread pool
The force deduction method summarizes the single elements in the 540 ordered array
打印菱形图案
be based on. NETCORE development blog project starblog - (14) realize theme switching function
“疫”起坚守 保障数据中台服务“不打烊”
[error record] configure NDK header file path in Visual Studio (three header file paths of NDK | ASM header file path selection related to CPU architecture)
Mobile asynchronous sending SMS verification code solution -efficiency+redis