private void UpdatePresetField() { var presetParent = rootVisualElement.Q <VisualElement>("Preset"); presetParent.Clear(); PresetData.LoadPresets(this.currentTypeInfo.type, this.presetList); if (this.presetList.Count > 0) { presetPopup = new PopupField <PresetData>(this.presetList, 0, PresetDataToString, PresetDataToString); #if UNITY_2019_1_OR_NEWER || UNITY_2019_OR_NEWER presetPopup.RegisterValueChangedCallback((val) => { this.currentPreset = val.newValue; }); #else presetPopup.OnValueChanged((val) => { this.currentPreset = val.newValue; }); #endif currentPreset = this.presetList[0]; presetParent.Add(presetPopup); } }
private VisualElement CreateWorldSceneField(ChapterNode chapterNode) { var worldScenes = GameFrameworkSettings.Database.GetGameData <DefaultWorldsSO>(2).GetSceneNames(chapterNode.WorldScene.world).ToList(); if (worldScenes.Count == 0) { worldScenes = new List <string>() { "" } } ; PopupField <string> field = new PopupField <string>( "World Scene", worldScenes, 0) { index = chapterNode.WorldScene.worldScene }; field.RegisterValueChangedCallback((v) => { owner.RegisterCompleteObjectUndo("Updated chapterNode worldScene"); var val = chapterNode.WorldScene; val.worldScene = field.index; chapterNode.WorldScene = val; }); return(field); }
private VisualElement CreateLevelCategoryField(ChapterNode chapterNode) { var levelNames = GameFrameworkSettings.Database.GetGameData <DefaultLevelCategoriesSO>(3).ArchetypeNames; levelNames = EditorUtilities.GetNoneSelectableFrom(levelNames); PopupField <string> field = new PopupField <string>( "Level Category", levelNames.ToList(), 0) { index = chapterNode.LevelScene.levelCategory + 1 }; field.RegisterValueChangedCallback((v) => { owner.RegisterCompleteObjectUndo("Updated chapterNode levelCategory"); var val = chapterNode.LevelScene; val.levelCategory = field.index - 1; chapterNode.LevelScene = val; var veIdx = controlsContainer.IndexOf(_levelSceneField); controlsContainer.RemoveAt(veIdx); _levelSceneField = CreateLevelSceneField(chapterNode); controlsContainer.Insert(veIdx, _levelSceneField); }); return(field); }
private void InitPackageVersion() { _packageVersionRoot = new VisualElement { name = "package_version_root" }; Add(_packageVersionRoot); // 插件版本UI用代码生成,不用uxml的原因是PopupField组件不能用uxml _getGitTagsButton = new Button { name = "get_git_tags", text = "获取版本信息" }; _packageVersionRoot.Add(_getGitTagsButton); _tagsList = new List <string> { "-select version-" }; _versionTagsPopupField = new PopupField <string>("Version:", _tagsList, 0) { value = "-select version-" }; _versionTagsPopupField.SetEnabled(false); _packageVersionRoot.Add(_versionTagsPopupField); _changeVersionButton = new Button { name = "change_version", text = "切换版本" }; _changeVersionButton.SetEnabled(false); _packageVersionRoot.Add(_changeVersionButton); }
public StyleField(string label) : base(label) { AddToClassList(s_UssClassName); styleSheets.Add(BuilderPackageUtilities.LoadAssetAtPath <StyleSheet>(s_UssPath)); var template = BuilderPackageUtilities.LoadAssetAtPath <VisualTreeAsset>(s_UxmlPath); template.CloneTree(this); visualInput = this.Q(s_VisualInputName); m_TextField = this.Q <TextField>(s_TextFieldName); m_TextField.isDelayed = true; var popupContainer = this.Q(s_OptionsPopupContainerName); m_StyleKeywords = StyleFieldConstants.KLDefault; m_CachedRegularOptionsList = GenerateAdditionalOptions(string.Empty); m_AllOptionsList = new List <string>(); m_AllOptionsList.AddRange(m_CachedRegularOptionsList); m_AllOptionsList.AddRange(m_StyleKeywords); m_OptionsPopup = new PopupField <string>(m_AllOptionsList, 0, OnFormatSelectedValue); m_OptionsPopup.AddToClassList(s_OptionsPopupUssClassName); popupContainer.Add(m_OptionsPopup); m_TextField.RegisterValueChangedCallback(OnTextFieldValueChange); m_OptionsPopup.RegisterValueChangedCallback(OnPopupFieldValueChange); }
protected override void OnEnable() { base.OnEnable(); rootVisualElement.styleSheets.Add(Resources.Load <StyleSheet>(MainStyleSheet)); VisualTreeAsset mainVisualTree = Resources.Load <VisualTreeAsset>(WindowLayout); mainVisualTree.CloneTree(rootVisualElement); _filter = rootVisualElement.Q <TextField>("component-filter"); _filter.RegisterValueChangedCallback(FilterChangedEventHandler); // TODO: remove the filter for now, we likely want to change // from using a PopupField to a ListView so that filtering actually works _filter.parent.Remove(_filter); VisualElement componentTypesContainer = rootVisualElement.Q <VisualElement>("container-component-type"); _componentTypePopup = new PopupField <string>("Component Type:", _componentNames, 0); _componentTypePopup.RegisterValueChangedCallback(OnComponentTypeChanged); componentTypesContainer.Add(_componentTypePopup); _selectedPrefabsContainer = rootVisualElement.Q <VisualElement>("container-selected-prefabs"); }
private void UpdateBonePopup(string[] names) { VisualElement boneElement = null; if (m_ModeField != null && mode == WeightEditorMode.Smooth) { boneElement = this.Q <VisualElement>("Bone"); boneElement.SetHiddenFromLayout(false); } if (m_BonePopup != null) { m_BonePopupContainer.Remove(m_BonePopup); } m_BonePopup = new PopupField <string>(new List <string>(names), 0); m_BonePopup.name = "BonePopupField"; m_BonePopup.label = TextContent.bone; m_BonePopup.tooltip = TextContent.boneToolTip; m_BonePopup.RegisterValueChangedCallback((evt) => { bonePopupChanged(boneIndex); }); m_BonePopupContainer.Add(m_BonePopup); if (boneElement != null) { boneElement.SetHiddenFromLayout(true); } }
protected override VisualElement CreateValueElement(SerializedProperty property) { if (!CheckUsedTypeAttr(property, null)) { return(new Label("Please Use UsedEnum Attribute")); } var inst = property.GetSelf() as KeyEnumObject; if (inst.IsFlags) { return(new Label("Not Support yet FlagsEnum...")); //System.Enum defaultValue; //if(inst.IsValid) //{ // defaultValue = inst.Value; //} //else //{ // defaultValue = (System.Enum)System.Enum.GetValues(inst.Value.GetType()).GetValue(0); //} //var enumField = new EnumField(defaultValue) //{ // bindingPath = $"{property.propertyPath}._value", //}; //return enumField; } else { var names = inst.HasType.GetEnumNames().ToList(); int index; if (inst.IsValid) { index = inst.EnumIndex; } else { index = names.Count; names.Add("!! Invalid Value !!"); } //var newValue = EditorGUI.Popup(position, index, names.ToArray()); //if (scope.changed) //{ // valueProp.intValue = newValue; //} var enumField = new PopupField <string>(names, index) { bindingPath = $"{property.propertyPath}._value", }; return(enumField); //DrawStandardEnum(inst, position, property, label); } //return new Label("Not Support UIElement Enum..."); }
static VisualElement CreatePropertyGUI(SerializedProperty property, List <TriggerTarget> targetChoices, Func <TriggerTarget, string> formatTarget) { var container = new VisualElement(); var targetProperty = property.FindPropertyRelative("target"); var currentTarget = (TriggerTarget)targetProperty.enumValueIndex; var selectingTarget = targetChoices.Contains(currentTarget) ? currentTarget : targetChoices[0]; var specifiedTargetItemField = new PropertyField(property.FindPropertyRelative("specifiedTargetItem")); void SwitchSpecifiedTargetItemField(TriggerTarget itemTriggerTarget) { specifiedTargetItemField.SetVisibility(itemTriggerTarget == TriggerTarget.SpecifiedItem); } var targetField = EnumField.Create(targetProperty.displayName, targetProperty, targetChoices, selectingTarget, formatTarget, SwitchSpecifiedTargetItemField); targetField.SetEnabled(targetChoices.Count > 1); SwitchSpecifiedTargetItemField((TriggerTarget)targetProperty.enumValueIndex); var keyField = new PropertyField(property.FindPropertyRelative("key")); var typeProperty = property.FindPropertyRelative("type"); var typeField = new PopupField <string>("Parameter Type") { bindingPath = "type" }; var valueProperty = property.FindPropertyRelative("value"); var valueField = new VisualElement(); var boolValueField = new PropertyField(valueProperty.FindPropertyRelative("boolValue")); var floatValueField = new PropertyField(valueProperty.FindPropertyRelative("floatValue")); var integerValueField = new PropertyField(valueProperty.FindPropertyRelative("integerValue")); valueField.Add(boolValueField); valueField.Add(floatValueField); valueField.Add(integerValueField); void SwitchTriggerValueField(ParameterType parameterType) { boolValueField.SetVisibility(parameterType == ParameterType.Bool); floatValueField.SetVisibility(parameterType == ParameterType.Float); integerValueField.SetVisibility(parameterType == ParameterType.Integer); } typeField.RegisterValueChangedCallback(e => { SwitchTriggerValueField((ParameterType)Enum.Parse(typeof(ParameterType), e.newValue)); }); SwitchTriggerValueField((ParameterType)typeProperty.enumValueIndex); container.Add(targetField); container.Add(specifiedTargetItemField); container.Add(keyField); container.Add(typeField); container.Add(valueField); return(container); }
public DiffusionProfileSlotControlView(DiffusionProfileInputMaterialSlot slot) { styleSheets.Add(Resources.Load <StyleSheet>("DiffusionProfileSlotControlView")); m_Slot = slot; popupField = new PopupField <string>(m_Slot.diffusionProfile.popupEntries, m_Slot.diffusionProfile.selectedEntry); popupField.RegisterValueChangedCallback(RegisterValueChangedCallback); Add(popupField); }
public DiffusionProfileSlotControlView(DiffusionProfileInputMaterialSlot slot) { AddStyleSheetPath("DiffusionProfileSlotControlView"); m_Slot = slot; popupField = new PopupField <string>(m_Slot.diffusionProfile.popupEntries, m_Slot.diffusionProfile.selectedEntry); popupField.OnValueChanged(OnValueChanged); Add(popupField); }
private BaseInputControl CreateCustomPopupField(ScreenCustomField field) { PopupField popupField = new PopupField(); popupField.PopupUrl = field.PopupUrl; popupField.DataBoundText = "_customFields." + field.Name + ".Text"; return(popupField); }
public void Initialize(VisualElement rootVisualElement) { m_Root = UIElementHelpers.LoadTemplate(kBasePath, "StartLiveLinkWindow"); m_Root.style.flexGrow = 1; m_SearchField = m_Root.Q <ToolbarSearchField>(kNamePrefix + "body__search"); m_SearchField.RegisterValueChangedCallback(evt => FilterConfigurations()); m_EmptyMessage = m_Root.Q <VisualElement>(kNamePrefix + "body__empty-message"); m_ConfigurationsListView = m_Root.Q <ListView>(kNamePrefix + "body__configurations-list"); m_ConfigurationsListView.makeItem = CreateBuildConfigurationItemVisualElement; m_ConfigurationsListView.bindItem = BindBuildConfigurationItem; m_ConfigurationsListView.itemsSource = m_FilteredBuildConfigurationViewModels; m_ConfigurationsListView.selectionType = SelectionType.Single; #if UNITY_2020_1_OR_NEWER m_ConfigurationsListView.onSelectionChange += OnConfigurationListViewSelectionChange; m_ConfigurationsListView.onItemsChosen += chosenConfigurations => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfigurations.First()); #else m_ConfigurationsListView.onSelectionChanged += OnConfigurationListViewSelectionChanged; m_ConfigurationsListView.onItemChosen += chosenConfiguration => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfiguration); #endif m_AddNewButton = m_Root.Q <Button>(kNamePrefix + "body__new-build-button"); m_AddNewButton.clicked += ShowNewBuildNameInput; m_NewBuildName = m_Root.Q <VisualElement>(kNamePrefix + "new-build-name"); m_NewBuildNameTextField = m_NewBuildName.Q <TextField>(); m_NewBuildNameSubmit = m_NewBuildName.Q <Button>(kNamePrefix + "new-build-name__submit"); m_NewBuildNameTextField.RegisterCallback <KeyDownEvent>(OnNewBuildKeyDown); m_NewBuildNameTextField.RegisterCallback <BlurEvent>(OnNewBuildFocusChanged); m_NewBuildName.Hide(); m_BuildMessage = m_Root.Q <VisualElement>(kNamePrefix + "build-message"); m_BuildMessage.Hide(); m_ActionButtons = m_Root.Q <VisualElement>(kNamePrefix + "footer"); m_StartModeDropdown = new PopupField <StartMode>(sStartModes, StartMode.RunLatestBuild, FormatStartMode, FormatStartMode) { style = { flexGrow = 1 } }; m_StartModeDropdown.RegisterValueChangedCallback(OnSelectedStartModeChanged); m_ActionButtons.Q <VisualElement>(kNamePrefix + "footer__build-mode-container").Add(m_StartModeDropdown); m_StartButton = m_ActionButtons.Q <Button>(kNamePrefix + "footer__start-button"); m_StartButton.clicked += () => { m_FooterMessage.Hide(); Start(m_StartModeDropdown.value, m_SelectedConfiguration); }; m_FooterMessage = m_Root.Q <VisualElement>(kNamePrefix + "message"); m_FooterMessage.Hide(); rootVisualElement.Add(m_Root); }
public NullElement(PropertyElement root, IProperty property, PropertyPath path) { m_PotentialTypes = new List <Type> { typeof(Null) }; binding = this; m_Root = root; m_Path = path; name = m_Path.ToString(); TypeConstruction.GetAllConstructableTypes <T>(m_PotentialTypes); if (typeof(T).IsArray) { Resources.Templates.NullStringField.Clone(this); this.Q <Label>().text = GuiFactory.GetDisplayName(property); var button = this.Q <Button>(); button.text = $"Null ({GetTypeName(typeof(T))})"; button.clickable.clicked += ReloadWithArrayType; if (property.IsReadOnly) { button.SetEnabledSmart(false); } return; } if (m_PotentialTypes.Count == 2) { Resources.Templates.NullStringField.Clone(this); this.Q <Label>().text = GuiFactory.GetDisplayName(property); var button = this.Q <Button>(); button.text = $"Null ({GetTypeName(typeof(T))})"; button.clickable.clicked += ReloadWithFirstType; if (property.IsReadOnly) { button.SetEnabledSmart(false); } return; } var typeSelector = new PopupField <Type>( GuiFactory.GetDisplayName(property), m_PotentialTypes, typeof(Null), GetTypeName, GetTypeName); typeSelector.RegisterValueChangedCallback(OnCreateItem); if (property.IsReadOnly) { typeSelector.pickingMode = PickingMode.Ignore; typeSelector.Q(className: UssClasses.Unity.BasePopupFieldInput).SetEnabledSmart(false); } Add(typeSelector); }
protected virtual void PopulateCustomFields(string recordId) { if (CustomFields != null) { foreach (ScreenCustomField field in CustomFields) { // field.CustomFieldValues // don't access this directly - it will fetch the values for all records for this field. ScreenCustomFieldValue fieldValue = ScreenCustomFieldValue.FetchByFieldIdAndRecordId(field.Id, recordId); if (fieldValue != null) { //Control customField = FindControl(field.Name); Control root = this; // this.Parent.ID == "ControlContainer" ? this.Parent.Parent : this; BaseInputControl customField = this.GetControlTree <BaseInputControl>(root).Where(control => control.ID == field.Name).FirstOrDefault(); if (customField != null) { switch (field.CftypeId) { case "Text": case "MultiLine": customField.FieldValueRaw = fieldValue.Text; break; case "Checkbox": customField.FieldValueRaw = fieldValue.Number == 1; break; case "Date": customField.FieldValueRaw = fieldValue.Date; break; case "List": customField.FieldValueRaw = fieldValue.IdValue; break; case "Number": customField.FieldValueRaw = fieldValue.Number; break; case "PopupSearch": PopupField popup = (customField as PopupField); if (popup != null) { popup.FieldValueRaw = fieldValue.IdValue; popup.FieldText = fieldValue.Text; // Better to go and get the row from the database to ensure we get an up to date description on read - otherwise we are potentially showing stale data? // Abandoned this - there is no way of making it self-maintaining, i.e. no way of getting the object and description field returned by a particular search // using just the Url. //popup.FieldText = resolvePopupText(field, fieldValue); } break; } } } } } }
public override VisualElement CreateInspectorGUI() { var root = new VisualElement(); var button = (ScreenTransitionButton)target; var uiManager = button.GetComponentInParent <UIManager>(); var screens = uiManager.GetScreens(); var nextScreenProperty = serializedObject.FindProperty("nextScreen"); // Obtain the currently selected screen var selectedIndex = 0; var selectedScreen = nextScreenProperty.objectReferenceValue as Screen; if (selectedScreen) { if (screens.Contains(selectedScreen)) { selectedIndex = screens.IndexOf(selectedScreen); } } else { nextScreenProperty.objectReferenceValue = screens[0]; nextScreenProperty.serializedObject.ApplyModifiedProperties(); } string StringFormatCallback(Screen screen) => screen.Name == string.Empty ? "<unnamed>" : screen.Name; var popup = new PopupField <Screen>("Next screen", screens, selectedIndex) { // bindingPath = "nextScreen", formatListItemCallback = StringFormatCallback, formatSelectedValueCallback = StringFormatCallback }; popup.RegisterValueChangedCallback(evt => { nextScreenProperty.objectReferenceValue = evt.newValue; nextScreenProperty.serializedObject.ApplyModifiedProperties(); }); var backToggle = new Toggle("Back to previous") { bindingPath = "back" }; backToggle.RegisterValueChangedCallback(evt => { popup.SetEnabled(!evt.newValue); }); popup.SetEnabled(!serializedObject.FindProperty("back").boolValue); root.Add(backToggle); root.Add(popup); return(root); }
static COPPACompliance GetCompliancyForFieldValue(PopupField <string> coppaField) { if (coppaField.value == L10n.Tr(k_Yes)) { return(COPPACompliance.COPPACompliant); } if (coppaField.value == L10n.Tr(k_No)) { return(COPPACompliance.COPPANotCompliant); } return(COPPACompliance.COPPAUndefined); }
private void OnEnable() { _rootView = this.GetRootVisualContainer(); _rootView.Add(new Label("Midi Settings") { style = { fontSize = 18, marginTop = 10, marginBottom = 10, } }); // Container for Device Name label and field VisualContainer deviceNameContainer = new VisualContainer() { style = { flexDirection = FlexDirection.Row } }; _rootView.Add(deviceNameContainer); // Label for Field deviceNameContainer.Add(new Label("Device Name")); // Input Name Field _deviceNameField = new TextField() { isDelayed = true, value = EditorPrefs.GetString(DEVICE_NAME_STRING), style = { flexGrow = 1 }, }; _deviceNameField.OnValueChanged(evt => EditorPrefs.SetString(DEVICE_NAME_STRING, evt.newValue)); //deviceNameContainer.Add(_deviceNameField); // Get available device names VRCPortMidiInput midi = new VRCPortMidiInput(); var deviceNames = midi.GetDeviceNames().ToList(); // Add blank device name to use if specified device not found deviceNames.Insert(0, ""); string currentDeviceValue = EditorPrefs.GetString(DEVICE_NAME_STRING); string defaultValue = deviceNames.Contains(currentDeviceValue) ? currentDeviceValue : ""; // Create and add device popup var deviceNamePopupField = new PopupField <string>(deviceNames, defaultValue) { style = { flexGrow = 1 }, name = "midiDevicePopUp", }; deviceNamePopupField.OnValueChanged(evt => EditorPrefs.SetString(DEVICE_NAME_STRING, evt.newValue)); deviceNameContainer.Add(deviceNamePopupField); }
public VisualElement Build(InspectorContext <BuildTarget> context) { m_TargetPopup = new PopupField <BuildTarget>(GetAvailableTargets(), 0, GetDisplayName, GetDisplayName) { label = context.PrettyName }; m_TargetPopup.RegisterValueChangedCallback(evt => { context.Data = evt.newValue; }); return(m_TargetPopup); }
private void DrawFields(ScorerData scData, List <string> keys) { CurveField curveField = new CurveField("uFunction"); int index = keys.IndexOf(scData.key); PopupField <string> popupField = new PopupField <string>("key", keys, index); /*UnityExtensions.DebugLogEnumerable(popupField.GetClasses()); * UnityExtensions.DebugLogEnumerable(curveField.GetClasses());*/ curveField.BindProperty(serData.FindPropertyRelative("uFunction")); popupField.BindProperty(serData.FindPropertyRelative("key")); contentContainer.Add(curveField); contentContainer.Add(popupField); }
static PopupField <string> BuildPopupField(VisualElement block, string anchorName) { var anchor = block.Q(anchorName); var anchorParent = anchor.parent; var anchorIndex = anchorParent.IndexOf(anchor); var popupField = new PopupField <string> { name = anchor.name }; anchorParent.RemoveAt(anchorIndex); anchorParent.Insert(anchorIndex, popupField); return(popupField); }
async Task RefreshVenueSelector(GroupID groupIdToSelect = null, VenueID venueIdToSelect = null) { selector.Clear(); selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox("会場情報を取得しています...", MessageType.None))); VisualElement venuePicker = null; void RecreateVenuePicker(GroupID groupId) { if (venuePicker != null) { selector.Remove(venuePicker); } venuePicker = CreateVenuePicker(groupId, allVenues[groupId], venueIdToSelect); selector.Add(venuePicker); } try { var groups = await APIServiceClient.GetGroups.Call(Empty.Value, userInfo.VerifiedToken, 3); foreach (var group in groups.List) { allVenues[group.Id] = await APIServiceClient.GetGroupVenues.Call(group.Id, userInfo.VerifiedToken, 3); } selector.Clear(); if (groups.List.Count == 0) { selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox("clusterにてチーム登録をお願いいたします", MessageType.Warning))); } else { var teamMenu = new PopupField <Group>("所属チーム", groups.List, 0, group => group.Name, group => group.Name); teamMenu.RegisterValueChangedCallback(ev => RecreateVenuePicker(ev.newValue.Id)); selector.Add(teamMenu); var groupToSelect = groups.List.Find(group => group.Id == groupIdToSelect) ?? groups.List[0]; teamMenu.SetValueWithoutNotify(groupToSelect); RecreateVenuePicker(groupToSelect.Id); } } catch (Exception e) { Debug.LogException(e); selector.Clear(); selector.Add(new IMGUIContainer(() => EditorGUILayout.HelpBox($"会場情報の取得に失敗しました {e.Message}", MessageType.Error))); } }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var root = new VisualElement() { name = "", }; root.style.flexDirection = new StyleEnum <FlexDirection>(FlexDirection.Row); var textTemplateEngine = GetTargetTextTemplateEngine(property); Assert.IsNotNull(textTemplateEngine); var keywordList = new List <string> { "" }; keywordList.AddRange(textTemplateEngine.Keywords.Select(k => k.key)); var keywordPopup = new PopupField <string>(keywordList, 0) { name = "IgonrePairKeywordPopup", bindingPath = $"{property.propertyPath}.keyword", }; keywordPopup.style.flexGrow = new StyleFloat(0.5f); keywordPopup.RegisterValueChangedCallback(e => { var pairValuePopup = keywordPopup.parent.Children() .First(c => c.name == VALUE_POPUP_NAME) as PopupField <string>; string log = ""; foreach (var child in pairValuePopup.Children()) { log += $"{child.name}:type={child.GetType().Name} {child.childCount} {child.ElementAt(0).GetType().Name} "; } Debug.Log($"debug -- value count={pairValuePopup.childCount} log={log}"); //e.newValue; }); root.Add(keywordPopup); var valueList = new List <string> { "", "hoge", "foo", "bar" }; var valuePopup = new PopupField <string>(valueList, 0) { name = VALUE_POPUP_NAME, bindingPath = $"{property.propertyPath}.value", }; valuePopup.style.flexGrow = new StyleFloat(0.5f); root.Add(valuePopup); return(root); }
public PackageView(AvailablePackage package) { this.package = package; style.height = 32; style.flexDirection = FlexDirection.Row; style.marginBottom = style.marginTop = style.marginLeft = style.marginRight = 4; style.alignItems = Align.Center; style.borderRadius = 4; packageName = new Label(package.Name); packageName.style.fontSize = FontSizes.packageRow; packageName.style.flex = 1; packageName.style.textColor = Colors.packageRowText; versionSelector = new PopupField <string>(package.Versions.ToList(), package.Versions.Last()); versionSelector.style.width = 100; versionSelector.style.height = 24; versionSelector.style.paddingRight = 12; versionSelector.style.textAlignment = TextAnchor.MiddleCenter; versionSelector.style.fontSize = FontSizes.packageRow; versionSelector.OnValueChanged(HandleVersionSelectorValueChanged); infoButton = new Button(HandleInfoClicked); infoButton.style.width = 40; infoButton.text = "Info"; installButton = new Button(HandleInstallClicked); installButton.style.width = 60; installButton.text = "Install"; switchVersionButton = new Button(HandleSwitchVersionClicked); switchVersionButton.style.width = 60; switchVersionButton.text = "Install"; installedLabel = new Label("Installed"); installedLabel.style.width = 60; installedLabel.style.fontSize = FontSizes.packageRow; installedLabel.style.textColor = Colors.packageRowText; removeButton = new Button(HandleRemoveClicked); removeButton.style.width = 30; removeButton.text = "X"; style.backgroundColor = Colors.packageRowBackground; isPackageInstalled = BindToDerivedState(packages.InstalledPackages, installedPackages => installedPackages.Packages.Any(p => p.Name == package.Name)); Init(); }
VisualElement CreateAlbedoContent() { var root = new VisualElement() { name = "Albedo and Metals" }; var validateTrueMetals = new Toggle("Check Pure Metals"); validateTrueMetals.SetValueWithoutNotify(sceneView.validateTrueMetals); validateTrueMetals.RegisterValueChangedCallback(ValidateTrueMetalsChanged); validateTrueMetals.tooltip = "Check if albedo is black for materials with an average specular color above 0.45"; root.Add(validateTrueMetals); var albedoSpecificContent = new VisualElement() { name = "Albedo" }; if (PlayerSettings.colorSpace == ColorSpace.Gamma) { albedoSpecificContent.Add(new HelpBox("Albedo Validation doesn't work when Color Space is set to gamma space", HelpBoxMessageType.Warning)); } m_SelectedAlbedoSwatch = m_AlbedoSwatchInfos[0]; m_SelectedAlbedoPopup = new PopupField <AlbedoSwatchInfo>("Luminance Validation", m_AlbedoSwatchInfos, m_SelectedAlbedoSwatch); m_SelectedAlbedoPopup.tooltip = "Select default luminance validation or validate against a configured albedo swatch"; m_SelectedAlbedoPopup.formatListItemCallback = swatch => swatch.name; m_SelectedAlbedoPopup.formatSelectedValueCallback = swatch => swatch.name; m_SelectedAlbedoPopup.RegisterValueChangedCallback(SetSelectedAlbedoSwatch); albedoSpecificContent.Add(m_SelectedAlbedoPopup); albedoSpecificContent.Add(m_AlbedoContent = CreateColorSwatch("magenta", Color.magenta)); var hue = EditorGUIUtility.TrTextContent("Hue Tolerance:", "Check that the hue of the albedo value of a " + "material is within the tolerance of the hue of the albedo swatch being validated against"); var sat = EditorGUIUtility.TrTextContent("Saturation Tolerance:", "Check that the saturation of the albedo " + "value of a material is within the tolerance of the saturation of the albedo swatch being validated against"); m_AlbedoHueTolerance = CreateSliderWithField(hue, m_AlbedoSwatchHueTolerance, k_AlbedoHueToleranceMin, k_AlbedoHueToleranceMax, SetAlbedoHueTolerance); albedoSpecificContent.Add(m_AlbedoHueTolerance); m_AlbedoSaturationTolerance = CreateSliderWithField(sat, m_AlbedoSwatchSaturationTolerance, k_AlbedoHueToleranceMin, k_AlbedoHueToleranceMax, SetSaturationTolerance); albedoSpecificContent.Add(m_AlbedoSaturationTolerance); root.Add(albedoSpecificContent); root.Add(CreateColorLegend()); return(root); }
private VisualElement BuildSpeakerField(SerializedProperty property, Action <SpeakerInfoAsset> updateFaceField) { if (property.propertyType != SerializedPropertyType.ObjectReference) { throw new ArgumentException(); } var currentObject = property.objectReferenceValue; var assetGuids = AssetDatabase.FindAssets("t:SpeakerInfoAsset"); var assets = assetGuids.Select(guid => AssetDatabase.LoadAssetAtPath <SpeakerInfoAsset>(AssetDatabase.GUIDToAssetPath(guid))).ToList();//Resources.FindObjectsOfTypeAll<SpeakerInfoAsset>().ToList(); assets.Insert(0, null); int index = -1; if (currentObject is SpeakerInfoAsset currentSpeakerInfoAsset) { index = assets.IndexOf(currentSpeakerInfoAsset); } else if (currentObject == null) { index = 0; } if (index < 0) { return(new ObjectField("話者") { bindingPath = property.propertyPath }); } Func <SpeakerInfoAsset, string> formatter = asset => asset ? asset.SpeakerInfo.Name : "(None)"; var menu = new PopupField <SpeakerInfoAsset>(assets, index, formatter, formatter); menu.label = "話者"; menu.RegisterValueChangedCallback(evt => { property.objectReferenceValue = evt.newValue; property.serializedObject.ApplyModifiedProperties(); updateFaceField.Invoke(evt.newValue); }); return(menu); }
public void AddFields() { VisualElement parent = new VisualElement(); GUIContent content = new GUIContent("My field"); IntegerField intField = UIElementsEditorUtility.AddField <IntegerField, int>(parent, content, 100, null); Assert.IsNotNull(intField); PopupField <int> popupField = UIElementsEditorUtility.AddPopupField(parent, content, new List <int> { 0, 1, 2, 3, 4 }, 0, null); Assert.IsNotNull(popupField); }
private void RegisterCallbacks() { Button copyCodeButton = rootVisualElement.Q <Button>("Copy Code"); copyCodeButton.clicked += () => { EditorGUIUtility.systemCopyBuffer = string.Join(Environment.NewLine, (string[])s_decompiledCodeField.itemsSource); }; var generatedTypesListView = rootVisualElement.Q <ListView>("Scripts ListView"); SetupListView(generatedTypesListView, FilteredTypes, 15, MakeScriptLabel, BindScriptLabel); generatedTypesListView.selectionType = SelectionType.Single; #if UNITY_2020_1_OR_NEWER generatedTypesListView.onSelectionChange += OnScriptSelected; #else generatedTypesListView.onSelectionChanged += OnScriptSelected; #endif var searchField = rootVisualElement.Q <ToolbarSearchField>("Script Search Field"); searchField.RegisterCallback <ChangeEvent <string>, ListView>(OnFilter, generatedTypesListView); SetupListView(s_decompiledCodeField, s_currentlyDisplayedDecompiledCode, 15, MakeScriptLineLabel, BindScriptLineLabel); var language = rootVisualElement.Q <EnumField>("Language Popup"); language.Init(defaultValue: DisplayLanguage.CSharp); language.RegisterValueChangedCallback(changeEvent => { s_currentDisplayLanguage = (DisplayLanguage)changeEvent.newValue; StartDecompilationOrDisplayDecompiledCode(); }); var fontSizes = new PopupField <int>( choices: Enumerable.Range(start: 12, count: 7).ToList(), defaultIndex: 0, formatSelectedValueCallback: GetFontSizeHeader, formatListItemCallback: GetFontSize ); fontSizes.RegisterValueChangedCallback(changeEvent => { s_decompiledCodeField.style.fontSize = changeEvent.newValue; s_decompiledCodeField.itemHeight = Mathf.CeilToInt(changeEvent.newValue * 1.5f); }); VisualElement fontSizeRoot = rootVisualElement.Q("Fontsize Popup"); fontSizeRoot.Add(fontSizes); s_decompilationStatusLabel.binding = new DecompilationStatusLabelBinding(); }
private void UpdateChoices(SerializedProperty property, InputActionAsset inputActionAsset, VisualElement result) { result.Clear(); if (inputActionAsset == null) { var propertyField = new ObjectField(property.displayName); propertyField.SetEnabled(false); result.Add(propertyField); return; } var assetReferences = AssetDatabase .LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(inputActionAsset)) .OfType <InputActionReference>() .ToList(); // Ugly hack: GenericMenu interprets "/" as a submenu path. But luckily, "/" is not the only slash we have in Unicode. var choices = inputActionAsset.Select(a => a.actionMap.name + "\uFF0F" + a.name).ToList(); choices.Insert(0, "None"); var references = inputActionAsset.Select(a => assetReferences.Find(r => a == r.action)).ToList(); references.Insert(0, null); var field = new PopupField <string>(property.displayName, choices, 0); { var selectedAction = ((InputActionReference)property.objectReferenceValue)?.action; field.value = choices[Mathf.Max(0, references.FindIndex(a => (a == null ? null : a.action) == selectedAction))]; } field.RegisterCallback <ChangeEvent <string> >(ev => { property.objectReferenceValue = references[Mathf.Clamp(field.index, 0, references.Count - 1)]; property.serializedObject.ApplyModifiedProperties(); }); field.schedule.Execute(() => { //if (!property.isValid) return; if (!property.Next(false)) { return; } var selectedAction = ((InputActionReference)property.objectReferenceValue)?.action; field.value = choices[Mathf.Max(0, references.FindIndex(a => (a == null ? null : a.action) == selectedAction))]; }).Every(100); result.Add(field); }
private void UpdateSelectableComponents(Object dataContext) { if (componentPopup != null) { componentPopup.RemoveFromHierarchy(); componentPopup = null; } var targetGameObject = dataContext as GameObject; if (targetGameObject == null) { return; } var components = new List <Component>(); targetGameObject.GetComponents(components); var selectableObjects = components.Cast <Object>().ToList(); selectableObjects.Insert(0, dataContext); int defaultIndex = selectableObjects.IndexOf(pComponent.objectReferenceValue); if (defaultIndex < 0) { defaultIndex = 0; } //Make sure we're currently set to the default value if (selectableObjects.Count > 0) { pComponent.objectReferenceValue = selectableObjects[defaultIndex]; pComponent.serializedObject.ApplyModifiedProperties(); } componentPopup = new PopupField <Object>("Component", selectableObjects, defaultIndex, FormatComponentType, FormatComponentTypePopup); componentPopup.RegisterCallback <ChangeEvent <Object> >(evt => { pComponent.objectReferenceValue = evt.newValue is GameObject ? null : evt.newValue; pProperty.stringValue = string.Empty; UpdateSelectableProperties(); pComponent.serializedObject.ApplyModifiedProperties(); }); rootContainer.Insert(2, componentPopup); }