前段時間策划們想知道UI預制件中使用了哪些音效
N多預制件、N多音效!!
如果純人工整理的話這還不累成狗?
累成狗不說,還容易出錯
所以獲取音頻剪輯小工具就誕生了,將策划從死亡邊緣拉了回來
我們先看一下相關API手冊:http://game.ceeger.com/Script/EditorUtility/EditorUtility.CollectDependencies.html
這玩意可好用了,之前也用它做過獲取預制件公共資源工具
看看名字:“收集依賴關系”
那還不簡單明了了,有依賴關系的東西都能獲取過來嘛
我寫了個方法,支持獲取任意類型
這個方法你可以直接copy去用,不用自己寫的。
使用方法也很簡單,在這里我提供一個完整的獲取預制件音頻剪輯的例子。上代碼咯
1 #region HeadComments 2 /* ======================================================================== 3 * Copyright (C) 2015 Arthun 4 * 5 * 作 者:Arthun 6 * 文件名稱:ArthunTools 7 * 功 能:升哥哥工具包 8 * 創建時間:2015/09/11 2:15:20 9 * 版 本:v1.0.0 10 * 11 * [修改日志] 12 * 修改者: 時間: 修改內容: 13 * 14 * ========================================================================= 15 */ 16 #endregion 17 18 using System.Collections.Generic; 19 using UnityEditor; 20 using UnityEngine; 21 22 public class ArthunTools : EditorWindow 23 { 24 /// 音頻剪輯信息 <summary> 25 /// 26 /// </summary> 27 public class AudioClipInfo 28 { 29 public string prefab = ""; 30 public string audio = ""; 31 } 32 33 /// 選中預制件(可多選)后按 Alt + G 鍵獲取 <summary> 34 /// 35 /// </summary> 36 [MenuItem("Arthun Tools/Get Select Prefabs Info &G")] 37 static void GetSelectPrefab() 38 { 39 GameObject[] gos = Selection.gameObjects; 40 41 Debug.Log("getCount:" + gos.Length.ToString()); 42 43 if (gos.Length == 0) 44 return; 45 46 List<AudioClipInfo> audioClipsInfo = new List<AudioClipInfo>(); 47 foreach (GameObject go in gos) 48 { 49 #region 依賴關系獲取音頻 50 List<AudioClip> audioClips = GetPrefabDepe<AudioClip>(go); 51 52 foreach (AudioClip ac in audioClips) 53 { 54 if (ac != null) 55 { 56 AudioClipInfo info = new AudioClipInfo(); 57 info.prefab = go.name; 58 info.audio = ac.name; 59 audioClipsInfo.Add(info); 60 } 61 } 62 #endregion 63 } 64 65 foreach (AudioClipInfo info in audioClipsInfo) 66 { 67 Debug.Log(string.Format("prefab:{0} audio:{1}", info.prefab, info.audio)); 68 } 69 70 Debug.Log("soundCount:" + audioClipsInfo.Count.ToString()); 71 } 72 73 /// 獲取預制件依賴 <summary> 74 /// 75 /// </summary> 76 /// <typeparam name="T">欲獲取的類型</typeparam> 77 /// <param name="go"></param> 78 /// <returns></returns> 79 static List<T> GetPrefabDepe<T>(GameObject go) 80 { 81 List<T> results = new List<T>(); 82 Object[] roots = new Object[] { go }; 83 Object[] dependObjs = EditorUtility.CollectDependencies(roots); 84 foreach (Object dependObj in dependObjs) 85 { 86 if (dependObj != null && dependObj.GetType() == typeof(T)) 87 { 88 results.Add((T)System.Convert.ChangeType(dependObj, typeof(T))); 89 } 90 } 91 92 return results; 93 } 94 }
文中不足之處歡迎批評指正
本文鏈接:http://www.cnblogs.com/shenggege/p/4799801.html