private bool DrawComparerSelection(AssertionComponent script) { if (allComparersList == null) { allComparersList = new List <Type>(); var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (var assembly in allAssemblies) { var types = assembly.GetTypes(); allComparersList.AddRange(types.Where(type => type.IsSubclassOf(typeof(ActionBase)) && !type.IsAbstract)); } } var allComparers = allComparersList.ToArray(); if (script.Action == null) { script.Action = (ActionBase)CreateInstance(allComparers.First()); } m_ComparerDropDown.Draw(script.Action.GetType(), allComparers, type => { if (script.Action == null || script.Action.GetType().Name != type.Name) { script.Action = (ActionBase)CreateInstance(type); AssertionExplorerWindow.Reload(); } }); return(script.Action != null); }
private string DrawListOfMethods(GameObject go, ActionBase comparer, string propertPath, Type[] accepatbleTypes, DropDownControl <string> dropDown) { string result = propertPath; if (accepatbleTypes == null) { result = DrawManualPropertyEditField(go, propertPath, accepatbleTypes, dropDown); } else { bool isPropertyOrFieldFound = true; if (string.IsNullOrEmpty(result)) { var options = GetFieldsAndProperties(go, comparer, result, accepatbleTypes); isPropertyOrFieldFound = options.Any(); if (isPropertyOrFieldFound) { result = options.First(); } } if (isPropertyOrFieldFound) { dropDown.Draw(go.name + '.', result, () => { try { var options = GetFieldsAndProperties(go, comparer, result, accepatbleTypes); return(options.ToArray()); } catch (Exception) { Debug.LogWarning("An exception was thrown while resolving property list. Reseting property path."); result = ""; return(new string[0]); } }, s => result = s); } else { result = DrawManualPropertyEditField(go, propertPath, accepatbleTypes, dropDown); } } return(result); }
private bool DrawComparerSelection(AssertionComponent script) { var types = typeof(ActionBase).Assembly.GetTypes(); var allComparers = types.Where(type => type.IsSubclassOf(typeof(ActionBase)) && !type.IsAbstract).ToArray(); if (script.Action == null) { script.Action = (ActionBase)CreateInstance(allComparers.First()); } comparerDropDown.Draw(script.Action.GetType(), allComparers, type => { if (script.Action == null || script.Action.GetType().Name != type.Name) { script.Action = (ActionBase)CreateInstance(type); AssertionExplorerWindow.Reload(); } }); return(script.Action != null); }
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()) { errorType = 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; errorType = 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; errorType = DoesPropertyExist(go, result); }); EditorGUILayout.EndHorizontal(); if (errorType != ErrorType.None) { if (errorType == ErrorType.MissingComponent) { EditorGUILayout.HelpBox("This property or field is not attached or set. It will fail unless it will be attached before check is perfomed.", MessageType.Warning); } else if (errorType == ErrorType.DoesNotExist) { EditorGUILayout.HelpBox("This property does not exist", MessageType.Error); } } return(result); }