private void buttonOpenWindowToEditEntry(VoiceProperties myScript) { string s_EditWindow = "Open Window Tab : "; //Show existing window instance. If one doesn't exist, make one. if (myScript.editorType == 0) { s_EditWindow += "w_textnVoice"; } if (myScript.editorType == 1) { s_EditWindow += "w_Item"; } if (myScript.editorType == 2) { s_EditWindow += "w_UI"; } if (myScript.editorType == 3) { s_EditWindow += "w_Feedback"; } s_EditWindow += " to edit the selected entry."; if (GUILayout.Button(s_EditWindow)) { ShowWindow(myScript); } }
private void ShowWindow(VoiceProperties myScript) { //Select ID serializedObject3 = new UnityEditor.SerializedObject(_textList.objectReferenceValue); SerializedProperty selectedID = serializedObject3.FindProperty("selectedID"); serializedObject3.Update(); selectedID.intValue = managerID.intValue; serializedObject3.ApplyModifiedProperties(); //Show existing window instance. If one doesn't exist, make one. if (myScript.editorType == 0) { EditorWindow.GetWindow(typeof(w_TextnVoice)); } if (myScript.editorType == 1) { EditorWindow.GetWindow(typeof(w_Item)); } if (myScript.editorType == 2) { EditorWindow.GetWindow(typeof(w_UI)); } if (myScript.editorType == 3) { EditorWindow.GetWindow(typeof(w_Feedback)); } }
public void Speak(ThingPart thingPart, string text, VoiceProperties properties) { if (voice == null) { try { voice = gameObject.AddComponent <WindowsVoice>() as WindowsVoice; voice.Init(); } catch (Exception exception) { voice = null; Log.Debug("Failed to initialize Windows Voice"); } } if (voice != null) { bool hasSurroundSound = false; Thing thing = thingPart.transform.parent.gameObject.GetComponent <Thing>(); if (thing != null) { hasSurroundSound = thing.hasSurroundSound; } Vector3 ourPosition = Managers.personManager.ourPerson.Head.transform.position; float distance = Vector3.Distance(ourPosition, thingPart.transform.position); const float maxDistanceToHear = 12.5f; const float startOfHearingFallOff = 2f; float relativeVolume = 1f; if (distance > startOfHearingFallOff && !hasSurroundSound) { relativeVolume = 1f - (distance - startOfHearingFallOff) / (maxDistanceToHear - startOfHearingFallOff); } const float generalVolumeAdjust = 0.5f; relativeVolume *= generalVolumeAdjust; if (properties == null) { properties = new VoiceProperties(); } VoiceProperties adjustedProperties = new VoiceProperties(); adjustedProperties.gender = properties.gender; adjustedProperties.volume = (int)((float)properties.volume * relativeVolume); adjustedProperties.pitch = properties.pitch; adjustedProperties.speed = properties.speed; if (adjustedProperties.volume > 0) { voice.Speak(text, adjustedProperties); } } }
//--> Launch a new Voice Over public void newVoiceOver(GameObject newObj) { VoiceProperties voiceProperties = newObj.GetComponent <VoiceProperties> (); //-> Add the entry in the diary if needed int managerID = voiceProperties.managerID; bool alreadyInDiary = false; if (voiceProperties.textList.r_Available(0, managerID)) { for (var i = 0; i < ingameGlobalManager.instance.currentPlayerDiaryList.Count; i++) { if (voiceProperties.managerID == ingameGlobalManager.instance.currentPlayerDiaryList [i]) { alreadyInDiary = true; break; } } if (!alreadyInDiary) { ingameGlobalManager.instance.currentPlayerDiaryList.Add(managerID); } } if (voiceProperties) { if (ingameGlobalManager.instance.voiceOverManager) { if (!voiceProperties.b_alreadyPlayed && voiceProperties.b_PlayOnce || !voiceProperties.b_PlayOnce) { voiceProperties.b_alreadyPlayed = true; ingameGlobalManager.instance.voiceOverManager.setupNewVoice( voiceProperties.r_TextList(), ingameGlobalManager.instance.currentLanguage, voiceProperties.managerID, voiceProperties.r_TextList().voiceOverDescription(ingameGlobalManager.instance.currentLanguage, voiceProperties.managerID), voiceProperties.r_TextList().r_audioPriority(ingameGlobalManager.instance.currentLanguage, voiceProperties.managerID), alreadyInDiary); } } } }
public void Find_UniqueId_In_The_TextList() { VoiceProperties myScript = (VoiceProperties)target; if (_textList.objectReferenceValue != null) { int HowManyEntry = myScript.textList.diaryList [0]._languageSlot.Count; for (var i = 0; i < HowManyEntry; i++) { if (myScript.textList.diaryList [0]._languageSlot [i].uniqueItemID == myScript.uniqueID) { //if (i == myScript.managerID) { Undo.RegisterFullObjectHierarchyUndo(myScript, myScript.name); //Debug.Log ("Position : " + i); myScript.managerID = i; break; } } } }
void OnEnable() { //-> Load the needed TextList VoiceProperties myScript = (VoiceProperties)target; string objectPath = "Assets/AP/Assets/Datas/ProjectManagerDatas.asset"; datasProjectManager _ProjectManagerDatas = AssetDatabase.LoadAssetAtPath(objectPath, typeof(UnityEngine.Object)) as datasProjectManager; string s_dataType = "wTextnVoices.asset"; if (myScript.editorType == 1) { s_dataType = "wItem.asset"; } if (myScript.editorType == 2) { s_dataType = "wUI.asset"; } if (myScript.editorType == 3) { s_dataType = "wFeedback.asset"; } string objectPath2 = "Assets/AP/Assets/Resources/" + _ProjectManagerDatas.currentDatasProjectFolder + "/TextList/" + s_dataType; TextList tmpTextList = AssetDatabase.LoadAssetAtPath(objectPath2, typeof(UnityEngine.Object)) as TextList; myScript.textList = tmpTextList; //-> Setup the SerializedProperties. SeeInspector = serializedObject.FindProperty("SeeInspector"); managerID = serializedObject.FindProperty("managerID"); uniqueID = serializedObject.FindProperty("uniqueID"); _textList = serializedObject.FindProperty("textList"); b_PlayOnce = serializedObject.FindProperty("b_PlayOnce"); Find_UniqueId_In_The_TextList(); Tex_01 = MakeTex(2, 2, new Color(.3f, .8f, 0.2F, .8f)); }
// --> Update the uniqueID when the managerID is change in the Inspector private void updateInventory(int value) { VoiceProperties myScript = (VoiceProperties)target; int HowManyEntry = myScript.textList.diaryList [0]._languageSlot.Count; for (var i = 0; i < HowManyEntry; i++) { //if (myScript.textList.diaryList [0]._languageSlot [i].uniqueItemID == myScript.uniqueID) { if (i == value) { Undo.RegisterFullObjectHierarchyUndo(myScript, myScript.name); //Debug.Log ("Position : " + i); uniqueID.intValue = myScript.textList.diaryList [0]._languageSlot [i].uniqueItemID; if (myScript.gameObject.GetComponent <Text>()) { myScript.gameObject.GetComponent <Text>().text = myScript.textList.diaryList [0]._languageSlot [i].diaryTitle[0]; } break; } } }
public override void OnInspectorGUI() { GUIStyle style_Yellow_01 = new GUIStyle(GUI.skin.box); style_Yellow_01.normal.background = Tex_01; VoiceProperties myScript = (VoiceProperties)target; if (SeeInspector.boolValue) // If true Default Inspector is drawn on screen { DrawDefaultInspector(); } serializedObject.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("See Inspector :", GUILayout.Width(85)); EditorGUILayout.PropertyField(SeeInspector, new GUIContent(""), GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(style_Yellow_01); EditorGUILayout.HelpBox("This script is used to play voice over and Subtitles when this object is selected in game.", MessageType.Info); buttonOpenWindowToEditEntry(myScript); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Manager :", GUILayout.Width(85)); EditorGUILayout.PropertyField(_textList, new GUIContent("")); EditorGUILayout.EndHorizontal(); if (_textList.objectReferenceValue != null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Manager ID :", GUILayout.Width(85)); EditorGUILayout.PropertyField(managerID, new GUIContent(""), GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { //Debug.Log ("here"); updateInventory(managerID.intValue); } serializedObject2 = new UnityEditor.SerializedObject(_textList.objectReferenceValue); if (managerID.intValue < serializedObject2.FindProperty("diaryList").GetArrayElementAtIndex(0).FindPropertyRelative("_languageSlot").arraySize && managerID.intValue >= 0) { _Title = serializedObject2.FindProperty("diaryList").GetArrayElementAtIndex(0).FindPropertyRelative("_languageSlot").GetArrayElementAtIndex(managerID.intValue).FindPropertyRelative("diaryTitle").GetArrayElementAtIndex(0); //if (myScript.textList.diaryList.Count > 0) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Item Title :", GUILayout.Width(85)); EditorGUILayout.LabelField(_Title.stringValue.ToString()); EditorGUILayout.EndHorizontal(); //} } else { EditorGUILayout.HelpBox("This ID doesn't exist", MessageType.Warning); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Play sound Only the first Time", GUILayout.Width(200)); EditorGUILayout.PropertyField(b_PlayOnce, new GUIContent(""), GUILayout.Width(30)); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); EditorGUILayout.LabelField(""); serializedObject.ApplyModifiedProperties(); }