以编程方式切换EditorGUI.Foldout

时间:2015-09-02 13:08:44

标签: c# unity3d editor

对于Unity3D编辑器脚本,是否可以通过编程方式将EditorGUI.Foldouts设置为关闭或打开状态?我希望当用户第一次选择游戏对象时,我的脚本最初会打开相关的折页。

同样,我希望默认情况下关闭多个折页,这样他们就不会占用组件窗格中的空间,例如RectTransformRawImage的折页。在脚本运行时动态添加。

1 个答案:

答案 0 :(得分:0)

EditorGUI.Foldout第二个参数是bool

您可以根据需要将该bool设置为打开或关闭。你不需要使用从它返回的同一个bool。或者您可以在该行之前或之后修改它的值

bool fold;

fold = SomeLogicFunction();
EditorGUI.Foldout(rect,fold,"Folder");

bool fold;

fold = EditorGUI.Foldout(rect,fold,"Folder");
fold = fold && SomeLogicFunction();

string name = "none";
if(selectedGameObject != null)
    name = selectedGameObject.name;
EditorGUI.Foldout(rect,selectedGameObject != null,name);

FYI。 FoldOut实际上只是切换该行的箭头。你是那个决定当它返回真实时你会在它下面画什么的人

相关问题