void OnEnable() { currentModules = new List <AutoSyncModule>(); serializedModules = new List <Editor>(); clips = new List <AudioClip>(); autoSyncModuleTypes = AutoSyncUtility.GetModuleTypes(); presets = AutoSyncUtility.GetPresets(); moduleInfos = new Dictionary <Type, AutoSyncModuleInfoAttribute>(); for (int i = 0; i < autoSyncModuleTypes.Count; i++) { moduleInfos.Add(autoSyncModuleTypes[i], AutoSyncUtility.GetModuleInfo(autoSyncModuleTypes[i])); } infoIcon = EditorGUIUtility.FindTexture("console.infoicon.sml"); if (EditorGUIUtility.isProSkin) { upIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Dark/up.png"); downIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Dark/down.png"); plusIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Dark/plus.png"); minusIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Dark/minus.png"); saveIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Dark/save.png"); } else { upIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Light/up.png"); downIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Light/down.png"); plusIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Light/plus.png"); minusIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Light/minus.png"); saveIcon = (Texture2D)EditorGUIUtility.Load("Rogo Digital/LipSync/Light/save.png"); } }
void OnGUI() { EditorStyles.label.wordWrap = true; GUILayout.Space(10); tab = GUILayout.Toolbar(tab, new string[] { "AutoSync Settings", "Batch Process" }); GUILayout.Space(10); bool ready = true; if (tab == 0) { ready = currentModules.Count > 0; GUILayout.Space(5); GUILayout.Box("Presets", EditorStyles.boldLabel); GUILayout.Space(5); presetScroll = GUILayout.BeginScrollView(presetScroll, GUILayout.MaxHeight(80)); if (presets.Length == 0) { GUILayout.Space(10); GUILayout.Box("No Presets Found", EditorStyles.centeredGreyMiniLabel); } else { EditorGUILayout.BeginVertical(); for (int i = -1; i < presets.Length; i++) { var lineRect = EditorGUILayout.BeginHorizontal(); if (i == presetHighlight) { GUI.Box(lineRect, "", (GUIStyle)"SelectionRect"); } if (i >= 0) { if (GUILayout.Button(presets[i].displayName, EditorStyles.label)) { LoadPreset(i); } } else { if (GUILayout.Button("None", EditorStyles.label)) { LoadPreset(-1); } } EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); } GUILayout.EndScrollView(); GUILayout.Space(5); var infoRect = EditorGUILayout.BeginVertical(GUILayout.ExpandHeight(true)); GUI.Box(infoRect, "", EditorStyles.helpBox); GUILayout.Space(5); if (presetHighlight == -1) { GUILayout.Box(new GUIContent("Select a preset for more information.", infoIcon), EditorStyles.label); } else { GUILayout.Box(presets[presetHighlight].displayName, EditorStyles.boldLabel); EditorGUILayout.LabelField(presets[presetHighlight].description, EditorStyles.label); GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.Space(5); EditorGUILayout.EndVertical(); GUILayout.Space(5); Rect toolbarRect = EditorGUILayout.BeginHorizontal(); toolbarRect.x = 0; GUI.Box(toolbarRect, "", EditorStyles.toolbar); GUILayout.Box("Current Modules", EditorStyles.miniLabel); GUILayout.FlexibleSpace(); Rect dropDownRect = EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Add", plusIcon, "Add a new module to the list"), EditorStyles.toolbarDropDown, GUILayout.Width(70))) { GenericMenu addMenu = new GenericMenu(); for (int i = 0; i < autoSyncModuleTypes.Count; i++) { bool isAdded = false; for (int m = 0; m < currentModules.Count; m++) { if (currentModules[m].GetType() == autoSyncModuleTypes[i]) { isAdded = true; break; } } if (isAdded) { addMenu.AddDisabledItem(new GUIContent(moduleInfos[autoSyncModuleTypes[i]].displayName)); } else { int e = i; addMenu.AddItem(new GUIContent(moduleInfos[autoSyncModuleTypes[i]].displayName), false, () => { AddModule(e); }); } } addMenu.AddSeparator(""); addMenu.AddItem(new GUIContent("Get More Modules"), false, () => { RDExtensionWindow.ShowWindow("LipSync_Pro"); }); addMenu.DropDown(dropDownRect); } if (GUILayout.Button(new GUIContent("New Preset", saveIcon, "Save the current setup as a new preset"), EditorStyles.toolbarButton, GUILayout.Width(90))) { var savePath = EditorUtility.SaveFilePanelInProject("Save AutoSync Preset", "New AutoSync Preset", "asset", ""); if (!string.IsNullOrEmpty(savePath)) { AutoSyncPreset preset = null; if (File.Exists(savePath)) { preset = AssetDatabase.LoadAssetAtPath <AutoSyncPreset>(savePath); } else { preset = CreateInstance <AutoSyncPreset>(); preset.CreateFromModules(currentModules.ToArray()); preset.displayName = Path.GetFileNameWithoutExtension(savePath); preset.description = "Using: "; for (int i = 0; i < currentModules.Count; i++) { preset.description += currentModules[i].GetType().Name; if (i < currentModules.Count - 1) { preset.description += ", "; } } } AssetDatabase.CreateAsset(preset, savePath); AssetDatabase.Refresh(); presets = AutoSyncUtility.GetPresets(); presetHighlight = -1; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(); settingsScroll = GUILayout.BeginScrollView(settingsScroll, false, false); if (currentModules.Count == 0) { GUILayout.Space(10); GUILayout.Box("No Modules Added", EditorStyles.centeredGreyMiniLabel); } else { for (int i = 0; i < currentModules.Count; i++) { var type = currentModules[i].GetType(); var info = moduleInfos[type]; GUILayout.BeginHorizontal(); GUILayout.Space(10); GUILayout.Box(new GUIContent(info.displayName, infoIcon, info.description), EditorStyles.label); GUILayout.Space(10); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(15)); GUILayout.Space(10); if (GUILayout.Button(new GUIContent(minusIcon, "Remove Module"))) { DestroyImmediate(serializedModules[i]); DestroyImmediate(currentModules[i]); serializedModules.RemoveAt(i); currentModules.RemoveAt(i); break; } GUILayout.Space(5); EditorGUI.BeginDisabledGroup(i == 0); if (GUILayout.Button(new GUIContent(upIcon, "Move Up"))) { currentModules.Insert(i - 1, currentModules[i]); currentModules.RemoveAt(i + 1); serializedModules.Insert(i - 1, serializedModules[i]); serializedModules.RemoveAt(i + 1); break; } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(i + 2 > currentModules.Count); if (GUILayout.Button(new GUIContent(downIcon, "Move Down"))) { currentModules.Insert(i + 2, currentModules[i]); currentModules.RemoveAt(i); serializedModules.Insert(i + 2, serializedModules[i]); serializedModules.RemoveAt(i); break; } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.BeginVertical(); var missing = GetMissingClipFeaturesInClipEditor(currentModules, i); if (missing != ClipFeatures.None) { EditorGUILayout.HelpBox(string.Format("This module requires: {0}.\n These features must either be present in the clip already, or be provided by a module above this one.", missing), MessageType.Error); } serializedModules[i].OnInspectorGUI(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.Space(15); } } GUILayout.FlexibleSpace(); GUILayout.Space(5); GUILayout.EndScrollView(); EditorGUILayout.EndVertical(); GUILayout.Space(5); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(!ready); if (GUILayout.Button("Start Single Process", GUILayout.Height(25))) { if (autoSyncInstance == null) { autoSyncInstance = new AutoSync(); } autoSyncInstance.RunSequence(currentModules.ToArray(), FinishedProcessingSingle, (LipSyncData)setup.data); } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(20); } else { ready = clips.Count > 0 && currentModules.Count > 0; GUILayout.Space(5); GUILayout.Box("Select AudioClips", EditorStyles.boldLabel); GUILayout.Space(5); batchScroll = GUILayout.BeginScrollView(batchScroll); for (int a = 0; a < clips.Count; a++) { GUILayout.BeginHorizontal(); GUILayout.Space(5); clips[a] = (AudioClip)EditorGUILayout.ObjectField(clips[a], typeof(AudioClip), false); GUILayout.FlexibleSpace(); if (GUILayout.Button("Remove", GUILayout.MaxWidth(200))) { clips.RemoveAt(a); break; } GUILayout.Space(5); GUILayout.EndHorizontal(); } GUILayout.Space(5); GUILayout.EndScrollView(); GUILayout.Space(5); GUILayout.BeginHorizontal(); if (GUILayout.Button("Add AudioClip")) { clips.Add(null); } if (GUILayout.Button("Add Selected")) { foreach (AudioClip c in Selection.GetFiltered(typeof(AudioClip), SelectionMode.Assets)) { if (!clips.Contains(c)) { clips.Add(c); } } } GUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.HelpBox("Settings from the AutoSync Settings tab will be used. Make sure they are correct.", MessageType.Info); xmlMode = EditorGUILayout.Toggle("Export as XML", xmlMode); loadTranscripts = EditorGUILayout.Toggle("Load Transcripts .txt", loadTranscripts); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); EditorGUI.BeginDisabledGroup(!ready); if (GUILayout.Button("Start Batch Process", GUILayout.Height(25))) { currentClip = 0; if (clips.Count > 0) { if (autoSyncInstance == null) { autoSyncInstance = new AutoSync(); } LipSyncData tempData = CreateInstance <LipSyncData>(); tempData.clip = clips[currentClip]; tempData.length = tempData.clip.length; if (loadTranscripts) { tempData.transcript = AutoSyncUtility.TryGetTranscript(tempData.clip); } autoSyncInstance.RunSequence(currentModules.ToArray(), FinishedProcessingMulti, tempData); } else { ShowNotification(new GUIContent("No clips added for batch processing!")); } } EditorGUI.EndDisabledGroup(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(20); } }