// Will make all current subtitles to go up private static void upSubtitles() { //for(var s : SubtitleMessage in subtitles) {} for (int i = 0; i < subtitles.Count; i++) { SubtitleMessage sub = subtitles[i] as SubtitleMessage; sub.goToNextPosition(); } }
// Add a subtitle on screen public static void show(string msg, float drtn, Color clr, bool it) { upSubtitles(); // Create the new subtitle SubtitleMessage s = new SubtitleMessage(msg, drtn, clr, it); subtitles.Add(s); // Hack for multi-lines subtitle, we retreive the number of lines then we add empty subtitles // TODO: Find a better way //int lines = s.getLines()-1; //for(int i = 0; i < lines; i++) //{ // upSubtitles(); // subtitles.Add(new SubtitleMessage(" ", drtn, clr, it)); //} }
// Update all SubtitleMessages and draw them void OnGUI() { // If there is at least a subtitle if (subtitles.Count > 0) { // Change skin GUISkin originalSkin = GUI.skin; GUI.skin = GuiSkin; // Draw box if (boxDraw) { GUI.Box(new Rect((Screen.width * marginPercent / 100) - boxMargins, (Screen.height * positionY / 100) - ((subtitles.Count - 1) * realLineSpacing) - (boxMargins / 2), (Screen.width * (100 - (marginPercent * 2)) / 100) + (boxMargins * 2), (subtitles.Count * realLineSpacing) + (boxMargins * 2)), ""); } // Draw each subtitles List <float> toAdd = new List <float>(); bool deleted = false; for (int i = 0; i < subtitles.Count; i++) { SubtitleMessage sub = subtitles[i] as SubtitleMessage; bool readyBefore = sub.calculated(); bool delete = sub.updateAndDraw(); if (delete) { subtitles.RemoveAt(i); i--; deleted = true; } if (!readyBefore) { for (int j = 0; j < sub.getLines() - 1; j++) { toAdd.Add(sub.duration); } } } // Add empty subtitles for empty lines for (int i = 0; i < toAdd.Count; i++) { upSubtitles(); subtitles.Add(new SubtitleMessage(" ", toAdd[i], Color.white, false)); } // If some subtitles were deleted, replace old subtitles to correct positions if (deleted) { int correctPosition = 0; for (int j = subtitles.Count - 1; j >= 0; j--) { SubtitleMessage sb = subtitles[j] as SubtitleMessage; sb.goToPosition(correctPosition); correctPosition++; } } // Reset skin GUI.skin = originalSkin; } }