/// <summary> /// Deseralizes the provided serialized timeline. /// </summary> public static Timeline Deserialize(string s_timeline) { Timeline timeline = new Timeline(""); // Splits the data file into chapters. string[] s_Chapters = s_timeline.Split(CHAPTERSPACER); foreach (string s_Chapter in s_Chapters) { if (s_Chapter == "") { continue; } // Splits the chapter into data pieces. string[] vars = s_Chapter.Split(EVENTSPACER); if (vars.Length == 0) { continue; } // A new chapter is created. TimelineChapter chapter = new TimelineChapter( int.Parse(vars[0]), vars[1], vars[2], int.Parse(vars[3])); // Starts later to skip chapter fields. for (int i = 4; i < vars.Length; i++) { // converts the var into a TimelineEvent string s_event = vars[i]; if (s_event == "") { continue; } TimelineEventData timelineData = JsonUtility.FromJson <TimelineEventData>(s_event); Type t = TimelineEventContainer.TypeOf(timelineData.Type); timelineData = (TimelineEventData)JsonUtility.FromJson(s_event, t); chapter.AddEvent(timelineData); } timeline.AddChapter(chapter); } return(timeline); }
/// <summary> /// Updates chapter at the provided index; /// </summary> public void UpdateChapter(int i, TimelineChapter updatedChapter) { Chapters[i] = updatedChapter; }
/// <summary> /// Removes the chapter from the list. /// </summary> public void RemoveChapter(TimelineChapter chapter) { Chapters.Remove(chapter); }
/// <summary> /// Adds a new Chapter to the list. /// </summary> public void AddChapter(TimelineChapter chapter) { Chapters.Add(chapter); }
/// <summary> /// Returns the Id of the first chapter instance that corresponds with the provided name. /// </summary> public int GetIdOf(string chapterName) { TimelineChapter chapter = Chapters.Find(c => c.Name == chapterName); return(chapter != null ? chapter.Id : -1); }