获取对Unity中序列化List <GameObject>的引用

时间:2019-07-18 03:05:42

标签: unity3d unity-editor

我需要在标记为可序列化的特定类中获得对我的列表的引用。

根据我的研究,我需要创建一个单独的类以充当容器,然后序列化该类的List。但这在我的特定解决方案中会非常麻烦。

我可以序列化一个GameObjects列表,然后通过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中,它循环遍历所有“幻灯片”,并允许我编辑作为给定幻灯片GameObject的子级的某些组件(例如Text和Image)

编辑:

我需要引用GameObject,然后通过这些引用对其进行突变,然后将其标记为脏并保存在编辑器中

我编写了以下脚本,以在给定的时间内自动将脏的编辑内容保存在编辑器中。

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 
    }
}

如何将这些游戏对象引用标记为脏?

0 个答案:

没有答案
相关问题