Example #1
0
    public static void OpenWindow()
    {
        StoryDialogEditor window = GetWindow <StoryDialogEditor>();

        window.titleContent = new GUIContent("Story-Dialog Editor");
    }
    // vvvvv LOAD STORY EDITOR vvvvv //

    public static void LoadItems(string path)
    {
        if (mainEditor == null)
        {
            // open a new window if it's unhooked
            Debug.Log("Window not found, opening new Story Dialog Editor window.");
            StoryDialogEditor.OpenWindow();
        }
        else if (HistoryManager.needsSave)
        {
            // create dialog entry to warn user that they have unsaved changes
            if (!EditorUtility.DisplayDialog("Load new entry", "Are you sure you want to open a new entry and close the current one?", "yes", "no"))
            {
                return;
            }
        }

        Debug.Log("attempting to load: " + path);

        EditorStoryNodeEntry storyEntry = new EditorStoryNodeEntry();

        XmlSerializer serializer = new XmlSerializer(typeof(EditorStoryNodeEntry));
        Encoding      encoding   = Encoding.GetEncoding("UTF-8");

        using (StreamReader stream = new StreamReader(path, encoding)) {
            storyEntry = serializer.Deserialize(stream) as EditorStoryNodeEntry;
        }

        // destroy the scene before populating it
        mainEditor.DestroyScene();

        // set the editor's offset to match the saved entry
        mainEditor.offset = storyEntry.offset;

        // load flags
        foreach (string entry in storyEntry.localFlags)
        {
            mainEditor.localFlagsMenu.AddItem(entry, markHistory: false);
        }

        // CPEID maps to ConnectionPoint to generate connections later
        Dictionary <int, ConnectionPoint> connectionPointMap = new Dictionary <int, ConnectionPoint>();

        // initialize all the nodes and generate the connection map
        Dictionary <int, List <int> > connectionMap = InitializeNodes(storyEntry, connectionPointMap);

        // create all the connections
        foreach (int inCPEID in connectionMap.Keys)
        {
            ConnectionManager.selectedInPoint = connectionPointMap[inCPEID];

            bool deletable = true;
            if (((Node)ConnectionManager.selectedInPoint.parent).nodeType == NodeType.Interrupt)
            {
                deletable = false;
            }
            foreach (int outCPEID in connectionMap[inCPEID])
            {
                ConnectionManager.selectedOutPoint = connectionPointMap[outCPEID];
                ConnectionManager.CreateConnection(deletable, markHistory: false);
            }
        }
        ConnectionManager.ClearConnectionSelection();

        Debug.Log("loaded: " + path);
        mainEditor.fileName = path;
    }