public void CreateNewAnimation(bool isAudioBased, int audioFileIndex, string newAnimFileName, float newTime) { if (newAnimFileName != "") { string newAudioName = ""; if (isAudioBased) { newAudioName = tagarela.audioFiles[audioFileIndex].name; } TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.smrTotal); guiTimeline = new TagarelaTimelineUI(newTime); guiTimeline.AddKeyframe(0f, _MorphTarget); guiTimelineSegment = new TagarelaTimelineSegmentUI(newTime); if (TagarelaFileManager.Save(newAnimFileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, newAudioName, newTime)) { TextAsset newFile = AssetDatabase.LoadMainAssetAtPath("Assets/Tagarela/System/Animations/" + newAnimFileName + ".xml") as TextAsset; AssetDatabase.Refresh(); tagarela.Clean(); tagarela.animationFiles.Add(newFile); CleanVars(); dialog = ScreenDialog.InitialScreen; Repaint(); Update(); LoadAnimationFile(tagarela.animationFiles[tagarela.animationFiles.Count - 1]); } } }
/// <summary> /// Create a <c>ScreenDialog</c> object, assign it to a parent <c>Component</c> and return it. /// </summary> /// <param name="parent">The dialog's supposed parent.</param> /// <param name="name">The Unity name of this dialog.</param> /// <param name="label">What is written in the header of the dialog.</param> /// <returns>The created <c>ScreenDialog</c></returns> public static ScreenDialog CreateCustomDialog(Component parent, string name, string label) { ScreenDialog dialog = GameObject.Instantiate(dialogTemplate, parent.transform); dialog.name = name; dialog.GetComponentInChildren <TextMeshProUGUI>().text = label; return(dialog); }
IEnumerator teste() { yield return(new WaitForSeconds(3)); LoadAnimationFile(tagarela.animationFiles[tagarela.animationFiles.Count - 1]); dialog = ScreenDialog.Timeline; Repaint(); }
/// <summary> /// Try to get the <c>ICustomDialogInputListener</c> assigned to the specified <c>ScreenDialog</c>. /// </summary> /// <remarks> /// Returns <c>null</c> if it cannot find an entry. Currently unused. /// </remarks> /// <param name="dialog">The key dialog.</param> /// <returns>The assigned <c>ICustomDialogInputListener</c> or <c>null</c> no key /// could be found</returns> public static ICustomDialogInputListener GetCustomDialogInputListener(ScreenDialog dialog) { ICustomDialogInputListener listener; if (listeners.TryGetValue(dialog, out listener)) { return(listener); } return(null); }
public static void Postfix(ref bool __result, ref ScreenDialog __instance, ref CoreInputControlMapping mapping, ref IGameUIComponent triggeredUI, ref InputManager.Controls triggeredMappingID) { // Check if there's a custom input listener assigned to this dialog. If that is the case, invoke its // ApplyScreenInput. ICustomDialogInputListener listener = CustomUIManager.GetCustomDialogInputListener(__instance); if (listener != null) { __result = listener.ApplyScreenInput(mapping, triggeredUI, triggeredMappingID); } }
/// <summary> /// Reinitalize the dialog. Use this if the dialog has already been created, but the UI elements have been /// destroyed due to a screen transition. /// </summary> /// <param name="parent">The container for this dialog, see <see cref="RunFilterDialog.RunFilterDialog"/></param> public void Reinit(RunHistoryScreen parent) { this.dialog = CustomUIManager.CreateCustomDialog(parent, "FilterDialog", "Run Data Filters"); content = dialog.transform.Find("Content"); dropdowns = new List <GameUISelectableDropdown>(); sliders = new List <SelectableSliderHelper>(); MakeOutcomeFilter(firstColumn, firstLine); MakeRunTypeFilter(firstColumn, firstLine + lineHeight); MakeCovenantFilter(firstColumn, firstLine + lineHeight * 2); MakeClanFilter(firstColumn, firstLine + lineHeight * 4); MakeProgressFilter(firstColumn, firstLine + lineHeight * 6); }
/// <summary> /// Initalize a bunch of UI element templates: a dialog, a button, a dropdown menu, a slider, a toggle button and /// a label. /// </summary> /// <remarks> /// This method needs to be called before trying to instantiate any UI elements with <c>CreateCustomXXX</c> /// methods, otherwise those will throw unchecked NullPointerExceptions (I should probably handle those better). /// Currently, this is achieved by the <see cref="InitCustomUIElementsPatch"/>. Also, once it has been called, /// another call to this method has no effect. /// </remarks> /// <param name="settingsScreen">The settings screen. Using this to store the dialog template so that it doesn't /// get unloaded. There's probably a less hacky way to do this.</param> /// <param name="dialog">The dialog to be used as a template.</param> /// <param name="settingsDialog">The Settings Dialog, used to get a variety of UI elements.</param> public static void InitalizeTemplates(SettingsScreen settingsScreen, ScreenDialog dialog, SettingsDialog settingsDialog) { // This only needs to run once. if (!AreTemplatesInitalized()) { initalized = true; // Just store a bunch of UI elements from the settings screen as templates. They will always be loaded, // so we don't have to care about manipulating them in any way yet. buttonTemplate = Traverse.Create(settingsDialog).Field("keyMappingButton").GetValue <GameUISelectableButton>(); dropdownTemplate = Traverse.Create(settingsDialog).Field("gameSpeedDropdown").GetValue <GameUISelectableDropdown>();; toggleTemplate = Traverse.Create(settingsDialog).Field("googlyEyesToggle").GetValue <GameUISelectableToggle>(); sliderTemplate = Traverse.Create(Traverse.Create(settingsDialog).Field("scrollSensitivityControl").GetValue <ScrollSensitivityControl>()).Field("slider").GetValue <SelectableSliderHelper>(); // There don't seem to be any labels that are assigned to explicit fields, which kinda makes sense, so we'll have to search for one. // This unfortunately breaks pretty easily as shown by the latest update of the game, so I guess we need a long term solution. labelTemplate = settingsDialog.transform.Find("Content/Content/Audio Section/Global volume control").GetComponentInChildren <TextMeshProUGUI>(); // Print warnings if any initalization has been unsuccessful. if (buttonTemplate == null) { AdvancedRunHistory.Log("Button template is null.", LogLevel.Warning); } if (dropdownTemplate == null) { AdvancedRunHistory.Log("Dropdown template is null.", LogLevel.Warning); } if (toggleTemplate == null) { AdvancedRunHistory.Log("Toggle template is null.", LogLevel.Warning); } if (sliderTemplate == null) { AdvancedRunHistory.Log("Slider template is null.", LogLevel.Warning); } if (labelTemplate == null) { AdvancedRunHistory.Log("Label template is null.", LogLevel.Warning); } // We actually neeed to instantiate a copy of the dialog template right now, as the Patch Notes dialog will // unload as soon as you leave the Main Menu screen. Also, we can remove its contents while we're at it. dialogTemplate = GameObject.Instantiate(dialog, settingsScreen.transform); foreach (Transform child in dialogTemplate.transform.Find("Content")) { GameObject.Destroy(child.gameObject); } if (dialogTemplate == null) { AdvancedRunHistory.Log("Dialog template is null.", LogLevel.Warning); } } }
void SelectObject() { bool hasTagarela = (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent <Tagarela>()); if (hasTagarela) { if (settings == null || guiTimeline == null || tagarela == null || tagarela.settings == null) { BackupOriginalMesh(); tagarela.Clean(); dialog = ScreenDialog.InitialScreen; } else if (lastSelectionGameObjectEditing == Selection.activeGameObject) { if (settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { dialog = ScreenDialog.InitialScreen; } } } else if (Selection.objects.Length != 0) { log_msg = "Invalid Object: There is no Tagarela Component"; dialog = ScreenDialog.InvalidObject; playMode = PlayMode.stopped; RestoreOriginalMesh(); } else if (Selection.objects.Length == 0) { if (lastSelectionGameObjectEditing != null && settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { Close(); } } }
public static void Postfix(ref MainMenuScreen __instance) { // We only need to do this once. In fact, not checking this probably results in the game freezing due // to an infinite recursion. if (!CustomUIManager.AreTemplatesInitalized()) { // Find the current ScreenManager to access the Settigns Screen and Settings Dialog, as the Settings // Dialog contains a lot of UI elements and is helpful in creating templates. ScreenManager screenManager = Traverse.Create(Traverse.Create(__instance).Field("gameStateManager").GetValue <GameStateManager>()).Field("screenManager").GetValue <ScreenManager>(); SettingsScreen settingsScreen = (SettingsScreen)screenManager.GetScreen(ScreenName.Settings); SettingsDialog settingsDialog = Traverse.Create(settingsScreen).Field("settingsDialog").GetValue <SettingsDialog>(); // We need to actually open the Settings Dialog in order for the UI elements to initalize correctly. screenManager.ShowScreen(ScreenName.Settings); settingsDialog.Open(); settingsDialog.Close(); // Use the Patch Notes Dialog as a template for custom dialogs PatchNotesUI patch = Traverse.Create(__instance).Field("patchNotesDialog").GetValue <PatchNotesUI>(); ScreenDialog dialogTemplate = Traverse.Create(patch).Field("dialog").GetValue <ScreenDialog>(); CustomUIManager.InitalizeTemplates(settingsScreen, dialogTemplate, settingsDialog); // Pretend that nothing has happend and return to the main menu. screenManager.ReturnToMainMenu(); } }
void OnGUI() { updateWindow = false; GUI.color = Color.white; GUI.DrawTexture(new Rect(0, 0, Screen.width, bgEditor.height), bgEditor); GUI.DrawTexture(new Rect(13, 14, logoEditor.width, logoEditor.height), logoEditor); GUILayout.BeginVertical(styleHeader); { GUI.color = Color.white; switch (dialog) { case ScreenDialog.InvalidObject: GUILayout.Label(log_msg, EditorStyles.boldLabel); break; case ScreenDialog.AddComponent: GUILayout.Label("", EditorStyles.boldLabel); GUILayout.Space(15f); if (GUILayout.Button("Add LipSync Component!")) { //Debug.Log("UnityLipSync -> LipSync Component created on " + LastSelected.name); Selection.activeGameObject.AddComponent(typeof(Tagarela)); } break; case ScreenDialog.InitialScreen: GUILayout.BeginHorizontal(); GUILayout.Label("Select Animation", styleFileTitle, GUILayout.Height(22)); if (GUILayout.Button("Create New Animation", styleBigButtons, new GUILayoutOption[] { GUILayout.Width(150), GUILayout.Height(18) })) { TagarelaEditorPopupNewFile popupNewFile = CreateInstance<TagarelaEditorPopupNewFile>(); popupNewFile.parent = this; RefreshAudiolist(); popupNewFile.audioList = audioList; popupNewFile.tagarela = tagarela; popupNewFile.ShowAuxWindow(); } GUILayout.Space(8f); GUILayout.EndHorizontal(); scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview); { GUILayout.BeginVertical(); { GUILayout.Space(15f); if (tagarela.animationFiles.Count > 0) { GUILayout.BeginVertical(styleGrid); { for (int i = tagarela.animationFiles.Count - 1; i >= 0 ; i--) { GUILayout.BeginHorizontal(); { //CLICK TO OPEN FILE if (GUILayout.Button(tagarela.animationFiles[i].name.ToString(), styleButtonGrid, GUILayout.Height(20))) { LoadAnimationFile(tagarela.animationFiles[i]); } } GUILayout.EndHorizontal(); } } GUILayout.EndHorizontal(); } GUI.color = Color.white; GUILayout.FlexibleSpace(); } //end vertical GUILayout.EndVertical(); } GUILayout.EndScrollView(); break; case ScreenDialog.Timeline: GUILayout.BeginHorizontal(); { GUILayout.Label(fileName, styleFileTitle, GUILayout.Height(21)); if (GUILayout.Button("Save", styleBigButtons, GUILayout.Width(70))) { string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; TagarelaFileManager.Save(fileName, tagarela.morphTargets, guiTimeline.keyframeSet, tagarela.neutralMesh.vertexCount, audioName, tagarela.settings.animationTime); } if (GUILayout.Button("Close", styleBigButtons, GUILayout.Width(70))) { switch (EditorUtility.DisplayDialogComplex("Close", "Do you want to save? ", "Yes", "No", "Cancel")) { case 0: updateTimeline = true; string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; TagarelaFileManager.Save(fileName, tagarela.morphTargets, guiTimeline.keyframeSet, tagarela.neutralMesh.vertexCount, audioName, tagarela.settings.animationTime); if (tagarela != null) tagarela.Clean(); CleanVars(); dialog = ScreenDialog.InitialScreen; break; case 1: if (tagarela != null) tagarela.Clean(); CleanVars(); dialog = ScreenDialog.InitialScreen; break; } } } GUILayout.EndHorizontal(); updateMorph = false; //###################################################################################### GUILayout.BeginVertical(styleBgTimeline, GUILayout.Height(bgTimeline.height)); { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (SelectedAudioclip != null) { GUILayout.Label(SelectedAudioclip.name); } GUILayout.FlexibleSpace(); GUILayout.Space(20); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (settings != null) GUILayout.Label(guiTimeline.selectedValue.ToString("0.000") + " / " + settings.animationTime.ToString("0.000")); } GUILayout.EndHorizontal(); GUILayout.Space(5); } GUILayout.EndHorizontal(); //scrollViewTimelineVector = GUILayout.BeginScrollView(scrollViewTimelineVector, styleScrollviewTimeline); //{ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Width(1040f) }); { GUILayout.Box("", new GUIStyle(), GUILayout.ExpandWidth(true)); Rect lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.width > 1) { guiTimeline.Draw(new Rect(lastRect.x, 124, lastRect.width, 57)); if (audioPreviewSpectrum != null) GUI.DrawTexture(new Rect(lastRect.x, 125, lastRect.width, 40), audioPreviewSpectrum); guiTimelineSegment.Draw(new Rect(lastRect.x + 2, 125, lastRect.width - 2, 130)); } switch (playMode) { case PlayMode.all: GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f); GUI.DrawTexture(new Rect(guiTimeline.timeLineRect.x + 1, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width) * timeNormalized, 11), EditorGUIUtility.whiteTexture); break; case PlayMode.segment: GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f); GUI.DrawTexture(new Rect(guiTimelineSegment.KeyframeSet[0].IconRect.x + 7, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width - 18) * timeNormalized, 11), EditorGUIUtility.whiteTexture); break; } } GUILayout.EndHorizontal(); GUI.color = Color.white; //} //GUILayout.EndScrollView(); GUILayout.Space(67); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (guiTimeline.keyframeSet.Count == 1 || disableGuiControls) GUI.enabled = false; if (GUILayout.Button(icoRemove, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) //btRemove { guiTimeline.RemoveKeyframe(guiTimeline.selectedIndex); } GUI.enabled = true; if (disableGuiControls) GUI.enabled = false; if (GUILayout.Button(icoAdd, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) //btAdd { TagarelaMorphTarget _morphTargetList = new TagarelaMorphTarget(); _morphTargetList.Populate(tagarela.morphTargets); guiTimeline.AddKeyframe(0.0f, _morphTargetList); updateTimeline = true; updateMorph = true; } } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Sliders to zero", styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(120), GUILayout.Height(20) })) //btAdd { TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders; if (_MorphTarget != null) { for (int i = 0; i < _MorphTarget.id.Count; i++) { _MorphTarget.sliderValue[i] = 0; } } updateTimeline = true; } GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { GUI.enabled = !disableGuiControls; if (GUILayout.Button(icoPlay, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { //tagarela.setTimer(0); playMode = PlayMode.all; } GUI.enabled = true; if (!guiTimelineSegment.active || disableGuiControls) GUI.enabled = false; if (GUILayout.Button(icoPlaySegment, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { tagarela.setTimer(guiTimelineSegment.KeyframeSet[0].Value); playMode = PlayMode.segment; } GUI.enabled = false; if (!playMode.Equals(PlayMode.stopped)) GUI.enabled = true; if (GUILayout.Button(icoStop, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { //tagarela.audio.loop = false; tagarela.setTimer(0f); //tagarela.audio.Stop(); playMode = PlayMode.stopped; if (tagarela.audio.isPlaying) tagarela.audio.Stop(); } //if don´t have any audio, is a time based animation if (SelectedAudioclip == null) { GUI.enabled = !disableGuiControls; GUILayout.Space(10); if (GUILayout.Button(icoClock, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { TagarelaEditorPopupTimeLength popupAnimLength = CreateInstance<TagarelaEditorPopupTimeLength>(); popupAnimLength.parent = this; popupAnimLength.title = "Time Settings"; popupAnimLength.currentLength = popupAnimLength.newLength = guiTimeline.totalValue; popupAnimLength.ShowAuxWindow(); }; } GUI.enabled = true; } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUI.enabled = !disableGuiControls; scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview); { if (tagarela.morphTargets.Count > 0 && guiTimeline.selectedIndex != -1 && guiTimeline.keyframeSet.Count > 0) { EditorGUILayout.BeginVertical(); { //seleciona a lista de acordo com o index selecionado TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders; GUI.color = GUI.contentColor; if (_MorphTarget != null) { //GUILayout.Space(13f); GUILayout.Space(14); //space before slider list for (int i = 0; i < _MorphTarget.id.Count; i++) { EditorGUILayout.BeginHorizontal(styleBgSlider, GUILayout.ExpandWidth(true)); { float temp_value = _MorphTarget.sliderValue[i]; GUILayout.Label(_MorphTarget.id[i], GUILayout.Width(150)); temp_value = GUILayout.HorizontalSlider(temp_value, 0, 100, GUILayout.ExpandWidth(true)); if (_MorphTarget.sliderValue[i] != temp_value) { _MorphTarget.sliderValue[i] = temp_value; updateTimeline = true; } } EditorGUILayout.EndHorizontal(); } } } EditorGUILayout.EndVertical(); } if (guiTimeline.refresh) updateWindow = true; if (guiTimeline.isDragging) { guiTimelineSegment.isDragging = false; guiTimelineSegment.enabled = false; if (updateMorphValue != guiTimeline.selectedValue && SelectedAudioclip != null) { playMode = PlayMode.currentTime; updateMorphValue = guiTimeline.selectedValue; } } if (guiTimeline.enabled && (guiTimeline.selectedIndex == -1 || lastKeyframeSelected != guiTimeline.selectedIndex)) { lastKeyframeSelected = guiTimeline.selectedIndex; updateMorphValue = guiTimeline.selectedValue; updateTimeline = true; } //if a new keyframe was create or cloned, call a update om mesh list if (guiTimeline.isKeyframeSetChanged) { lastKeyframeSelected = -1; guiTimeline.isKeyframeSetChanged = false; updateTimeline = true; updateMorph = true; } if (guiTimelineSegment.refresh) updateWindow = true; if (guiTimelineSegment.isDragging) { guiTimeline.isDragging = false; guiTimeline.enabled = false; if (updateMorphValue != guiTimelineSegment.SelectedValue) { playMode = PlayMode.currentTime; updateMorphValue = guiTimelineSegment.SelectedValue; updateMorph = true; } } if (!guiTimelineSegment.isDragging && !guiTimeline.isDragging) { guiTimelineSegment.enabled = true; guiTimeline.enabled = true; } if (playMode.Equals(PlayMode.all) || playMode.Equals(PlayMode.segment)) { guiTimeline.enabled = false; } } GUILayout.EndScrollView(); GUI.enabled = true; break; } } GUILayout.EndVertical(); if (updateWindow || tagarela != null && tagarela.isPlaying) Repaint(); }
public void LoadAnimationFile(TextAsset file) { //RefreshMeshlist(); RefreshAudiolist(); tagarela.Clean(); CleanVars(); settings = TagarelaFileManager.Load(file); lastSelectionGameObjectEditing = Selection.activeGameObject; fileName = file.name; guiTimeline = new TagarelaTimelineUI(settings.animationTime); audioPreviewSpectrum = null; SelectedAudioclip = null; tagarela.audio.clip = null; tagarela.isPlaying = false; playMode = PlayMode.stopped; if (settings.audioFile != null) { for (int i = 0; i < tagarela.audioFiles.Count; i++) { if (settings.audioFile == tagarela.audioFiles[i].name) { SelectedAudioclip = tagarela.audioFiles[i]; tagarela.audio.clip = tagarela.audioFiles[i]; audioPreviewSpectrum = TagarelaAudioSpectrum.CreatePreview(SelectedAudioclip, 1024, 64, new Color(150f / 255f, 200f / 255f, 25f / 255f, 0.8f), TagarelaAudioSpectrum.PreviewType.both); audioPreviewSpectrum.hideFlags = HideFlags.DontSave; } } } // CARREGA O ARQUIVO XML //configurações principais if (settings.meshList.id != null) { guiTimeline.keyframeSet = new List<TagarelaTimelineUI.TLkeyframe>(); for (int i = 0; i < settings.keyframes.values.Length; i++) { TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.morphTargets); for (int j = 0; j < settings.keyframes.sliderSettings[i].Length; j++) { float[] sliders = settings.keyframes.sliderSettings[i]; if (j < tagarela.morphTargets.Count) { //tagarela.morphTargets[j].hideFlags = HideFlags.DontSave; _MorphTarget.sliderValue[j] = sliders[j]; } } guiTimeline.AddKeyframe(settings.keyframes.values[i], _MorphTarget); } } else { guiTimeline.keyframeSet = new List<TagarelaTimelineUI.TLkeyframe>(); TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.morphTargets); guiTimeline.AddKeyframe(0f, _MorphTarget); } //Update the file settings settings = TagarelaFileManager.UpdateSettings(tagarela.morphTargets, guiTimeline.keyframeSet, tagarela.neutralMesh.vertexCount, settings.audioFile, guiTimeline.totalValue); guiTimelineSegment = new TagarelaTimelineSegmentUI(settings.animationTime); tagarela.OpenFile(file); timeNormalized = 0f; playMode = PlayMode.stopped; lastKeyframeSelected = -1; lastKeyframeSelected = guiTimeline.selectedIndex; updateMorphValue = guiTimeline.selectedValue; updateTimeline = true; if (settings != null && Selection.objects.Length == 1) { dialog = ScreenDialog.Timeline; } }
public void CreateNewAnimation(bool isAudioBased, int audioFileIndex, string newAnimFileName, float newTime) { if (newAnimFileName != "") { string newAudioName = ""; if (isAudioBased) newAudioName = tagarela.audioFiles[audioFileIndex].name; TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.morphTargets); guiTimeline = new TagarelaTimelineUI(newTime); guiTimeline.AddKeyframe(0f, _MorphTarget); guiTimelineSegment = new TagarelaTimelineSegmentUI(newTime); if (TagarelaFileManager.Save(newAnimFileName, tagarela.morphTargets, guiTimeline.keyframeSet, tagarela.neutralMesh.vertexCount, newAudioName, newTime)) { TextAsset newFile = AssetDatabase.LoadMainAssetAtPath("Assets/Tagarela/System/Animations/" + newAnimFileName + ".xml") as TextAsset; AssetDatabase.Refresh(); tagarela.Clean(); tagarela.animationFiles.Add(newFile); CleanVars(); dialog = ScreenDialog.InitialScreen; Repaint(); Update(); LoadAnimationFile(tagarela.animationFiles[tagarela.animationFiles.Count - 1]); } } }
public void LoadAnimationFile(TextAsset file) { RefreshAudiolist(); tagarela.Clean(); CleanVars(); settings = TagarelaFileManager.Load(file); lastSelectionGameObjectEditing = Selection.activeGameObject; fileName = file.name; guiTimeline = new TagarelaTimelineUI(settings.animationTime); audioPreviewSpectrum = null; SelectedAudioclip = null; tagarela.audio.clip = null; tagarela.isPlaying = false; playMode = PlayMode.stopped; if (settings.audioFile != null) { for (int i = 0; i < tagarela.audioFiles.Count; i++) { if (settings.audioFile == tagarela.audioFiles[i].name) { SelectedAudioclip = tagarela.audioFiles[i]; tagarela.audio.clip = tagarela.audioFiles[i]; audioPreviewSpectrum = TagarelaAudioSpectrum.CreatePreview(SelectedAudioclip, 1024, 64, new Color(150f / 255f, 200f / 255f, 25f / 255f, 0.8f), TagarelaAudioSpectrum.PreviewType.both); audioPreviewSpectrum.hideFlags = HideFlags.DontSave; } } } // CARREGA O ARQUIVO XML //configurações principais if (settings.meshList.id != null) { guiTimeline.keyframeSet = new List <TagarelaTimelineUI.TLkeyframe>(); for (int i = 0; i < settings.keyframes.values.Length; i++) { TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.smrTotal); for (int j = 0; j < settings.keyframes.sliderSettings[i].Length; j++) { float[] sliders = settings.keyframes.sliderSettings[i]; if (j < tagarela.smrTotalBlendShapesCount) { //tagarela.morphTargets[j].hideFlags = HideFlags.DontSave; _MorphTarget.sliderValue[j] = sliders[j]; } } guiTimeline.AddKeyframe(settings.keyframes.values[i], _MorphTarget); } } else { guiTimeline.keyframeSet = new List <TagarelaTimelineUI.TLkeyframe>(); TagarelaMorphTarget _MorphTarget = new TagarelaMorphTarget(); _MorphTarget.Populate(tagarela.smrTotal); guiTimeline.AddKeyframe(0f, _MorphTarget); } //Update the file settings settings = TagarelaFileManager.UpdateSettings(tagarela.smrTotal, guiTimeline.keyframeSet, 0, settings.audioFile, guiTimeline.totalValue); guiTimelineSegment = new TagarelaTimelineSegmentUI(settings.animationTime); tagarela.OpenFile(file); timeNormalized = 0f; playMode = PlayMode.stopped; lastKeyframeSelected = -1; lastKeyframeSelected = guiTimeline.selectedIndex; updateMorphValue = guiTimeline.selectedValue; updateTimeline = true; if (settings != null && Selection.objects.Length == 1) { dialog = ScreenDialog.Timeline; } }
void OnGUI() { updateWindow = false; GUI.color = Color.white; GUI.DrawTexture(new Rect(0, 0, Screen.width, bgEditor.height), bgEditor); GUI.DrawTexture(new Rect(13, 14, logoEditor.width, logoEditor.height), logoEditor); GUILayout.BeginVertical(styleHeader); { GUI.color = Color.white; switch (dialog) { case ScreenDialog.InvalidObject: GUILayout.Label(log_msg, EditorStyles.boldLabel); break; case ScreenDialog.AddComponent: GUILayout.Label("", EditorStyles.boldLabel); GUILayout.Space(15f); if (GUILayout.Button("Add LipSync Component!")) { //Debug.Log("UnityLipSync -> LipSync Component created on " + LastSelected.name); Selection.activeGameObject.AddComponent(typeof(Tagarela)); } break; case ScreenDialog.InitialScreen: GUILayout.BeginHorizontal(); GUILayout.Label("Select Animation", styleFileTitle, GUILayout.Height(22)); if (GUILayout.Button("Create New Animation", styleBigButtons, new GUILayoutOption[] { GUILayout.Width(150), GUILayout.Height(18) })) { TagarelaEditorPopupNewFile popupNewFile = CreateInstance <TagarelaEditorPopupNewFile>(); popupNewFile.parent = this; RefreshAudiolist(); popupNewFile.audioList = audioList; popupNewFile.tagarela = tagarela; popupNewFile.ShowAuxWindow(); } GUILayout.Space(8f); GUILayout.EndHorizontal(); scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview); { GUILayout.BeginVertical(); { GUILayout.Space(15f); if (tagarela.animationFiles.Count > 0) { GUILayout.BeginVertical(styleGrid); { for (int i = tagarela.animationFiles.Count - 1; i >= 0; i--) { GUILayout.BeginHorizontal(); { //CLICK TO OPEN FILE if (GUILayout.Button(tagarela.animationFiles[i].name.ToString(), styleButtonGrid, GUILayout.Height(20))) { LoadAnimationFile(tagarela.animationFiles[i]); } } GUILayout.EndHorizontal(); } } GUILayout.EndHorizontal(); } GUI.color = Color.white; GUILayout.FlexibleSpace(); } //end vertical GUILayout.EndVertical(); } GUILayout.EndScrollView(); break; case ScreenDialog.Timeline: GUILayout.BeginHorizontal(); { GUILayout.Label(fileName, styleFileTitle, GUILayout.Height(21)); if (GUILayout.Button("Save", styleBigButtons, GUILayout.Width(70))) { string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; TagarelaFileManager.Save(fileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, audioName, tagarela.settings.animationTime); } if (GUILayout.Button("Close", styleBigButtons, GUILayout.Width(70))) { switch (EditorUtility.DisplayDialogComplex("Close", "Do you want to save? ", "Yes", "No", "Cancel")) { case 0: updateTimeline = true; string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; TagarelaFileManager.Save(fileName, tagarela.smrTotal, guiTimeline.keyframeSet, 0, audioName, tagarela.settings.animationTime); if (tagarela != null) { tagarela.Clean(); } CleanVars(); dialog = ScreenDialog.InitialScreen; break; case 1: if (tagarela != null) { tagarela.Clean(); } CleanVars(); dialog = ScreenDialog.InitialScreen; break; } } } GUILayout.EndHorizontal(); updateMorph = false; //###################################################################################### GUILayout.BeginVertical(styleBgTimeline, GUILayout.Height(bgTimeline.height)); { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (SelectedAudioclip != null) { GUILayout.Label(SelectedAudioclip.name); } GUILayout.FlexibleSpace(); GUILayout.Space(20); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (settings != null) { GUILayout.Label(guiTimeline.selectedValue.ToString("0.000") + " / " + settings.animationTime.ToString("0.000")); } } GUILayout.EndHorizontal(); GUILayout.Space(5); } GUILayout.EndHorizontal(); //scrollViewTimelineVector = GUILayout.BeginScrollView(scrollViewTimelineVector, styleScrollviewTimeline); //{ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true)); //GUILayout.BeginHorizontal(new GUILayoutOption[] { GUILayout.Width(1040f) }); { GUILayout.Box("", new GUIStyle(), GUILayout.ExpandWidth(true)); Rect lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.width > 1) { guiTimeline.Draw(new Rect(lastRect.x, 124, lastRect.width, 57)); if (audioPreviewSpectrum != null) { GUI.DrawTexture(new Rect(lastRect.x, 125, lastRect.width, 40), audioPreviewSpectrum); } guiTimelineSegment.Draw(new Rect(lastRect.x + 2, 125, lastRect.width - 2, 130)); } switch (playMode) { case PlayMode.all: GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f); GUI.DrawTexture(new Rect(guiTimeline.timeLineRect.x + 1, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width) * timeNormalized, 11), EditorGUIUtility.whiteTexture); break; case PlayMode.segment: GUI.color = new Color(130f / 255f, 170f / 255f, 30f / 255f, 0.3f); GUI.DrawTexture(new Rect(guiTimelineSegment.KeyframeSet[0].IconRect.x + 7, guiTimeline.timeLineRect.y + 44, (guiTimeline.timeLineRect.width - 18) * timeNormalized, 11), EditorGUIUtility.whiteTexture); break; } } GUILayout.EndHorizontal(); GUI.color = Color.white; //} //GUILayout.EndScrollView(); GUILayout.Space(67); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { if (guiTimeline.keyframeSet.Count == 1 || disableGuiControls) { GUI.enabled = false; } if (GUILayout.Button(icoRemove, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) //btRemove { guiTimeline.RemoveKeyframe(guiTimeline.selectedIndex); } GUI.enabled = true; if (disableGuiControls) { GUI.enabled = false; } if (GUILayout.Button(icoAdd, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) //btAdd { TagarelaMorphTarget _morphTargetList = new TagarelaMorphTarget(); _morphTargetList.Populate(tagarela.smrTotal); guiTimeline.AddKeyframe(0.0f, _morphTargetList); updateTimeline = true; updateMorph = true; } } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Sliders to zero", styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(120), GUILayout.Height(20) })) //btAdd { TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders; if (_MorphTarget != null) { for (int i = 0; i < _MorphTarget.id.Count; i++) { _MorphTarget.sliderValue[i] = 0; } } updateTimeline = true; } GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(GUILayout.ExpandWidth(false)); { GUI.enabled = !disableGuiControls; if (GUILayout.Button(icoPlay, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { //tagarela.setTimer(0); playMode = PlayMode.all; } GUI.enabled = true; if (!guiTimelineSegment.active || disableGuiControls) { GUI.enabled = false; } if (GUILayout.Button(icoPlaySegment, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { tagarela.setTimer(guiTimelineSegment.KeyframeSet[0].Value); playMode = PlayMode.segment; } GUI.enabled = false; if (!playMode.Equals(PlayMode.stopped)) { GUI.enabled = true; } if (GUILayout.Button(icoStop, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { //tagarela.audio.loop = false; tagarela.setTimer(0f); //tagarela.audio.Stop(); playMode = PlayMode.stopped; if (tagarela.audio.isPlaying) { tagarela.audio.Stop(); } } //if don´t have any audio, is a time based animation if (SelectedAudioclip == null) { GUI.enabled = !disableGuiControls; GUILayout.Space(10); if (GUILayout.Button(icoClock, styleBtTimeline, new GUILayoutOption[] { GUILayout.Width(22), GUILayout.Height(20) })) { TagarelaEditorPopupTimeLength popupAnimLength = CreateInstance <TagarelaEditorPopupTimeLength>(); popupAnimLength.parent = this; popupAnimLength.title = "Time Settings"; popupAnimLength.currentLength = popupAnimLength.newLength = guiTimeline.totalValue; popupAnimLength.ShowAuxWindow(); } ; } GUI.enabled = true; } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); GUI.enabled = !disableGuiControls; scrollViewVector = GUILayout.BeginScrollView(scrollViewVector, styleScrollview); { if (tagarela.smrTotal.Count > 0 && guiTimeline.selectedIndex != -1 && guiTimeline.keyframeSet.Count > 0) { EditorGUILayout.BeginVertical(); { //seleciona a lista de acordo com o index selecionado TagarelaMorphTarget _MorphTarget = guiTimeline.morphSliders; GUI.color = GUI.contentColor; if (_MorphTarget != null) { //GUILayout.Space(13f); GUILayout.Space(14); //space before slider list for (int i = 0; i < _MorphTarget.id.Count; i++) { EditorGUILayout.BeginHorizontal(styleBgSlider, GUILayout.ExpandWidth(true)); { float temp_value = _MorphTarget.sliderValue[i]; GUILayout.Label(_MorphTarget.id[i], GUILayout.Width(150)); temp_value = GUILayout.HorizontalSlider(temp_value, 0, 100, GUILayout.ExpandWidth(true)); if (_MorphTarget.sliderValue[i] != temp_value) { _MorphTarget.sliderValue[i] = temp_value; updateTimeline = true; } } EditorGUILayout.EndHorizontal(); } } } EditorGUILayout.EndVertical(); } if (guiTimeline.refresh) { updateWindow = true; } if (guiTimeline.isDragging) { guiTimelineSegment.isDragging = false; guiTimelineSegment.enabled = false; if (updateMorphValue != guiTimeline.selectedValue && SelectedAudioclip != null) { playMode = PlayMode.currentTime; updateMorphValue = guiTimeline.selectedValue; } } if (guiTimeline.enabled && (guiTimeline.selectedIndex == -1 || lastKeyframeSelected != guiTimeline.selectedIndex)) { lastKeyframeSelected = guiTimeline.selectedIndex; updateMorphValue = guiTimeline.selectedValue; updateTimeline = true; } //if a new keyframe was create or cloned, call a update om mesh list if (guiTimeline.isKeyframeSetChanged) { lastKeyframeSelected = -1; guiTimeline.isKeyframeSetChanged = false; updateTimeline = true; updateMorph = true; } if (guiTimelineSegment.refresh) { updateWindow = true; } if (guiTimelineSegment.isDragging) { guiTimeline.isDragging = false; guiTimeline.enabled = false; if (updateMorphValue != guiTimelineSegment.SelectedValue) { playMode = PlayMode.currentTime; updateMorphValue = guiTimelineSegment.SelectedValue; updateMorph = true; } } if (!guiTimelineSegment.isDragging && !guiTimeline.isDragging) { guiTimelineSegment.enabled = true; guiTimeline.enabled = true; } if (playMode.Equals(PlayMode.all) || playMode.Equals(PlayMode.segment)) { guiTimeline.enabled = false; } } GUILayout.EndScrollView(); GUI.enabled = true; break; } } GUILayout.EndVertical(); if (updateWindow || tagarela != null && tagarela.isPlaying) { Repaint(); } }
void SelectObject() { bool hasTagarela = (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<Tagarela>()); if (hasTagarela) { if (settings == null || guiTimeline == null || tagarela == null || tagarela.settings == null) { BackupOriginalMesh(); tagarela.Clean(); dialog = ScreenDialog.InitialScreen; } else if (lastSelectionGameObjectEditing == Selection.activeGameObject) { if (settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { dialog = ScreenDialog.InitialScreen; } } } else if (Selection.objects.Length != 0) { log_msg = "Invalid Object: There is no Tagarela Component"; dialog = ScreenDialog.InvalidObject; playMode = PlayMode.stopped; RestoreOriginalMesh(); } else if (Selection.objects.Length == 0) { if (lastSelectionGameObjectEditing != null && settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { Close(); } } }
void SelectObject() { bool hasTagarela = (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<Tagarela>()); if (hasTagarela) { if (settings == null || guiTimeline == null || tagarela == null || tagarela.settings == null) { BackupOriginalMesh(); tagarela.Clean(); dialog = ScreenDialog.InitialScreen; } else if (lastSelectionGameObjectEditing == Selection.activeGameObject) { if (settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { dialog = ScreenDialog.InitialScreen; } } } else if (Selection.objects.Length != 0) { log_msg = "Invalid Object: There is no Tagarela Component"; dialog = ScreenDialog.InvalidObject; playMode = PlayMode.stopped; RestoreOriginalMesh(); } else if (Selection.objects.Length == 0) { if (lastSelectionGameObjectEditing != null && settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { Close(); } } /* if (Selection.activeGameObject == null && dialog != ScreenDialog.Timeline || Selection.objects.Length > 1) { log_msg = "Select a valid object!"; //valid_object = false; //exist_component = false; Debug.Log("opa " + dialog); if (dialog == ScreenDialog.Timeline) { if (EditorUtility.DisplayDialog("Close animation", "Do you want to save? ", "Yes", "No")) { string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; TagarelaFileManager.Save(arquivo_aberto, tagarela.morphTargets, guiTimeline.KeyframeSet, tagarela.neutralMesh.vertexCount, audioName, tagarela.settings.animationTime); CleanVars(); } RestoreOriginalMesh(); } else { SelectedAudioclip = null; if (tagarela != null) tagarela.Clean(); RestoreOriginalMesh(); } dialog = ScreenDialog.InvalidObject; } else if (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<MeshFilter>() && !Selection.activeGameObject.GetComponent<Tagarela>()) { dialog = ScreenDialog.InvalidObject; } else if (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<Tagarela>()) { //Selection.activeGameObject.hideFlags = HideFlags.HideInHierarchy; RestoreOriginalMesh(); BackupOriginalMesh(); if (tagarela != null) { dialog = ScreenDialog.InitialScreen; } else { tagarela.Clean(); dialog = ScreenDialog.InitialScreen; } } */ }
void SelectObject() { bool hasTagarela = (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent <Tagarela>()); if (hasTagarela) { if (settings == null || guiTimeline == null || tagarela == null || tagarela.settings == null) { BackupOriginalMesh(); tagarela.Clean(); dialog = ScreenDialog.InitialScreen; } else if (lastSelectionGameObjectEditing == Selection.activeGameObject) { if (settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { dialog = ScreenDialog.InitialScreen; } } } else if (Selection.objects.Length != 0) { log_msg = "Invalid Object: There is no Tagarela Component"; dialog = ScreenDialog.InvalidObject; playMode = PlayMode.stopped; RestoreOriginalMesh(); } else if (Selection.objects.Length == 0) { if (lastSelectionGameObjectEditing != null && settings != null && tagarela.settings == settings && guiTimeline != null) { dialog = ScreenDialog.Timeline; } else { Close(); } } /* * if (Selection.activeGameObject == null && dialog != ScreenDialog.Timeline || Selection.objects.Length > 1) * { * log_msg = "Select a valid object!"; * //valid_object = false; * //exist_component = false; * Debug.Log("opa " + dialog); * if (dialog == ScreenDialog.Timeline) * { * if (EditorUtility.DisplayDialog("Close animation", "Do you want to save? ", "Yes", "No")) * { * string audioName = SelectedAudioclip != null ? SelectedAudioclip.name : ""; * TagarelaFileManager.Save(arquivo_aberto, tagarela.morphTargets, guiTimeline.KeyframeSet, tagarela.neutralMesh.vertexCount, audioName, tagarela.settings.animationTime); * CleanVars(); * } * RestoreOriginalMesh(); * } * else * { * SelectedAudioclip = null; * if (tagarela != null) tagarela.Clean(); * RestoreOriginalMesh(); * } * dialog = ScreenDialog.InvalidObject; * } * else if (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<MeshFilter>() && !Selection.activeGameObject.GetComponent<Tagarela>()) * { * * dialog = ScreenDialog.InvalidObject; * } * else if (Selection.objects.Length == 1 && Selection.activeGameObject.GetComponent<Tagarela>()) * { * //Selection.activeGameObject.hideFlags = HideFlags.HideInHierarchy; * RestoreOriginalMesh(); * BackupOriginalMesh(); * * if (tagarela != null) * { * dialog = ScreenDialog.InitialScreen; * } * else * { * tagarela.Clean(); * dialog = ScreenDialog.InitialScreen; * } * } */ }
/// <summary> /// Assign a custom <c>ICustomDialogInputListener</c> to the specified <c>ScreenDialog</c>. /// </summary> /// <remarks> /// Each dialog can only have one associated listener. The listener method will be called /// before the main method and can stop the main method from executing if it returns <c>true</c>, /// Currently unused. /// </remarks> /// <param name="dialog">The key dialog.</param> /// <param name="listener">The assigned listener.</param> public static void SetCustomDialogInputListener(ScreenDialog dialog, ICustomDialogInputListener listener) { listeners.Add(dialog, listener); }
IEnumerator teste() { yield return new WaitForSeconds(3); LoadAnimationFile(tagarela.animationFiles[tagarela.animationFiles.Count - 1]); dialog = ScreenDialog.Timeline; Repaint(); }
public static bool ShowWarning(string message) { bool result = ScreenDialog.ShowDialog("Aviso", message); return(result); }