private string DrawManualPropertyEditField(GameObject go, string propertPath, Type[] acceptableTypes, DropDownControl<string> dropDown) { var propertyResolver = new PropertyResolver { AllowedTypes = acceptableTypes }; IList<string> list; var loadProps = new Func<string[]>(() => { try { list = propertyResolver.GetFieldsAndPropertiesUnderPath(go, propertPath); } catch (ArgumentException) { list = propertyResolver.GetFieldsAndPropertiesUnderPath(go, ""); } return list.ToArray(); }); EditorGUILayout.BeginHorizontal(); var labelSize = EditorStyles.label.CalcSize(new GUIContent(go.name + '.')); GUILayout.Label(go.name + (propertPath.Length > 0 ? "." : ""), EditorStyles.label, GUILayout.Width(labelSize.x)); string btnName = "hintBtn"; if (GUI.GetNameOfFocusedControl() == btnName && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.DownArrow) { Event.current.Use(); dropDown.PrintMenu(loadProps()); GUI.FocusControl(""); m_FocusBackToEdit = true; } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName(btnName); var result = GUILayout.TextField(propertPath, EditorStyles.textField); if (EditorGUI.EndChangeCheck()) { m_Error = DoesPropertyExist(go, result); } if (m_FocusBackToEdit) { m_FocusBackToEdit = false; GUI.FocusControl(btnName); } if (GUILayout.Button("Clear", EditorStyles.miniButton, GUILayout.Width(38))) { result = ""; GUI.FocusControl(null); m_FocusBackToEdit = true; m_Error = DoesPropertyExist(go, result); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(labelSize.x)); dropDown.Draw("", result ?? "", loadProps, s => { result = s; GUI.FocusControl(null); m_FocusBackToEdit = true; m_Error = DoesPropertyExist(go, result); }); EditorGUILayout.EndHorizontal(); switch (m_Error) { case SelectedPathError.InvalidPath: EditorGUILayout.HelpBox("This property does not exist", MessageType.Error); break; case SelectedPathError.MissingComponent: EditorGUILayout.HelpBox("This property or field is not attached or set. It will fail unless it will be attached before the check is perfomed.", MessageType.Warning); break; } return result; }
private string DrawManualPropertyEditField(GameObject go, string propertPath, Type[] acceptableTypes, DropDownControl <string> dropDown) { var propertyResolver = new PropertyResolver { AllowedTypes = acceptableTypes }; IList <string> list; var loadProps = new Func <string[]> (() => { try { list = propertyResolver.GetFieldsAndPropertiesUnderPath(go, propertPath); } catch (ArgumentException) { list = propertyResolver.GetFieldsAndPropertiesUnderPath(go, ""); } return(list.ToArray()); }); EditorGUILayout.BeginHorizontal(); var labelSize = EditorStyles.label.CalcSize(new GUIContent(go.name + '.')); GUILayout.Label(go.name + (propertPath.Length > 0 ? "." : ""), EditorStyles.label, GUILayout.Width(labelSize.x)); string btnName = "hintBtn"; if (GUI.GetNameOfFocusedControl() == btnName && Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.DownArrow) { Event.current.Use(); dropDown.PrintMenu(loadProps()); GUI.FocusControl(""); focusBackToEdit = true; } EditorGUI.BeginChangeCheck(); GUI.SetNextControlName(btnName); var result = GUILayout.TextField(propertPath, EditorStyles.textField); if (EditorGUI.EndChangeCheck()) { error = DoesPropertyExist(go, result); } if (focusBackToEdit) { focusBackToEdit = false; GUI.FocusControl(btnName); } if (GUILayout.Button("clear", EditorStyles.miniButton, GUILayout.Width(38))) { result = ""; GUI.FocusControl(null); focusBackToEdit = true; error = DoesPropertyExist(go, result); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(labelSize.x)); dropDown.Draw("", result ?? "", loadProps, s => { result = s; GUI.FocusControl(null); focusBackToEdit = true; error = DoesPropertyExist(go, result); }); EditorGUILayout.EndHorizontal(); switch (error) { case SelectedPathError.InvalidPath: EditorGUILayout.HelpBox("This property does not exist", MessageType.Error); break; case SelectedPathError.MissingComponent: EditorGUILayout.HelpBox("This property or field is not attached or set. It will fail unless it will be attached before the check is perfomed.", MessageType.Warning); break; } return(result); }