Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class ParseTwine : MonoBehaviour
- {
- public class Node
- {
- public string title;
- public string text;
- }
- public TextAsset text;
- public List<Node> nodes = new List<Node>();
- Node currentNode;
- void Start()
- {
- Parse(text.text);
- }
- void Parse(string text)
- {
- nodes.Clear();
- // 0 - searching for start, 1 - reading nodes
- int mode = 0;
- int phase = 0;
- string[] lines = text.Split('\n');
- Node node = null;
- foreach (string line in lines)
- {
- if (mode == 0)
- {
- if (line.IndexOf("Tiddler") != -1)
- {
- mode = 1;
- }
- }
- else if (mode == 1)
- {
- if (line[0] == 'V')
- {
- if (phase == 0)
- {
- node = new Node();
- node.text = line.Substring(1, line.Length-1);
- node.text = node.text.Replace("\\u000a", "\n");
- phase = 1;
- }
- else if (phase == 1)
- {
- node.title = line.Substring(1, line.Length-1);
- phase = 0;
- nodes.Add(node);
- Debug.Log("------------------------------------");
- Debug.Log("Title: " + node.title);
- Debug.Log("Text: " + node.text);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement