Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///		Updates chapter at the provided index;
 /// </summary>
 public void UpdateChapter(int i, TimelineChapter updatedChapter)
 {
     Chapters[i] = updatedChapter;
 }
Ejemplo n.º 3
0
 /// <summary>
 ///		Removes the chapter from the list.
 /// </summary>
 public void RemoveChapter(TimelineChapter chapter)
 {
     Chapters.Remove(chapter);
 }
Ejemplo n.º 4
0
 /// <summary>
 ///		Adds a new Chapter to the list.
 /// </summary>
 public void AddChapter(TimelineChapter chapter)
 {
     Chapters.Add(chapter);
 }
Ejemplo n.º 5
0
        /// <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);
        }