Skip to content

Instantly share code, notes, and snippets.

@cr4yz
Created December 14, 2020 16:59
Show Gist options
  • Save cr4yz/8d1fd6ee757cbd6351972aeb19c33984 to your computer and use it in GitHub Desktop.
Save cr4yz/8d1fd6ee757cbd6351972aeb19c33984 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
[RequireComponent(typeof(UIDocument))]
public class TestScript : MonoBehaviour
{
private VisualElement _parent;
private void Start()
{
var scroll = new ScrollView();
scroll.style.height = 200;
scroll.style.backgroundColor = Color.white;
for(int i = 0; i < 100; i++)
{
var el = new Label("Test Label");
scroll.Add(el);
}
_parent = new VisualElement();
_parent.Add(scroll);
GetComponent<UIDocument>().rootVisualElement.Add(_parent);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
_parent.visible = !_parent.visible;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment