public override void Serialize(ExporterEntry entry, Dictionary <string, Extension> extensions, UnityEngine.Object component = null) { if (!ENTRY_CLIPS.ContainsKey(entry)) { ENTRY_CLIPS.Add(entry, new List <SeinAudioClip>()); ENTRY_URIS.Add(entry, new Dictionary <AudioClip, string>()); } Sein_audioClipsExtension extension; var source = component as SeinAudioSource; if (!extensions.ContainsKey(ExtensionName)) { extension = new Sein_audioClipsExtension(); AddExtension(extensions, extension); } else { extension = (Sein_audioClipsExtension)extensions["Sein_audioClips"]; } var list = ENTRY_CLIPS[entry]; var uris = ENTRY_URIS[entry]; foreach (var c in source.clips) { var clip = c.clip; if (c.clip == null) { throw new Exception("Clip '" + c.name + "' has no audio source!"); } if (list.Contains(clip)) { continue; } var newClip = new Sein_audioClipsExtension.AudioClip(); newClip.name = clip.name; newClip.mode = clip.mode; newClip.isLazy = clip.isLazy; if (uris.ContainsKey(clip.clip)) { newClip.uri = uris[clip.clip]; } else { newClip.uri = SaveAudio(clip.clip); } list.Add(clip); extension.clips.Add(newClip); } }
private void LoadClip(Sein_audioClipsExtension.AudioClip clip, string gltfPath, string basePath, int i) { var uri = Path.Combine(gltfPath, clip.uri); if (clip.uri != null && File.Exists(uri)) { var tmp = clip.uri.Split('/'); var name = tmp[tmp.Length - 1]; if (clip.name != null) { name = clip.name; } var path = Path.Combine(basePath, name); if (File.Exists(path)) { if (!IMPORTED_URIS.Contains(clip.uri)) { name = Path.GetFileNameWithoutExtension(name) + "-" + i + Path.GetExtension(name); path = Path.Combine(basePath, name); FileUtil.CopyFileOrDirectory(uri, path); IMPORTED_URIS.Add(clip.uri); } } else { FileUtil.CopyFileOrDirectory(uri, path); IMPORTED_URIS.Add(clip.uri); } AssetDatabase.Refresh(); var unityClip = AssetDatabase.LoadAssetAtPath <AudioClip>(path); var directory = GLTFUtils.getPathProjectFromAbsolute(basePath); path = Path.Combine(directory, name + ".asset"); var seinClip = ScriptableObject.CreateInstance <SeinAudioClip>(); seinClip.clip = unityClip; seinClip.mode = clip.mode; seinClip.isLazy = clip.isLazy; AssetDatabase.CreateAsset(seinClip, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); seinClip = AssetDatabase.LoadAssetAtPath <SeinAudioClip>(path); IMPORTED_CLIPS.Add(seinClip); } else { Debug.LogWarning("Audio clip not found"); } }