static void CreateListItem(ReorderableList list, int index, VisualElement root) { root.style.flexDirection = FlexDirection.Row; var element = list.ListProperty.GetArrayElementAtIndex(index); var nameField = new TextField { multiline = false, style = { width = 150, alignItems = Align.FlexStart } }; nameField.RegisterValueChangedCallback(evt => { // Variable must not contain any spaces or the smart format parser will not be able to correctly parse them as selectors nameField.SetValueWithoutNotify(evt.newValue.ReplaceWhiteSpaces("-")); }); nameField.BindProperty(element.FindPropertyRelative("name")); root.Add(nameField); var group = new ObjectField { style = { flexGrow = 1 } }; group.objectType = typeof(GlobalVariablesGroup); group.BindProperty(element.FindPropertyRelative("group")); root.Add(group); }
void InitTileSet(VisualElement root) { tileNameField = root.Query <TextField>("tile-name-field").First(); onlyCrossToggle = root.Query <Toggle>("only-cross-toggle").First(); tilesListView = root.Query <ListView>("tiles-list-view").First(); addTilesButton = root.Query <Button>("add-tile-button").First(); removeTileButton = root.Query <Button>("remove-tile-button").First(); tileNameField.BindProperty(serializedObject.FindProperty("tileName")); onlyCrossToggle.BindProperty(serializedObject.FindProperty("onlyCross")); var serializedTileSetElements = serializedObject.FindProperty("tileSetElements"); tilesListView.makeItem += () => new PropertyField(); tilesListView.bindItem = (e, i) => { if (i >= serializedTileSetElements.arraySize) { return; } (e as PropertyField).BindProperty(serializedTileSetElements.GetArrayElementAtIndex(i)); }; tilesListView.BindProperty(serializedTileSetElements); addTilesButton.clickable.clicked += () => tileSet.AddEmpty(); removeTileButton.clickable.clicked += () => tileSet.RemoveAt(tilesListView.selectedIndex); }
public static SettingsProvider CreateBulletTeamSettingsProvider() { // First parameter is the path in the Settings window. // Second parameter is the scope of this setting: it only appears in the Settings window for the Project scope. var provider = new SettingsProvider("Project/BulletTeamSettings", SettingsScope.Project) { label = "Bullet Team Layers", // activateHandler is called when the user clicks on the Settings item in the Settings window. activateHandler = (searchContext, rootElement) => { var settings = BulletTeamSettings.GetSerializedSettings(); settings.Update(); // rootElement is a VisualElement. If you add any children to it, the OnGUI function // isn't called because the SettingsProvider uses the UIElements drawing framework. //rootElement.styleSheets.Add (AssetDatabase.LoadAssetAtPath<StyleSheet> ("Assets/Editor/settings_ui.uss")); var title = new Label() { text = "Bullet Team Layers" }; title.AddToClassList("title"); rootElement.Add(title); var properties = new ScrollView() { style = { flexDirection = FlexDirection.Column } }; properties.AddToClassList("property-list"); rootElement.Add(properties); SerializedProperty layerNamesProp = settings.FindProperty("layerNames"); for (int i = 0; i < layerNamesProp.arraySize; i++) { SerializedProperty property = layerNamesProp.GetArrayElementAtIndex(i); TextField prop = new TextField() { label = string.Format("Layer {0}", i), value = property.stringValue }; prop.BindProperty(property); prop.AddToClassList("property-value"); properties.Add(prop); } settings.ApplyModifiedProperties(); }, // Populate the search keywords to enable smart search filtering and label highlighting: keywords = new HashSet <string>(new [] { "Bullet Team Layers" }) }; return(provider); }
public override VisualElement CreatePropertyGUI(SerializedProperty property) { var root = new Foldout { value = property.isExpanded, text = property.displayName }; root.RegisterValueChangedCallback(evt => property.isExpanded = evt.newValue); var name = new TextField("Shared Group Name"); name.BindProperty(property.FindPropertyRelative("m_SharedGroupName")); root.Add(name); var group = new ObjectField("Shared Group") { allowSceneObjects = false, objectType = typeof(AddressableAssetGroup) }; var groupProperty = property.FindPropertyRelative("m_SharedGroup"); group.BindProperty(groupProperty); group.RegisterValueChangedCallback(evt => name.style.display = evt.newValue != null ? DisplayStyle.None : DisplayStyle.Flex); name.style.display = groupProperty.objectReferenceValue != null ? DisplayStyle.None : DisplayStyle.Flex; root.Add(group); var localeName = new TextField("Locale Group Name"); localeName.BindProperty(property.FindPropertyRelative("m_LocaleGroupNamePattern")); root.Add(localeName); var localeGroupsProperty = property.FindPropertyRelative("m_LocaleGroups"); var list = new ReorderableList(localeGroupsProperty) { CreateItemCallback = CreateItem, AddCallback = ShowAddItemMenu, RemoveCallback = RemoveItem, ReorderCallback = MoveItem }; root.Add(list); var readOnly = new Toggle("Read Only"); readOnly.BindProperty(property.FindPropertyRelative("m_MarkEntriesReadOnly")); root.Add(readOnly); return(root); }
public static TextField CreateEditableLabel(TextElement container, SerializedProperty property, bool multiline = false) { var edit = new TextField { multiline = multiline }; edit.BindProperty(property); edit.AddToClassList(NodeEditableLabelUssClassName); edit.Q(TextField.textInputUssName).RegisterCallback <FocusOutEvent>(evt => HideEditableText(edit)); container.BindProperty(property); container.RegisterCallback <MouseDownEvent>(evt => OnEditEvent(evt, edit)); container.RegisterValueChangedCallback(e => container.text = e.newValue); container.Add(edit); HideEditableText(edit); return(edit); }
static void CreateManagedItem(ReorderableList list, int index, VisualElement root) { const float leftMargin = 14; // Space for foldout arrow root.style.flexDirection = FlexDirection.Row; var element = list.ListProperty.GetArrayElementAtIndex(index); var nameField = new TextField { multiline = false, style = { width = 150, alignItems = Align.FlexStart } }; nameField.RegisterValueChangedCallback(evt => { // Variable must not contain any spaces or the smart format parser will not be able to correctly parse them as selectors nameField.SetValueWithoutNotify(evt.newValue.ReplaceWhiteSpaces("-")); }); nameField.BindProperty(element.FindPropertyRelative("name")); root.Add(nameField); var variable = element.FindPropertyRelative("variable"); var label = ManagedReferenceUtility.GetDisplayName(variable.managedReferenceFullTypename); if (!variable.hasVisibleChildren) { root.Add(new Label(label.text) { style = { paddingLeft = leftMargin } }); } else { var propEditor = new PropertyField(variable, label.text) { style = { flexGrow = 1 } }; propEditor.BindProperty(list.ListProperty.serializedObject); propEditor.style.paddingLeft = leftMargin; root.Add(propEditor); } }
/// <summary> /// UI Toolkit version /// </summary> /// <param name="property"></param> /// <returns></returns> public override VisualElement CreatePropertyGUI(SerializedProperty property) { var code = property.FindPropertyRelative("m_Code"); var foldout = new Foldout { text = "Identifier" }; foldout.BindProperty(property); var localeField = new ObjectField { objectType = typeof(Locale), value = LocalizationEditorSettings.GetLocale(code.stringValue) }; localeField.AddToClassList("unity-base-field__input"); localeField.RegisterCallback <MouseDownEvent>(evt => evt.StopPropagation()); localeField.RegisterCallback <MouseUpEvent>(evt => evt.StopPropagation()); localeField.RegisterValueChangedCallback(evt => { var locale = evt.newValue as Locale; code.stringValue = locale != null ? locale.Identifier.Code : string.Empty; code.serializedObject.ApplyModifiedProperties(); }); foldout.hierarchy[0].Add(localeField); foldout.hierarchy[0].hierarchy[0].RemoveFromClassList("unity-base-field__input"); foldout.hierarchy[0].hierarchy[0].AddToClassList("unity-base-field__label"); var codeField = new TextField { label = "Code" }; codeField.RegisterValueChangedCallback(evt => { localeField.SetValueWithoutNotify(LocalizationEditorSettings.GetLocale(evt.newValue)); }); codeField.BindProperty(code); foldout.Add(codeField); return(foldout); }