public static void Open(Rect rect, List <SearchProposition> models, Action <int> elementSelectedHandler) { var win = new ListSelectionWindow(rect, models, elementSelectedHandler); win.Show(rect); win.Bind(); }
static void OnGUIHandler(string obj) { if (m_MaxLabelWidth == 0) { m_MaxLabelWidth = Get().dependencyTypeInfos.Select(ti => ti.content).Max(content => EditorStyles.label.CalcSize(content).x); m_MaxLabelWidth = Mathf.Min(kMaxLabelWidth, m_MaxLabelWidth); } var settings = Get(); using (new SettingsWindow.GUIScope()) { var oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = m_MaxLabelWidth; if (Unsupported.IsDeveloperMode()) { if (GUILayout.Button(L10n.Tr("Clear Scene Template Preferences"))) { ClearPreferences(); } } EditorGUI.BeginChangeCheck(); settings.newSceneOverride = (NewSceneOverride)EditorGUILayout.EnumPopup(L10n.TextContent("New Scene Menu"), settings.newSceneOverride, GUILayout.Width(m_MaxLabelWidth + 150), GUILayout.ExpandWidth(false)); if (EditorGUI.EndChangeCheck()) { Save(); } GUILayout.Space(Styles.verticalSpace); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label(L10n.Tr("Default types"), EditorStyles.boldLabel, GUILayout.Width(m_MaxLabelWidth - 15)); GUILayout.Label(L10n.Tr("Clone"), EditorStyles.boldLabel); } foreach (var depInfo in settings.dependencyTypeInfos) { if (depInfo.ignore || !depInfo.supportsModification) { continue; } using (new EditorGUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); var toClone = EditorGUILayout.Toggle(depInfo.content, depInfo.defaultInstantiationMode == TemplateInstantiationMode.Clone, GUILayout.Width(m_MaxLabelWidth + 20)); if (EditorGUI.EndChangeCheck()) { depInfo.defaultInstantiationMode = toClone ? TemplateInstantiationMode.Clone : TemplateInstantiationMode.Reference; Save(); } if (GUILayout.Button(L10n.Tr("Remove"), GUILayout.Width(Styles.buttonWidth))) { settings.dependencyTypeInfos.Remove(depInfo); Save(); GUIUtility.ExitGUI(); } } } GUILayout.Space(Styles.verticalSpace); EditorGUI.BeginChangeCheck(); var clone = EditorGUILayout.Toggle(L10n.TextContent("All Other Types"), settings.defaultDependencyTypeInfo.defaultInstantiationMode == TemplateInstantiationMode.Clone); if (EditorGUI.EndChangeCheck()) { settings.defaultDependencyTypeInfo.defaultInstantiationMode = clone ? TemplateInstantiationMode.Clone : TemplateInstantiationMode.Reference; Save(); } EditorGUIUtility.labelWidth = oldLabelWidth; GUILayout.Space(Styles.verticalSpace); using (new EditorGUILayout.HorizontalScope()) { var listDropDownBtnRect = EditorGUILayout.GetControlRect(false, GUILayout.Width(Styles.addTypeButtonWidth)); if (EditorGUI.DropdownButton(listDropDownBtnRect, Styles.addTypeContent, FocusType.Passive, GUI.skin.button)) { var alreadyAddedTypeIds = settings.dependencyTypeInfos.Select(d => d.type); var typeIdsSet = new HashSet <string>(alreadyAddedTypeIds); var availablePropositions = m_AllTypesPropositions.Where(p => !typeIdsSet.Contains(p.type.FullName)).ToList(); ListSelectionWindow.Open(listDropDownBtnRect, availablePropositions, selectedIndex => { if (selectedIndex != -1) { var type = availablePropositions[selectedIndex].type; AddNewType(type); } }); } } GUILayout.Space(Styles.verticalSpace); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button(L10n.Tr("Reset Defaults"))) { ResetDefaults(); } GUILayout.FlexibleSpace(); } EditorGUIUtility.labelWidth = oldLabelWidth; } }
private static void OnGUIHandler(string obj) { var settings = Get(); using (new SettingsWindow.GUIScope()) { var oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = Styles.labelWidth; if (Unsupported.IsDeveloperMode()) { if (GUILayout.Button("Clear Scene Template Preferences")) { ClearPreferences(); } } using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("Default types", EditorStyles.boldLabel, GUILayout.Width(285)); GUILayout.Label("Clone", EditorStyles.boldLabel); } foreach (var depInfo in settings.dependencyTypeInfos) { if (depInfo.ignore || !depInfo.supportsModification) { continue; } using (new EditorGUILayout.HorizontalScope()) { EditorGUI.BeginChangeCheck(); var toClone = EditorGUILayout.Toggle(new GUIContent(depInfo.label), depInfo.defaultInstantiationMode == TemplateInstantiationMode.Clone, GUILayout.Width(325)); if (EditorGUI.EndChangeCheck()) { depInfo.defaultInstantiationMode = toClone ? TemplateInstantiationMode.Clone : TemplateInstantiationMode.Reference; Save(k_Path, settings); } if (GUILayout.Button("Remove", GUILayout.Width(Styles.buttonWidth))) { settings.dependencyTypeInfos.Remove(depInfo); Save(k_Path, settings); GUIUtility.ExitGUI(); } } } GUILayout.Space(Styles.verticalSpace); EditorGUI.BeginChangeCheck(); var clone = EditorGUILayout.Toggle(new GUIContent("All Other Types"), settings.defaultDependencyTypeInfo.defaultInstantiationMode == TemplateInstantiationMode.Clone); if (EditorGUI.EndChangeCheck()) { settings.defaultDependencyTypeInfo.defaultInstantiationMode = clone ? TemplateInstantiationMode.Clone : TemplateInstantiationMode.Reference; Save(k_Path, settings); } GUILayout.Space(Styles.verticalSpace); using (new EditorGUILayout.HorizontalScope()) { GUILayout.Label("Add Type", EditorStyles.boldLabel, GUILayout.Width(Styles.buttonWidth)); EditorGUI.BeginChangeCheck(); m_TypeToAddLabel = GUILayout.TextField(m_TypeToAddLabel); if (EditorGUI.EndChangeCheck()) { // User has overridden the type. m_TypeToAdd = null; } var listDropDownBtnRect = EditorGUILayout.GetControlRect(false, GUILayout.Width(Styles.buttonWidth)); ListSelectionWindow.SelectionButton(listDropDownBtnRect, Styles.typeSelectorWindowSize, new GUIContent("Browse..."), GUI.skin.button, m_AllTypesLabels, selectedIndex => { if (selectedIndex != -1) { m_TypeToAddLabel = m_AllTypesLabels[selectedIndex]; m_TypeToAdd = m_AllTypes[selectedIndex]; } }); using (new EditorGUI.DisabledScope(string.IsNullOrEmpty(m_TypeToAddLabel))) if (GUILayout.Button("Add", GUILayout.Width(Styles.buttonWidth))) { var typeId = m_TypeToAdd != null ? m_TypeToAdd.FullName : m_TypeToAddLabel; if (settings.dependencyTypeInfos.Find(d => d.type == typeId) == null) { settings.dependencyTypeInfos.Add(new DependencyTypeInfo(typeId, m_TypeToAddLabel) { defaultInstantiationMode = TemplateInstantiationMode.Clone, userAdded = true }); Sort(settings.dependencyTypeInfos); Save(k_Path, settings); m_TypeToAddLabel = ""; m_TypeToAdd = null; GUIUtility.ExitGUI(); } else { Debug.LogWarning($"Already a dependency information for type: {typeId}"); } } } GUILayout.Space(Styles.verticalSpace); using (new EditorGUILayout.HorizontalScope()) { if (GUILayout.Button("Reset Defaults")) { ResetDefaults(); } GUILayout.FlexibleSpace(); } EditorGUIUtility.labelWidth = oldLabelWidth; } }