void AddSpeaker(SpeakerTrack myScript, int speakerIndex, float time) { SpeakerEvent[] n = new SpeakerEvent[myScript.Length + 1]; SpeakerEvent ev = new SpeakerEvent(); ev.speakerIndex = speakerIndex; ev.time = time; bool newEvtAdded = false; int i = 0; foreach (SpeakerEvent ev1 in myScript.Events) { if (!newEvtAdded && ev.time < ev1.time) { n [i++] = ev; newEvtAdded = true; } else { n [i++] = ev1; } } if (newEvtAdded == false) { n[n.Length - 1] = ev; } myScript.Events = n; }
public override void OnInspectorGUI() { // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); // TODO: Draw UI here //EditorGUILayout.PropertyField(); DrawDefaultInspector(); Dialog diag = (Dialog)target; if (EditorApplication.isPlaying) { if (!diag.IsPlaying() && GUILayout.Button("Play")) { diag.StartDialog(); } } ConversationTable table = diag.GetComponent <ConversationTable>(); if (diag.Track == null && table != null && table.m_speakerMonologue != null) { if (GUILayout.Button("Port from Conversation")) { SpeakerTrack track = new SpeakerTrack(); track.name = table.m_speakerMonologue.name; track.DialogClip = table.m_speakerMonologue; track.ParticipantNumber = (uint)diag.Participants.Length; diag.Track = track; AssetDatabase.CreateAsset(track, "Assets/" + track.name + ".asset"); } } if (GUILayout.Button("Auto-Feed Participants from Children")) { diag.Participants = diag.GetComponentsInChildren <DialogParticipant>(); } // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { // Update the serializedProperty - always do this in the beginning of OnInspectorGUI. serializedObject.Update(); SpeakerTrack myScript = (SpeakerTrack)target; playing = false; if (myScript.DialogClip != null) { playing = Get <bool> (myScript.DialogClip, "IsClipPlaying"); } if (!playing) { if (myScript.DialogClip != null && GUILayout.Button("Play")) { playing = true; Call(myScript.DialogClip, "PlayClip"); playing = true; } if (GUILayout.Button("Clear Speaker Track")) { myScript.Events = new SpeakerEvent[0]; } } if (playing) { EditorUtility.SetDirty(target); float time = Get <float>(myScript.DialogClip, "GetClipPosition"); if (!paused) { if (GUILayout.Button("Pause")) { Call(myScript.DialogClip, "PauseClip"); paused = true; } } else { if (GUILayout.Button("Resume")) { Call(myScript.DialogClip, "ResumeClip"); paused = false; } } if (GUILayout.Button("Stop")) { Call(myScript.DialogClip, "StopClip"); playing = false; } int currentSpeaker = myScript.GetSpeakerAt(time); float timeTillNextSpeaker = 0; int nextSpeaker = myScript.GetNextSpeaker(time, out timeTillNextSpeaker); for (int i = 0; i < myScript.ParticipantNumber; i++) { string label = "" + (i + 1); if (i == currentSpeaker) { label = "->" + label; } if (i == nextSpeaker) { label = "next:" + label; } if (GUILayout.Button(label)) { AddSpeaker(myScript, i, time); } } string label2 = "Silence"; if (-1 == currentSpeaker) { label2 = "->" + label2; } if (-1 == nextSpeaker) { label2 = "next:" + label2; } if (GUILayout.Button(label2)) { AddSpeaker(myScript, -1, time); } GUILayout.HorizontalSlider(time, 0, myScript.DialogClip.length); GUILayout.Label(time + " / " + myScript.DialogClip.length); GUILayout.Label("Next Speaker (" + ((nextSpeaker == -1)?"None":("" + (nextSpeaker + 1))) + ") in " + timeTillNextSpeaker); } //EditorGUILayout.PropertyField(); DrawDefaultInspector(); // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI. serializedObject.ApplyModifiedProperties(); }