'How to manually change variables on custom window editor and make it it persistent?

I'm trying to create a custom editor window in Unity that make me able to generate "things".

When I open my custom window I want a list (and of course other variables like name etc.) that I will use to randomly choose prefabs from it and spawn it in specific places but i want be able to modify this list manually from my window in case I need to do it and make my manual changes persistent if for example I close and re-open my window (like when you modify a list from inspector). I want my designers to be able to modify it "only" from the window.

How can I modify a list this way (and so in from the window and make changes persistent)?

public List<int> numbers = new List<int>() { 1,2,4,5,6,7};
public List<Stuff> provaPrefab = new List<Stuff>();

void OnGUI() {

    ScriptableObject target = this;
    SerializedObject so = new SerializedObject(target);
    SerializedProperty stringsProperty = so.FindProperty("provaPrefab");
    SerializedProperty numbersLists = so.FindProperty("numbers");

    EditorGUILayout.PropertyField(stringsProperty, true);
    EditorGUILayout.PropertyField(numbersLists, true);
    so.ApplyModifiedProperties();

}

Here an example of my code. As i already said I want my object List "Stuff" be editable by hand from my window and if i reopen my window hand changes must be saved. Thanks in advance!



Solution 1:[1]

When saving changes in any object from editor script, I call the following three methods.

AssetDatabase.Refresh();
EditorUtility.SetDirty(object);
AssetDatabase.SaveAssets();

Let me know if this helps you

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Devendra Pratap Singh