private void PopulateTags(bool isOpen) { Foldout tagsFoldout = rootVisualElement.Q <Foldout>("TagsFoldout"); tagsFoldout.SetValueWithoutNotify(isOpen); tagsFoldout.Clear(); ListView listView = CreateListViewForTags(); tagsFoldout.Add(listView); List <ScriptableTag> tags = ScriptableSettingsManager.Instance.Tags; for (int i = 0; i < tags.Count; i++) { Toggle toggle = new Toggle(); toggle.text = " " + tags[i].name; int index = i; toggle.RegisterValueChangedCallback(x => OnToggleTag(tags[index], x)); ContextualMenuManipulator manipulator = new ContextualMenuManipulator(x => { x.menu.AppendAction("Delete", y => DeleteTag(tags[index])); }) { target = toggle }; listView.Add(toggle); } listView.style.height = Mathf.Min(tags.Count * 20, 100); Button tagsAdd = rootVisualElement.Q <Button>("TagsAdd"); tagsAdd.clicked -= GoToCreateNewTag; tagsAdd.clicked += GoToCreateNewTag; }
/// <summary> /// Initializes <see cref="Foldout"/> properties using values from the attribute bag. /// </summary> /// <param name="ve">The object to initialize.</param> /// <param name="bag">The attribute bag.</param> /// <param name="cc">The creation context; unused.</param> public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc) { base.Init(ve, bag, cc); Foldout f = ve as Foldout; if (f != null) { f.text = m_Text.GetValueFromBag(bag, cc); f.SetValueWithoutNotify(m_Value.GetValueFromBag(bag, cc)); } }
public KeyCodeNode() { Initialize("KeyCode", DefaultNodePosition); var foldout = new Foldout(); foldout.text = "KeyCode (click to select)"; var baseComponents = Enum.GetNames(typeof(KeyCode)).ToList(); var components = new List <string>(); components.AddRange(baseComponents); var listView = new ListView(components, 20, () => new Label(), (visualElement, index) => { var element = (Label)visualElement; element.text = components[index]; }); listView.onSelectionChanged += selection => { CodeGraph.Instance.InvalidateSaveButton(); var text = (string)selection[0]; KeyCode = text; foldout.text = $"KeyCode ({text})"; foldout.SetValueWithoutNotify(false); }; listView.style.height = 100; var searchBar = new TextField(); searchBar.RegisterValueChangedCallback(evt => { var value = evt.newValue.Trim(); if (!string.IsNullOrEmpty(value) && !string.IsNullOrWhiteSpace(value)) { components = baseComponents.Where(s => s.ToLower(CultureInfo.InvariantCulture).Contains(value.ToLower())).ToList(); listView.itemsSource = components; listView.Refresh(); } else { components = baseComponents.Where(s => true).ToList(); listView.itemsSource = components; listView.Refresh(); } }); foldout.Q("unity-checkmark").style.width = 0; foldout.contentContainer.Add(searchBar); foldout.contentContainer.Add(listView); foldout.RegisterValueChangedCallback(evt => { if (evt.newValue) { searchBar[0].Focus(); searchBar.value = ""; } }); foldout.SetValueWithoutNotify(false); inputContainer.Add(foldout); var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float)); valuePort.portName = "keyCode"; AddOutputPort(valuePort, () => $"KeyCode.{KeyCode}"); Refresh(); }
public GetComponentNode() { Initialize("Get Component", DefaultNodePosition); var foldout = new Foldout(); foldout.text = "Type (click to select)"; var baseComponents = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(Component)) select type.Name).ToList(); var components = new List <string>(); components.AddRange(baseComponents); var listView = new ListView(components, 20, () => new Label(), (visualElement, index) => { var element = (Label)visualElement; element.text = components[index]; }); listView.onSelectionChanged += selection => { var text = (string)selection[0]; ComponentType = text; foldout.text = $"Type ({text})"; foldout.SetValueWithoutNotify(false); }; listView.style.height = 100; var searchBar = new TextField(); searchBar.RegisterValueChangedCallback(evt => { var value = evt.newValue.Trim(); if (!string.IsNullOrEmpty(value) && !string.IsNullOrWhiteSpace(value)) { components = baseComponents.Where(s => s.ToLower(CultureInfo.InvariantCulture).Contains(value.ToLower())).ToList(); listView.itemsSource = components; listView.Refresh(); } else { components = baseComponents.ToList(); listView.itemsSource = components; listView.Refresh(); } }); foldout.Q("unity-checkmark").style.width = 0; foldout.contentContainer.Add(searchBar); foldout.contentContainer.Add(listView); foldout.RegisterValueChangedCallback(evt => { if (evt.newValue) { searchBar[0].Focus(); searchBar.value = ""; } }); foldout.SetValueWithoutNotify(false); inputContainer.Add(foldout); var inputPort = base.InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(float)); inputPort.portName = "gameobject"; AddInputPort(inputPort, () => { var connections = inputPort.connections.ToList(); if (connections.Count == 0) { return($"new GameObject() /* WARNING: You probably want connect this node to something. */"); } var output = connections[0].output; var node = output.node as AbstractNode; if (node == null) { return($"new GameObject() /* ERROR: Something went wrong and the connected node ended up as null. */"); } return(node.OutputPortDictionary[output].GetCode()); }); var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float)); valuePort.portName = "component"; AddOutputPort(valuePort, () => $"{InputPortDictionary[inputPort].RequestCode()}.GetComponent<{ComponentType}>()"); Refresh(); }