public static void Display(Type[] repairedTypeOptions, SerializedProperty property) { if (window != null) { window.Close(); } SelectRepairedTypeWindow.repairedTypeOptions = repairedTypeOptions; SelectRepairedTypeWindow.property = property; window = ScriptableObject.CreateInstance(typeof(SelectRepairedTypeWindow)) as SelectRepairedTypeWindow; window.titleContent = new GUIContent("Select repaired type"); window.ShowUtility(); }
private static void DrawTypeSelectionControl(Rect position, SerializedProperty property, GUIContent label, SystemTypeAttribute filter) { try { Color restoreColor = GUI.color; bool restoreShowMixedValue = EditorGUI.showMixedValue; bool typeResolved = string.IsNullOrEmpty(property.stringValue) || ResolveType(property.stringValue) != null; EditorGUI.showMixedValue = property.hasMultipleDifferentValues; GUI.color = enabledColor; if (typeResolved) { property.stringValue = DrawTypeSelectionControl(position, label, property.stringValue, filter, true); } else { if (SelectRepairedTypeWindow.WindowOpen) { GUI.color = disabledColor; DrawTypeSelectionControl(position, label, property.stringValue, filter, false); } else { Rect dropdownPosition = new Rect(position.x, position.y, position.width - 90, position.height); Rect buttonPosition = new Rect(position.x + position.width - 75, position.y, 75, position.height); Color defaultColor = GUI.color; GUI.color = errorColor; property.stringValue = DrawTypeSelectionControl(dropdownPosition, label, property.stringValue, filter, false); GUI.color = defaultColor; if (GUI.Button(buttonPosition, "Try Repair", EditorStyles.miniButton)) { string typeNameWithoutAssembly = property.stringValue.Split(new string[] { "," }, StringSplitOptions.None)[0]; string typeNameWithoutNamespace = System.Text.RegularExpressions.Regex.Replace(typeNameWithoutAssembly, @"[.\w]+\.(\w+)", "$1"); Type[] repairedTypeOptions = FindTypesByName(typeNameWithoutNamespace, filter); if (repairedTypeOptions.Length > 1) { SelectRepairedTypeWindow.Display(repairedTypeOptions, property); } else if (repairedTypeOptions.Length > 0) { property.stringValue = SystemType.GetReference(repairedTypeOptions[0]); } else { EditorUtility.DisplayDialog("No types found", "No types with the name '" + typeNameWithoutNamespace + "' were found.", "OK"); } } } } GUI.color = restoreColor; EditorGUI.showMixedValue = restoreShowMixedValue; } finally { ExcludedTypeCollectionGetter = null; } }
private void OnDisable() { window = null; }