Сбрасываются сохранения в ScriptableObject

Не могу понять, в чём подвох. Сделал простенький MenuController для быстрого прототипирования меню и перехода между страницами. Написал CustomEditor для этого контроллера. Вот код:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(MenuController))]
[CanEditMultipleObjects]
public class MenuConEditor : Editor
{
    private SerializedProperty pagesData;

    private SerializedProperty StartPageName;

    //int test;
    private void OnEnable()
    {
        pagesData = serializedObject.FindProperty("pagesData");
        StartPageName = serializedObject.FindProperty("StartPageName");
    }
    //int a;
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        //MenuController controller = (MenuController)target;

        //  Если список страниц равен null , то создаётся пустой список
        if (pagesData.objectReferenceValue == null)
        {
            pagesData.objectReferenceValue = CreateInstance<PagesData>();
        }
        PagesData list = (PagesData)pagesData.objectReferenceValue;

        //  Начальная страница, открывающаяся при запуске сцены. Поле и предупреждение, если поле пусто
        if (StartPageName.stringValue == null)
            StartPageName.stringValue = "";
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("Start page");
        StartPageName.stringValue = EditorGUILayout.TextField(StartPageName.stringValue);
        EditorGUILayout.EndHorizontal();
        if (StartPageName.stringValue.Length == 0)
        {
            EditorGUILayout.HelpBox("Start page is not set. On start the firts page in list will be opened", MessageType.Warning);
        }

        //  Кнопка добавления новой страницы
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Add page", GUILayout.Width(100)))
        {
            list.pages.Add((Page)CreateInstance("Page"));
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.LabelField("___________________________________________________________________");

        // Цикл, отображающий информацию об каждой странице
        for (int i = 0; i < list.pages.Count;i++)
        {
            Page currpage = list.pages[i];

            //  Первая строка, Поле названия страницы и кнопка удаления страницы
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Name");
            currpage.Name = EditorGUILayout.TextField(currpage.Name);
            if (GUILayout.Button("Delete", GUILayout.Width(70)))
            {
                list.pages.RemoveAt(i);
                OnInspectorGUI();
            }
            EditorGUILayout.EndHorizontal();

            if (currpage.Name == null)
                currpage.Name = "";

            //Предупреждение, если имя страницы пустое
            if (currpage.Name.Length == 0)
            {
                EditorGUILayout.HelpBox("Name is not set!", MessageType.Warning);
            }

            // Поле объекта страницы и ошибка, если поле равно null
            currpage.pageObject = (GameObject)EditorGUILayout.ObjectField("Object", currpage.pageObject, typeof(GameObject), true);
            if (currpage.pageObject == null)
            {
                EditorGUILayout.HelpBox("Object of page is null!", MessageType.Error);
            }

            // Если список переходов равен null , то создаётся пустой список
            if (currpage.transitions == null)
            {
                currpage.transitions = new List<string>();
            }

            // Кнопка добавления перехода
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Transitions on pages");
            if (GUILayout.Button("Add transition", GUILayout.Width(140)))
            {
                currpage.transitions.Add("transition");
                OnInspectorGUI();
            }
            EditorGUILayout.EndHorizontal();

            // Цикл, отображающий все переходы
            for(int t = 0; t < currpage.transitions.Count;t++)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("transition on");
                currpage.transitions[t] = EditorGUILayout.TextField(currpage.transitions[t]);
                if (GUILayout.Button("Delete", GUILayout.Width(70)))
                {
                    currpage.transitions.RemoveAt(t);
                    OnInspectorGUI();
                }
                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.LabelField("______________________________________________________________________________");
        }

        if (GUI.changed)
        {
            EditorUtility.SetDirty(list);
            EditorUtility.SetDirty((MenuController)target);
        }

        serializedObject.ApplyModifiedProperties();
    }
}

Вот классы, которые сохраняются, например, Page.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Page : ScriptableObject
{
    public string Name;
    public GameObject pageObject;
    public List<string> transitions;
}

Этот класс служит для сохранения списка страниц, потому что SerializedProperty не может сохранить сам объект списка:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class PagesData : ScriptableObject
{
    public List<Page> pages;
    public void OnEnable()
    {
        if (pages == null)
            pages = new List<Page>();
    }
}

Вроде бы всё должно работать. Но вот сегодня открываю проект, выбираю объект, который содержит этот контроллер: This script cannot be loaded... При этом, стоит отметить, я оставил код с ошибками, но совершенно в другом файле, чтобы сегодня его дописать. Когда я эти ошибки закомментировал, то скрипт прогрузился, но ничего не отображал, только кнопку (согласно CustomEditor'у), т.е. сохранения слетели. При этом похожая ситуация была вчера. Я тоже открыл проект с ошибками в каком-то другом файле, но этот контроллер прекрасно прогрузился и ничего не слетело. В чём может быть проблема? В коде? Но он прекрасно до этого работал. Есть ли ещё способы вот так сохранять состояния между перезаходами в Unity?


Ответы (0 шт):