/// <summary>
        /// 加载所有的音频资源
        /// </summary>
        public static void LoadAudioClipSource()
        {
            GenerateAllAudioPatch();
            for (int i = 0; i < AudioAssetRelativePathList.Count; i++)
            {
                AudioClip cli = AssetDatabase.LoadAssetAtPath <AudioClip>(AudioAssetRelativePathList[i]);
                if (cli)
                {
                    string guid = AssetBundleManagerEditor.GetAssetGUIDFromMeta(AudioAssetAbsolutePathList[i]);
                    if (!string.IsNullOrEmpty(guid))
                    {
                        AudioClipInfo inf = new AudioClipInfo();
                        inf.AssetGUID        = guid;
                        inf.AssetName        = GetAssetNameFromPatchWithOutExe(AudioAssetRelativePathList[i]);
                        inf.AssetNameWithExe = GetAssetNameFromPatch(AudioAssetRelativePathList[i]);
                        AssetImporter importer = AssetImporter.GetAtPath(AudioAssetRelativePathList[i]);

                        inf.AssetBundleName = importer.assetBundleName;
                        if (!string.IsNullOrEmpty(importer.assetBundleVariant))
                        {
                            inf.AssetBundleName += "." + importer.assetBundleVariant;
                        }
                        inf.AudioLength      = cli.length;
                        inf.ResObj           = cli;
                        inf.AbsolutePatch    = AudioAssetAbsolutePathList[i];
                        inf.RelativePatch    = AudioAssetRelativePathList[i];
                        inf.HostTreeViewName = string.Empty;
                        AudioSourceList.Add(inf);
                        AudioSourceTable.Add(guid, inf);
                    }
                }
            }

            GenrateResTreeView();
        }
        /// <summary>
        /// 刷新资源
        /// </summary>
        /// <param name="movedAssetGUIDList">移动资源的GUID,如果移动了资源编辑器需要更新对应的配置里的资源</param>
        public static void RefrshAudioClipSource(List <string> movedAssetGUIDList = null)
        {
            UnLoadAudioClipSource();
            LoadAudioClipSource();

            currentSelectedClipInfo = default(AudioClipInfo);
            currentSelectedConfig   = null;

            AdjustSourceAndConfig(movedAssetGUIDList);
            if (EditorInstance)
            {
                EditorInstance.Repaint();
            }
        }
 /// <summary>
 /// 卸载所有的音频资源
 /// </summary>
 public static void UnLoadAudioClipSource()
 {
     foreach (AudioClipInfo s in AudioSourceList)
     {
         Resources.UnloadAsset(s.ResObj);
     }
     ResRootTreeView.Clear();
     ResSecondRootTreeView.Clear();
     AudioSourceList.Clear();
     AudioAssetAbsolutePathList.Clear();
     AudioAssetRelativePathList.Clear();
     AudioSourceTable.Clear();
     currentSelectedClipInfo = default(AudioClipInfo);
 }
예제 #4
0
        private static void AdjustFromList(List <string> PointedGUIDList)
        {
            //移动了资源,更新编辑器里对应的资源配置
            if (null != PointedGUIDList && PointedGUIDList.Count > 0)
            {
                foreach (EditorSoundConfigData cof in CurrentSoundConfigTable.Values)
                {
                    bool bAdjust = false;
                    foreach (string s in PointedGUIDList)
                    {
                        //找出一样的GUID
                        if (cof.data.AssetGUID.Equals(s))
                        {
                            //移动的资源还在Sound文件夹里面
                            if (AudioSourceTable.ContainsKey(s))
                            {
                                AudioClipInfo inf = AudioSourceTable[s];
                                cof.data.AssetBundleName = inf.AssetBundleName;
                                cof.data.AssetName       = inf.AssetName;
                                bAdjust = true;

                                //更新树状图
                                GenerateHostTreeView_Config(cof);
                                break;
                            }
                        }
                    }

                    if (!bAdjust)
                    {
                        cof.data.AssetBundleName = string.Empty;
                        cof.data.AssetName       = string.Empty;
                        cof.data.AssetGUID       = string.Empty;

                        SoundManager.SoundSystemLog("配置:" + cof.data.nID + "无法找到匹配的资源!");
                    }
                }
            }
        }
        static void CheckSecondRootView_Res(string[] splitString, string root, AudioClipInfo data)
        {
            //如果长度是2,表明,只在这个跟节点里而已,直接添加进去就行
            if (splitString.Length == 1)
            {
                data.ParentTreeViewName = string.Empty;
                data.HostTreeViewName   = root;
                ResRootTreeView[root].AudioClipList.Add(data);
            }
            else//如果不是,则看看次级节点
            {
                //第二根节点
                string secondRoot = splitString[1];


                //第二根节点已经存在,直接添加进去就行
                if (ResSecondRootTreeView.ContainsKey(secondRoot))
                {
                    data.HostTreeViewName   = secondRoot;
                    data.ParentTreeViewName = root;

                    ResSecondRootTreeView[secondRoot].AudioClipList.Add(data);
                }
                else //不存在,新建一个,再添加进去
                {
                    TreeViewNode nod = null;
                    ResRootTreeView[root].ChildViewList.Add(secondRoot);
                    nod = new TreeViewNode();
                    nod.TreeViewName       = secondRoot;
                    nod.ParentTreeViewName = root;

                    nod.AudioClipList.Add(data);
                    data.HostTreeViewName   = secondRoot;
                    data.ParentTreeViewName = root;

                    ResSecondRootTreeView.Add(secondRoot, nod);
                }
            }
        }
        /// <summary>
        /// 计算属于哪个树节点
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <returns></returns>
        static void GenerateHostTreeView_Res(AudioClipInfo s)
        {
            //如果assetbundlename是空的,不处理
            if (string.IsNullOrEmpty(s.AssetBundleName))
            {
                return;
            }


            //用于判断的节点不能有后缀
            string treepatch = s.AssetBundleName.Replace(".soundpkg", "");

            //去掉sound头
            treepatch = treepatch.Replace("sound/", "");

            string[] splitString = treepatch.Split('/');

            string root = splitString[0];

            //如果根节点表里有这个节点
            if (ResRootTreeView.ContainsKey(root))
            {
                s.ParentTreeViewName = string.Empty;
                //再去检查第二根节点
                CheckSecondRootView_Res(splitString, root, s);
            }
            else
            {
                //新建跟节点
                TreeViewNode no = new TreeViewNode();
                no.TreeViewName       = root;
                no.ParentTreeViewName = string.Empty;
                ResRootTreeView.Add(root, no);

                //再去检查第二根节点
                CheckSecondRootView_Res(splitString, root, s);
            }
        }