【发布时间】:2018-12-06 13:56:38
【问题描述】:
尝试为自定义编辑器编写代码,但当我按下播放按钮时,下拉或弹出字段值总是会重置。
我浏览了一些类似的问题,并在添加应用修改和设置脏时找到了解决方案,但都没有解决问题。
知道会发生什么吗?
下面是代码:
[CustomEditor(typeof(EnemyAI))]
public class Level_SelectionEditor : Editor
{
string[] _choices = new[] { "snailer", "sheller" };
int _choiceIndex = 0;
override public void OnInspectorGUI()
{
// Draw the default inspector
var mc = target as EnemyAI;
EditorGUILayout.PropertyField(serializedObject.FindProperty("damage"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("attackCounter"), true);
EditorGUILayout.PrefixLabel("Type");
EditorGUI.indentLevel++;
_choiceIndex = EditorGUILayout.Popup(_choiceIndex, _choices);
//updated in code
if (_choices[_choiceIndex] == "snailer")
{
mc.type = EnemyAI.Type.snailer;
EditorGUILayout.PropertyField(serializedObject.FindProperty("snailerEffect"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("snailerShootPoint"), true);
}
else
{
mc.type = EnemyAI.Type.sheller;
EditorGUILayout.PropertyField(serializedObject.FindProperty("rotationsPerMinute"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("rotationTime"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("pauseTime"), true);
}
// Save the changes back to the object
EditorUtility.SetDirty(target);
serializedObject.ApplyModifiedProperties();
}
}
【问题讨论】:
标签: unity3d