public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (types == null || types.Count == 0) { var availableCommands = CommanderUtils.GetAvailableCommands(); types = CommanderUtils.GetTypesAsString(availableCommands); namespaceNames = new List <string>(types.Keys).ToArray(); } EditorGUI.BeginProperty(position, label, property); // Label. EditorGUI.LabelField(position, label); // 子段落不缩进 var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // 命名空间 var namespaceRect = new Rect(position.x, position.y + LINE_HEIGHT, position.width, LINE_HEIGHT); var propertyNamespace = property.FindPropertyRelative("commandNamespace"); var i = Array.IndexOf(namespaceNames, propertyNamespace.stringValue); if (i < 0) { i = 0; } EditorGUI.BeginChangeCheck(); i = EditorGUI.Popup(namespaceRect, "Namespace", i, namespaceNames); if (EditorGUI.EndChangeCheck() || string.IsNullOrEmpty(propertyNamespace.stringValue)) { propertyNamespace.stringValue = namespaceNames[i]; } // Command. var commandRect = new Rect(position.x, position.y + LINE_HEIGHT * 2, position.width, LINE_HEIGHT); var propertyCommand = property.FindPropertyRelative("commandName"); var commands = types[propertyNamespace.stringValue]; var commandIndex = commands.IndexOf(propertyCommand.stringValue); if (commandIndex < 0) { commandIndex = 0; } EditorGUI.BeginChangeCheck(); commandIndex = EditorGUI.Popup(commandRect, "Command", commandIndex, new List <string>(commands).ToArray()); if (EditorGUI.EndChangeCheck() || string.IsNullOrEmpty(propertyCommand.stringValue)) { propertyCommand.stringValue = commands[commandIndex]; } // 设置缩进 EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (this.types == null || this.types.Count == 0) { var availableCommands = CommanderUtils.GetAvailableCommands(); this.types = CommanderUtils.GetTypesAsString(availableCommands); this.namespaceNames = this.types.Keys.ToArray(); } EditorGUI.BeginProperty(position, label, property); // Label. EditorGUI.LabelField(position, label); // Don't make child fields be indented. var indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // Namespace. var namespaceRect = new Rect(position.x, position.y + LINE_HEIGHT, position.width, LINE_HEIGHT); var propertyNamespace = property.FindPropertyRelative("commandNamespace"); var namespaceIndex = Array.IndexOf(this.namespaceNames, propertyNamespace.stringValue); if (namespaceIndex < 0) { namespaceIndex = 0; } EditorGUI.BeginChangeCheck(); namespaceIndex = EditorGUI.Popup(namespaceRect, "Namespace", namespaceIndex, this.namespaceNames); if (EditorGUI.EndChangeCheck() || string.IsNullOrEmpty(propertyNamespace.stringValue)) { propertyNamespace.stringValue = this.namespaceNames[namespaceIndex]; } // Command. var commandRect = new Rect(position.x, position.y + LINE_HEIGHT * 2, position.width, LINE_HEIGHT); var propertyCommand = property.FindPropertyRelative("commandName"); var commands = this.types[propertyNamespace.stringValue]; var commandIndex = commands.IndexOf(propertyCommand.stringValue); if (commandIndex < 0) { commandIndex = 0; } EditorGUI.BeginChangeCheck(); commandIndex = EditorGUI.Popup(commandRect, "Command", commandIndex, commands.ToArray()); if (EditorGUI.EndChangeCheck() || string.IsNullOrEmpty(propertyCommand.stringValue)) { propertyCommand.stringValue = commands[commandIndex]; } // Set indent back to what it was. EditorGUI.indentLevel = indent; EditorGUI.EndProperty(); }
protected void OnEnable() { component = (T)this.target; var availableCommands = CommanderUtils.GetAvailableCommands(); types = CommanderUtils.GetTypesAsString(availableCommands); namespaceNames = new List <string>(types.Keys).ToArray(); }
protected void OnEnable() { this.component = (T)this.target; var availableCommands = CommanderUtils.GetAvailableCommands(); this.types = CommanderUtils.GetTypesAsString(availableCommands); this.namespaceNames = this.types.Keys.ToArray(); }