/// <summary> /// Do the UI elements for the ignore list /// </summary> private static void HandleIgnoreListPreferences() { if (_ignoreList == null) { _ignoreList = PreferencesSerialization .LoadIgnoreList() .ToList(); } EditorGUILayout.LabelField("Ignore list - enter the name of a GameObject to ignore when scanning (case sensitive)"); GUILayout.Space(5); var rect = EditorGUILayout.BeginHorizontal(); rect = new Rect(rect.x, rect.y - CellMargin, rect.width, 10 + CellMargin); EditorGUI.DrawRect(new Rect(rect.x, rect.y, rect.width, 55 + CellMargin * 2f), new Color(0.5f, 0.5f, 0.5f, 0.3f));//the drawn rectangle is bigger than the actual rectangle to include the buttons EditorGUI.LabelField(rect, "Use +/- buttons to increase or decrease number of items in ignore list: (" + _ignoreList.Count.ToString() + ")"); EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (GUILayout.Button("+", GUILayout.Width(40))) { var blacklistItem = new BlacklistItem(string.Empty, ignoreChildren: false); _ignoreList.Add(blacklistItem); } if (GUILayout.Button("-", GUILayout.Width(40)) && _ignoreList.Count > 0) { _ignoreList.RemoveAt(_ignoreList.Count - 1); _dirtyIgnoreList = true; } GUILayout.Space(18); if (_ignoreList.Count != 0) { // Handle UI and save changes to local ignoreList for (int i = 0; i < _ignoreList.Count; i++) { _ignoreList[i] = HandleIndividualIgnoreItem(_ignoreList[i]); } } // Save the inputs, if anything changed if (_dirtyIgnoreList) { PreferencesSerialization.SaveIgnoreList(_ignoreList); _dirtyIgnoreList = false; } }
/// <summary> /// Draws the UI element for each ignore item, and saves the values into the list for use /// </summary> private static BlacklistItem HandleIndividualIgnoreItem(BlacklistItem blacklistItem) { var rect = EditorGUILayout.BeginHorizontal(); rect = new Rect(rect.x, rect.y - CellMargin, rect.width, rect.height + CellMargin * 2f); EditorGUI.DrawRect(rect, new Color(0.5f, 0.5f, 0.5f, 0.3f)); EditorGUILayout.LabelField("GameObject name: ", GUILayout.Width(112)); var name = EditorGUILayout.TextField(blacklistItem.Name, GUILayout.Width(250)); EditorGUILayout.LabelField(" Also ignore children: ", GUILayout.Width(137)); var ignoreChildren = EditorGUILayout.Toggle(blacklistItem.IgnoreChildren, GUILayout.Width(15)); EditorGUILayout.EndHorizontal(); GUILayout.Space(14); if (name != blacklistItem.Name || ignoreChildren != blacklistItem.IgnoreChildren) { _dirtyIgnoreList = true; } return(new BlacklistItem(name.Trim(), ignoreChildren)); }