我在使用 Unity 的 API 修改编辑器 GUI 来改变引用值时遇到问题。
当我进入编辑器更改 GUI 中的值时,它只是刷新并保留我在参数中提供的标签文本/对象,为什么它不改变引用并显示它呢?
1.
我正在引用一个附加到特定游戏对象的类ButtonManager script = target as ButtonManager;
我想更改该类的值,script.thisImageCaption = EditorGUILayout.TextArea("Content for the main image slide", script.thisImageCaption);
但这不起作用
奇怪的是... bools工作,当我选中该框时,GUI 会记住我的选择并修改引用的值,那么为什么其他人不呢?
script.hasAudioClip = EditorGUILayout.Toggle("Voice Over?", script.hasAudioClip);
2. 我还引用了游戏对象及其各个组件
//following code is a snippet of code, the full context isnt provided, only the context related to mutating referenced values
List<Tuple<int, Text, Image>> imageCloneHolder = new List<Tuple<int, Text, Image>>();
imageCloneHolder.Add(new Tuple<int, Text, Image>(
slide.GetInstanceID(),
slide.transform.GetChild(1).GetComponent<Text>(),//get reference to text
slide.transform.GetChild(0).GetComponent<Image>()//get reference to image
));
item.Item2.text = EditorGUILayout.TextArea("Content for the image cloneslide",
item.Item2.text);//dosen't modify the referenced text
item.Item3.sprite = EditorGUILayout.ObjectField("This second Image slides image",
item.Item3.sprite,
typeof(Sprite),
false) as Sprite;//doesn't modify the referenced image
我不太明白出了什么问题,我认为当您在 Unity 和 C#(带有类、组件等)中获取引用时,它们将是指向真实对象而不是副本的指针,但似乎 Unity 的 GUI API 让我修改副本?对于类中引用的字符串,这不是真的吗?或者对于一些 Unity 组件?
屏幕转储