/// <inheritdoc /> protected override void RenderMemberControl(Rect position) { var options = GetNameOptions(); DropdownOption <AnimatorParameter> selectedOption = null; DropdownOption <AnimatorParameter> noneOption = new DropdownOption <AnimatorParameter>(null, "No Parameter"); AnimatorParameter value = GetValue(); if (value != null) { string label = value.name; AnimatorParameter valueInOptions = options.Select(option => option.value).FirstOrDefault(ap => ap.Corresponds(value)); if (valueInOptions != null) { selectedOption = new DropdownOption <AnimatorParameter>(valueInOptions, label); } else { selectedOption = new DropdownOption <AnimatorParameter>(value, label); } } // Make sure the callback uses the property of this drawer, not at its later value. var propertyNow = property; bool enabled = targets.Any(target => target != null); if (!enabled) { EditorGUI.BeginDisabledGroup(true); } DropdownGUI <AnimatorParameter> .PopupSingle ( position, newValue => { Update(propertyNow); SetValue(newValue); propertyNow.serializedObject.ApplyModifiedProperties(); }, options, selectedOption, noneOption, nameProperty.hasMultipleDifferentValues ); if (!enabled) { EditorGUI.EndDisabledGroup(); } }
protected override void InitOption() { List <TMP_Dropdown.OptionData> Options = new List <TMP_Dropdown.OptionData>(); foreach (string Option in typeof(EGraphicQuality).GetEnumNames()) { Options.Add(new TMP_Dropdown.OptionData(Option)); } DropdownOption.AddOptions(Options); DropdownOption.value = QualitySettings.GetQualityLevel();; }
protected override void ProcessRecord() { var ctl = new DropdownOption { Key = Key, Text = Text }; SetControlProps(ctl); WriteObject(ctl); }
public SessionViewModel(IQueryable <FeedbackCondition> feedbackOptions, IQueryable <Profile> profileOptions, IQueryable <Participant> participantOptions, Session existingSession = null) { bool setValues = (existingSession != null); FeedbackOptions = new List <DropdownOption>(); foreach (var opt in feedbackOptions) { var dropdownOption = new DropdownOption(opt); if (setValues && existingSession.FeedbackCondition.Id == opt.Id) { dropdownOption.DefaultSelected = true; } FeedbackOptions.Add(dropdownOption); } ParticipantOptions = new List <DropdownOption>(); foreach (var opt in participantOptions) { var dropdownOption = new DropdownOption(opt); if (setValues && existingSession.Participant.Id == opt.Id) { dropdownOption.DefaultSelected = true; } ParticipantOptions.Add(dropdownOption); } TrialBlocks = new List <TrialBlockViewModel>(); if (setValues) { WordListId = existingSession.WordListId ?? 0; SessionID = existingSession.Id.ToString(); Name = existingSession.Name; foreach (var block in existingSession.TrialBlocks) { var blockVM = new TrialBlockViewModel(block, profileOptions); TrialBlocks.Add(blockVM); } Completed = existingSession.Completed; } else { Completed = false; SessionID = null; for (int x = 0; x < 8; x++) { var newTB = new TrialBlockViewModel(profileOptions); newTB.IndexInSession = x; TrialBlocks.Add(newTB); } } TrialBlocks = TrialBlocks.OrderBy(x => x.IndexInSession).ToList(); }
protected override void InitOption() { List <string> options = new List <string>(); int value = -1; for (int i = 0; i < Screen.resolutions.Length; i++) { Resolution resolution = Screen.resolutions[i]; int currentRefreshRate = Screen.currentResolution.refreshRate; options.Add(resolution.ToString()); if (resolution.width == Screen.currentResolution.width && resolution.height == Screen.currentResolution.height && (currentRefreshRate - 1 <= resolution.refreshRate || resolution.refreshRate <= currentRefreshRate + 1)) //Refresh rate has +-1 margin { value = i; } } DropdownOption.AddOptions(options); DropdownOption.value = value; }
public static List <SelectListItem> ToSelectList <T>(this IEnumerable <T> array, object selectedValue = null, SelectListItem emptyOption = null) { List <SelectListItem> selectList = new List <SelectListItem>(); DropdownOption option; string text, value, selectedValueText = (selectedValue ?? "").ToString(); bool selected; if (emptyOption != null) { selectList.Add(emptyOption); } foreach (object item in array) { if (item.GetType() == typeof(DropdownOption)) { option = (DropdownOption)item; } else { option = new DropdownOption { Text = item.ToString(), Value = item.ToString() } }; text = (option.Text ?? "").ToString(); value = (option.Value ?? "").ToString(); selected = selectedValueText != null && (value == selectedValueText); selectList.Add(new SelectListItem { Text = text, Value = value, Selected = selected }); } return(selectList); }
/// <inheritdoc /> protected override void RenderMemberControl(Rect position) { // Other Targets // Some Unity Objects, like Assets, are not supported by the drawer. // Just display an error message to let the user change their target. if (targetType == UnityObjectType.Other) { EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None); return; } // Display a list of all available reflected members in a popup. UnityMember value = GetValue(); DropdownOption <UnityMember> selectedOption = null; if (value != null) { if (targetType == UnityObjectType.GameObject) { string label; if (value.component == null) { label = string.Format("GameObject.{0}", value.name); } else { label = string.Format("{0}.{1}", value.component, value.name); } // There seems to be no way of differentiating between null parameter types // (fields, properties and implicitly typed methods) and zero parameter types // because Unity's serialized property array cannot be assigned to null, only // given an array size of zero. // TODO: The solution would be to use a single comma-separated // string instead of an array of strings, which we could differentiate manually. if (value.parameterTypes != null && value.parameterTypes.Length > 0) { string parameterString = string.Join(", ", value.parameterTypes.Select(t => t.PrettyName()).ToArray()); label += string.Format(" ({0})", parameterString); } selectedOption = new DropdownOption <UnityMember>(value, label); } else if (targetType == UnityObjectType.ScriptableObject) { selectedOption = new DropdownOption <UnityMember>(value, value.name); } } bool enabled = targetType != UnityObjectType.None; if (!enabled) { EditorGUI.BeginDisabledGroup(true); } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues; value = DropdownGUI <UnityMember> .PopupSingle ( position, GetAllMemberOptions, selectedOption, new DropdownOption <UnityMember>(null, string.Format("Nothing")) ); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SetValue(value); } if (!enabled) { EditorGUI.EndDisabledGroup(); } }
public static string GetText(this DropdownOption dropdownOption) => dropdownOption == DropdownOption.Default ? "Please select an option" : $"Option {GetIndex(dropdownOption)}";
public static string GetValue(this DropdownOption dropdownOption) => dropdownOption == DropdownOption.Default ? string.Empty : GetIndex(dropdownOption).ToString();
public static int GetIndex(this DropdownOption dropdownOption) => (int)dropdownOption;
private void AddJobOption(DropdownOption option) => _jobListDropdown.AddOptions(new List <Dropdown.OptionData> { option });
public ParallelDropdownsBuilder <T> Prepend(DropdownOption option) { _options.TryAdd(_memberName.Key, new Dropdown(new [] { option }, _memberName.Name)); return(this); }
/// <inheritdoc /> protected override void RenderMemberControl(Rect position) { // Other Targets // Some Unity Objects, like Assets, are not supported by the drawer. // Just display an error message to let the user change their target. if (targetType == UnityObjectType.Other) { EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None); return; } // Display a list of all available reflected members in a popup. var options = new List <DropdownOption <TMember> >(); TMember value = GetValue(); DropdownOption <TMember> selectedOption = null; DropdownOption <TMember> noneOption = new DropdownOption <TMember>(null, string.Format("No {0}", memberLabel)); if (targetType == UnityObjectType.GameObject) { // Check if all targets have a GameObject (none are empty). // If they do, display all members of the GameObject type. if (HasSharedGameObject()) { var gameObjectOptions = GetSortedMemberOptions(typeof(GameObject)); foreach (var gameObjectOption in gameObjectOptions) { // Prefix label by GameObject for popup clarity. gameObjectOption.label = string.Format("GameObject/{0}", gameObjectOption.label); options.Add(gameObjectOption); } } // Find all shared component types across targets. // Display all members of each one found. foreach (Type componentType in GetSharedComponentTypes()) { var componentOptions = GetSortedMemberOptions(componentType, componentType.Name); foreach (var componentOption in componentOptions) { // Prefix label and option by component type for clear distinction. componentOption.label = string.Format("{0}/{1}", componentType.Name, componentOption.label); options.Add(componentOption); } } // Determine which option is currently selected. if (value != null) { string label; if (value.component == null) { label = string.Format("GameObject.{0}", value.name); } else { label = string.Format("{0}.{1}", value.component, value.name); } UnityMethod method = value as UnityMethod; if (method != null) { string parameterString = string.Join(", ", method.parameterTypes.Select(t => t.PrettyName()).ToArray()); label += string.Format(" ({0})", parameterString); } TMember valueInOptions = options.Select(option => option.value).FirstOrDefault(member => member.Corresponds(value)); if (valueInOptions != null) { selectedOption = new DropdownOption <TMember>(valueInOptions, label); } else { selectedOption = new DropdownOption <TMember>(value, label); } } } else if (targetType == UnityObjectType.ScriptableObject) { // ScriptableObject Target // Make sure all targets share the same ScriptableObject Type. // If they do, display all members of that type. Type scriptableObjectType = GetSharedScriptableObjectType(); if (scriptableObjectType != null) { options.AddRange(GetSortedMemberOptions(scriptableObjectType)); // Determine which option is currently selected. if (value != null) { selectedOption = options.Find(o => o.value.Corresponds(value)); if (selectedOption == null) { selectedOption = new DropdownOption <TMember>(value, value.name); } } } } // Make sure the callback uses the property of this drawer, not at its later value. var propertyNow = property; bool enabled = targetType != UnityObjectType.None; if (!enabled) { EditorGUI.BeginDisabledGroup(true); } DropdownGUI <TMember> .PopupSingle ( position, newValue => { Update(propertyNow); SetValue(newValue); propertyNow.serializedObject.ApplyModifiedProperties(); }, options, selectedOption, noneOption, hasMultipleDifferentValues ); if (!enabled) { EditorGUI.EndDisabledGroup(); } }
/// <inheritdoc /> protected override void RenderMemberControl(Rect position) { // Other Targets // Some Unity Objects, like Assets, are not supported by the drawer. // Just display an error message to let the user change their target. if (targetType == UnityObjectType.Other) { EditorGUI.HelpBox(position, "Unsupported Unity Object type.", MessageType.None); return; } // Display a list of all available reflected members in a popup. UnityMember value = GetValue(); DropdownOption<UnityMember> selectedOption = null; if (value != null) { if (targetType == UnityObjectType.GameObject) { string label; if (value.component == null) { label = string.Format("GameObject.{0}", value.name); } else { label = string.Format("{0}.{1}", value.component, value.name); } // There seems to be no way of differentiating between null parameter types // (fields, properties and implicitly typed methods) and zero parameter types // because Unity's serialized property array cannot be assigned to null, only // given an array size of zero. // TODO: The solution would be to use a single comma-separated // string instead of an array of strings, which we could differentiate manually. if (value.parameterTypes != null && value.parameterTypes.Length > 0) { string parameterString = string.Join(", ", value.parameterTypes.Select(t => t.PrettyName()).ToArray()); label += string.Format(" ({0})", parameterString); } selectedOption = new DropdownOption<UnityMember>(value, label); } else if (targetType == UnityObjectType.ScriptableObject) { selectedOption = new DropdownOption<UnityMember>(value, value.name); } } bool enabled = targetType != UnityObjectType.None; if (!enabled) EditorGUI.BeginDisabledGroup(true); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = nameProperty.hasMultipleDifferentValues; value = DropdownGUI<UnityMember>.PopupSingle ( position, GetAllMemberOptions, selectedOption, new DropdownOption<UnityMember>(null, string.Format("Nothing")) ); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { SetValue(value); } if (!enabled) EditorGUI.EndDisabledGroup(); }
public ParallelDropdownBuilderConfiguration <T> Prepend(DropdownOption option) { _builder.Prepend(option); return(this); }
private void OtherDropdownViewAction(DropdownOption selectedOption) { Debug.Log($"This is the other automatically assigned dropdown action: {selectedOption.text}"); }
protected override void InitOption() { string[] options = typeof(FullScreenMode).GetEnumNames(); DropdownOption.AddOptions(options.ToList()); DropdownOption.value = Array.IndexOf(options, Screen.fullScreenMode.ToString()); }