Skip to content

Instantly share code, notes, and snippets.

@ErnSur
Created July 8, 2019 20:19
Show Gist options
  • Save ErnSur/ad4f5c70478b3309c33d84ea14ab58a3 to your computer and use it in GitHub Desktop.
Save ErnSur/ad4f5c70478b3309c33d84ea14ab58a3 to your computer and use it in GitHub Desktop.
Unity UI-Elements Scope implementation
namespace UnityEngine.UIElements
{
public class Scope : IDisposable
{
public static VisualElement CurrentRoot { get; private set; }
public readonly VisualElement root;
private VisualElement _previousRoot;
public Scope(VisualElement root)
{
if (CurrentRoot != null)
{
_previousRoot = CurrentRoot;
_previousRoot.Add(root);
}
CurrentRoot = this.root = root;
}
public Scope(VisualElement root, string name) : this(root)
{
root.name = name;
}
void IDisposable.Dispose()
{
CurrentRoot = _previousRoot;
}
public void Add(VisualElement child)
{
root.Add(child);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment