我需要在标记为可序列化的特定类中获取对我的列表的引用。
根据我的研究,我需要创建一个单独的类作为容器,然后序列化该类的列表。但是,这在我的特定解决方案中会非常麻烦。
我可以序列化一个游戏对象列表,然后通过 UnityEditor API 访问和改变这些值吗?
伪代码
var listOfGameObjects = serializedObject.FindProperty("listofgameobjects");//something like this
//I'd do some logic to mutate some sub properties/objects contained in a particular GameObject
//then dirty the attribute so Unity updates the new values I input through the GUI
serializedObject.ApplyModifiedProperties();
but it gets a reference to the List of gameObjects
上下文 我有一个列表,其中包含用于弹出的幻灯片。在我的 GUI 中,它循环遍历所有“幻灯片”,并允许我编辑作为给定幻灯片游戏对象的子项的某些组件(例如文本和图像)
编辑:
我需要引用游戏对象,然后通过这些引用对它们进行变异,然后将它们标记为脏并将它们保存在编辑器中
我编写了以下脚本以在给定的时间内自动将脏编辑保存在编辑器中。
public static class SaveDirtyEdits//container to hold our coroutine, static because we only want one to be running
{
public static System.Collections.IEnumerator UpdateDirtyGUIChanges(float timeTillSave)
{
yield return new WaitForSeconds(timeTillSave);
//the items that are marked dirty are done automatically in the GUI scripts written for the button manager
UnityEditor.AssetDatabase.SaveAssets();
}
}
public class LeidosAlwaysRunInEditor : Editor
{
public void Update()
{
SaveDirtyEdits.UpdateDirtyGUIChanges(120f);//start a coroutine to save dirty edits (every x amount of input seconds)
MoveNextTarget();//not sure what this does but you need it to update the changes we are applying with our coroutine
}
}
如何将这些游戏对象引用标记为脏?