Ejemplo n.º 1
0
    protected void LoadClipData(int type, string name, System.Action <AudioClip> completeAction)
    {
        string dataPath               = "audio/";
        AudioBeanDictionary dicData   = new AudioBeanDictionary();
        AudioClip           audioClip = null;

        switch (type)
        {
        case 1:
            dicData   = listMusicData;
            dataPath += "music";
            break;

        case 2:
            dicData   = listSoundData;
            dataPath += "sound";
            break;

        case 3:
            dicData   = listEnvironmentData;
            dataPath += "environment";
            break;
        }
        if (dicData.TryGetValue(name, out audioClip))
        {
            completeAction?.Invoke(audioClip);
            return;
        }
        audioClip = LoadAssetUtil.SyncLoadAsset <AudioClip>(dataPath, name);
        if (audioClip != null)
        {
            dicData.Add(name, audioClip);
        }
        completeAction?.Invoke(audioClip);
    }
Ejemplo n.º 2
0
    public void LoadClipDataByAddressbles(int type, string name, System.Action <AudioClip> completeAction)
    {
        AudioBeanDictionary dicData = new AudioBeanDictionary();

        switch (type)
        {
        case 1:
            dicData = listMusicData;
            break;

        case 2:
            dicData = listSoundData;
            break;

        case 3:
            dicData = listEnvironmentData;
            break;
        }
        if (dicData.TryGetValue(name, out AudioClip audioClip))
        {
            completeAction?.Invoke(audioClip);
            return;
        }
        LoadAddressablesUtil.LoadAssetAsync <AudioClip>(name, (data) =>
        {
            if (data.Result != null)
            {
                dicData.Add(name, data.Result);
            }
            completeAction?.Invoke(data.Result);
        });
    }
Ejemplo n.º 3
0
 /// <summary>
 /// 根据文件夹下所有文件添加字典
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="mapFood"></param>
 public static void AddAudioBeanDictionaryByFolder(string folderPath, AudioBeanDictionary map)
 {
     FileInfo[] files = FileUtil.GetFilesByPath(folderPath);
     foreach (FileInfo item in files)
     {
         Object[] objs = AssetDatabase.LoadAllAssetsAtPath(folderPath + item.Name);
         objs.ToList().ForEach(obj =>
         {
             if (obj as AudioClip != null)
             {
                 map.Add(obj.name, obj as AudioClip);
             }
         });
     }
 }