Documentation for the Unity C# Library
Loading...
Searching...
No Matches
VoiceOverImporterWindow.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using System.Linq;
4using System.Text;
5using PixoVR.Audio;
6#if UNITY_EDITOR
7using Sirenix.OdinInspector;
8using Sirenix.OdinInspector.Editor;
9using UnityEditor;
10#endif
11using UnityEngine;
12using yutokun;
13
14namespace PixoVR.Event.Editor
15{
16#if UNITY_EDITOR
17 public class VoiceOverImporterWindow : OdinEditorWindow
18 {
19 public const string VoiceOverDataPath = "Assets/VoiceOverData";
20
21 [Sirenix.OdinInspector.FilePath(Extensions = "csv")]
22 public string filePath;
23
24 [MenuItem("Window/PIXO/Voiceover importer")]
25 public static void Open()
26 {
27 GetWindow(typeof(VoiceOverImporterWindow), false, "Voiceover importer");
28 }
29
30 [Button]
31 public void Import()
32 {
33 var sheet = CSVParser.LoadFromPath(filePath);
34 var name = Path.GetFileNameWithoutExtension(filePath);
35
36 var voiceOverDataPath = $"{VoiceOverDataPath}/{name}.asset";
37 var asset = AssetDatabase.LoadAssetAtPath<VoiceOverData>(voiceOverDataPath);
38
39 if (asset == null)
40 {
41 Directory.CreateDirectory(voiceOverDataPath);
42 asset = VoiceOverData.CreateInstance<VoiceOverData>();
43 AssetDatabase.CreateAsset(asset, voiceOverDataPath);
44 }
45
46 for (int i = 0; i < sheet.Count; i++)
47 {
48 string id = sheet[i][0];
49 string text = sheet[i][1];
50
51 if (!asset.voiceOverInfos.Any(v => v.id == id))
52 {
53 asset.voiceOverInfos.Add(new VoiceOverInfo() {id = id});
54 }
55
56 var info = asset.voiceOverInfos.First(v => v.id == id);
57 info.voiceOverText = text;
58
59 string[] guids = AssetDatabase.FindAssets($"t:AudioClip {id}", new[] {$"{VoiceOverDataPath}/Clips"});
60
61 AudioClip clip = null;
62
63 foreach (string guid in guids)
64 {
65 var fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(guid));
66
67 if (fileName == id)
68 {
69 clip = AssetDatabase.LoadAssetAtPath<AudioClip>(AssetDatabase.GUIDToAssetPath(guid));
70 }
71 }
72
73 if (clip != null)
74 {
75 info.voiceOver = clip;
76 }
77 else
78 {
79 Debug.LogWarning("No audio clip for " + id);
80 }
81 }
82
83 EditorUtility.SetDirty(asset);
84 }
85 }
86#endif
87}
Data that stores all information about voice overs.
[System.Serializable]
static List< List< string > > LoadFromPath(string path, Delimiter delimiter=Delimiter.Auto, Encoding encoding=null)
Load CSV data from specified path.
Definition CSVParser.cs:27