private void DrawField(GUIContent label, Field field, bool showType = true) { // Custom field types: field.value = CustomFieldTypeService.DrawField(label, field, database); if (showType) { DrawFieldType(field); } }
private void DrawFieldType(Field field) { // Custom field types: CustomFieldTypeService.DrawFieldType(field); //---Was: //FieldType newFieldType = (FieldType) EditorGUILayout.EnumPopup(field.type); //if (newFieldType != field.type) { // field.type = newFieldType; // field.value = string.Empty; //} }
private void OnAddVariableDropdown(Rect buttonRect, ReorderableList list) { var menu = new GenericMenu(); string[] fieldTypes = CustomFieldTypeService.GetDialogueSystemTypes(); string[] fieldPublicNames = CustomFieldTypeService.GetDialogueSystemPublicNames(); for (int i = 0; i < fieldPublicNames.Length; i++) { var fieldType = (i < fieldTypes.Length) ? fieldTypes[i] : "CustomFieldType_Text"; menu.AddItem(new GUIContent(fieldPublicNames[i]), false, OnSelectVariableTypeToAdd, fieldType); } menu.ShowAsContext(); }
private void DrawField(Field field, bool isTitleEditable = true, bool showType = true) { EditorGUI.BeginDisabledGroup(!isTitleEditable); field.title = EditorGUILayout.TextField(field.title); EditorGUI.EndDisabledGroup(); // Custom field types: field.value = CustomFieldTypeService.DrawField(field, database); if (showType) { DrawFieldType(field); } }
private void OnDrawVariableElement(Rect rect, int index, bool isActive, bool isFocused) { if (!(variableReorderableList != null && 0 <= index && index < variableReorderableList.count)) { return; } var variable = variableReorderableList.list[index] as Variable; if (variable == null) { return; } if (!variable.FieldExists("Initial Value")) { variable.fields.Add(new Field("Initial Value", string.Empty, FieldType.Text)); } if (!variable.FieldExists("Description")) { variable.fields.Add(new Field("Description", string.Empty, FieldType.Text)); } var initialValueField = Field.Lookup(variable.fields, "Initial Value"); var descriptionField = Field.Lookup(variable.fields, "Description"); var wholeWidth = rect.width - 6f; var typeWidth = Mathf.Min(wholeWidth / 4, 80f); var fieldWidth = (wholeWidth - typeWidth) / 3; var originalColor = GUI.backgroundColor; var variableName = variable.Name; var conflicted = conflictedVariableNames.Contains(variableName); if (conflicted) { GUI.backgroundColor = Color.red; } EditorGUI.BeginChangeCheck(); variable.Name = EditorGUI.TextField(new Rect(rect.x, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), variableName); if (EditorGUI.EndChangeCheck()) { ResetFilteredVariableList(); } if (conflicted) { GUI.backgroundColor = originalColor; } initialValueField.value = CustomFieldTypeService.DrawField(new Rect(rect.x + fieldWidth + 2, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), initialValueField, database); descriptionField.value = EditorGUI.TextField(new Rect(rect.x + 2 * (fieldWidth + 2), rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), descriptionField.value); CustomFieldTypeService.DrawFieldType(new Rect(rect.x + 3 * (fieldWidth + 2), rect.y + 2, typeWidth, EditorGUIUtility.singleLineHeight), initialValueField); }
private void OnSelectVariableTypeToAdd(object data) { if (data == null || data.GetType() != typeof(string) || createNewVariable == null) { return; } var typeName = (string)data; Dictionary <string, CustomFieldType> types = CustomFieldTypeService.GetTypesDictionary(); var variable = createNewVariable(group); var field = Field.Lookup(variable.fields, "Initial Value"); if (types.ContainsKey(typeName) && field != null) { field.type = types[typeName].storeFieldAsType; field.typeString = typeName; } }
private void OnDrawVariableElement(Rect rect, int index, bool isActive, bool isFocused) { if (!(reorderableList != null && 0 <= index && index < reorderableList.count)) { return; } var variable = reorderableList.list[index] as Variable; if (variable == null) { return; } //var nameControl = "VarName" + index; //var descriptionControl = "VarDescription" + index; if (!variable.FieldExists("Initial Value")) { variable.fields.Add(new Field("Initial Value", string.Empty, FieldType.Text)); } if (!variable.FieldExists("Description")) { variable.fields.Add(new Field("Description", string.Empty, FieldType.Text)); } var variableNameField = Field.Lookup(variable.fields, "Name"); var initialValueField = Field.Lookup(variable.fields, "Initial Value"); var descriptionField = Field.Lookup(variable.fields, "Description"); var showRuntimeValue = canShowRuntimeValues && Application.isPlaying; var wholeWidth = rect.width - 6f; var typeWidth = Mathf.Min(wholeWidth / 4, 80f); var fieldWidth = (wholeWidth - typeWidth) / (showRuntimeValue ? 4 : 3); var originalColor = GUI.backgroundColor; var variableName = variableNameField.value; var conflicted = conflictedVariableNames.Contains(variableName); if (conflicted) { GUI.backgroundColor = Color.red; } EditorGUI.BeginChangeCheck(); //GUI.SetNextControlName(nameControl); variableNameField.value = EditorGUI.TextField(new Rect(rect.x, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), variableName); if (EditorGUI.EndChangeCheck()) { refreshVariablesView(); } if (conflicted) { GUI.backgroundColor = originalColor; } rect.x += fieldWidth + 2; initialValueField.value = CustomFieldTypeService.DrawField(new Rect(rect.x, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), initialValueField, database); rect.x += fieldWidth + 2; if (showRuntimeValue) { EditorGUI.BeginDisabledGroup(true); string runtimeValue; if (!runtimeValues.TryGetValue(variableName, out runtimeValue)) { runtimeValue = "???"; } EditorGUI.TextField(new Rect(rect.x, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), runtimeValue); EditorGUI.EndDisabledGroup(); rect.x += fieldWidth + 2; } //GUI.SetNextControlName(descriptionControl); descriptionField.value = EditorGUI.TextField(new Rect(rect.x, rect.y + 2, fieldWidth, EditorGUIUtility.singleLineHeight), descriptionField.value); rect.x += fieldWidth + 2; CustomFieldTypeService.DrawFieldType(new Rect(rect.x, rect.y + 2, typeWidth, EditorGUIUtility.singleLineHeight), initialValueField); //var focusedControl = GUI.GetNameOfFocusedControl(); //if (string.Equals(nameControl, focusedControl) || string.Equals(descriptionControl, focusedControl)) //{ // if (DialogueEditorWindow.instance != null) // { // DialogueEditorWindow.inspectorSelection = variable; // } //} }