Skip to content

Instantly share code, notes, and snippets.

Avatar

Shane Celis shanecelis

View GitHub Profile
@shanecelis
shanecelis / DragManipulator.cs
Last active Nov 21, 2022
This manipulator makes a visual element draggable at runtime in Unity's UIToolkit.
View DragManipulator.cs
/* Original code[1] Copyright (c) 2022 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/b6fb3fe8ed5356be1a3aeeb9e7d2c145
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
*/
using UnityEngine;
using UnityEngine.UIElements;
@shanecelis
shanecelis / ChildAnnotator.cs
Last active Oct 22, 2022
Fake CSS pseudo classes :first-child and :last-child in Unity's UIToolkit with regular USS classes .first-child and .last-child.
View ChildAnnotator.cs
/* Original code[1] Copyright (c) 2022 Shane Celis[1]
Licensed under the MIT License[1]
[1]: https://gist.github.com/shanecelis/1ab175c46313da401138ccacceeb0c90
[1]: https://twitter.com/shanecelis
[1]: https://opensource.org/licenses/MIT
*/
using UnityEngine.Scripting;
using UnityEngine.UIElements;
@shanecelis
shanecelis / ProgressBar.cs
Last active Aug 31, 2022
Exposes runtime progress bar for UIToolkit for Unity 2020.3.
View ProgressBar.cs
/** Using UIElements and want to use UIToolkit's progress bar at runtime? Hope,
you're using Unity 2021.1 or later. If you aren't, you can expose the
progress bar in Unity 2020.3 and perhaps even earlier versions (not tested).
`com.unity.ui v1.0.0-preview.18` uses the following #ifdef for the
`ProgressBar` class[1]:
```
#if !UIE_PACKAGE || UNITY_2021_1_OR_NEWER
```
@shanecelis
shanecelis / MyEnumerable.cs
Created May 10, 2022
Demonstration of how to make an allocation-less struct IEnumerator.
View MyEnumerable.cs
/** Suppose you want to do a `foreach` on your collection without any
allocations. You know it's possible.
You've heard you need to use a struct IEnumerator, but how?
*/
using System.Collections;
using System.Collections.Generic;
/** You implement IEnumerable<T> in your collection class. */
public class MyEnumerable<T> : IEnumerable<T> {
@shanecelis
shanecelis / NativeArrayOfArrays.cs
Last active Apr 11, 2022
Make one long linear NativeArray look like a two-dimensional jagged array.
View NativeArrayOfArrays.cs
/* Original code[1] Copyright (c) 2022 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/f0e295b12ec1ab09f67ad5980ac9b324
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
*/
using System;
using System.Collections.Generic;
@shanecelis
shanecelis / SurfaceMeshProcessor.cs
Created Apr 3, 2022
Not intended for real distribution. Just enabling a twitter discussion.
View SurfaceMeshProcessor.cs
using System;
using System.Collections.Generic;
using Nito.Disposables;
using Unity.Burst;
using Unity.Collections;
using Unity.Jobs;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering;
using static Unity.Mathematics.math;
@shanecelis
shanecelis / CopyToUnity.csproj_
Last active Mar 26, 2022
Copy your dotnet libraries to your Unity game project
View CopyToUnity.csproj_
<?xml version="1.0" encoding="utf-8"?>
<!-- Original code[1] Copyright (c) 2022 Shane Celis[2]
Licensed under the MIT License[3]
[1]: https://gist.github.com/shanecelis/db73854d7257fdd2a8798d3ba7d4d00f
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
* * *
@shanecelis
shanecelis / RawButton.cs
Created Nov 21, 2021
A style-less Button for Unity's UIToolkit.
View RawButton.cs
using System;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
/** Rather than trying to undo the .unity-button class, we just remove it from
the element to begin with. */
public class RawButton : Button {
public RawButton() : this(null) { }
public RawButton(Action onClick) : base(onClick) {
@shanecelis
shanecelis / Draggable.cs
Last active Nov 10, 2021
A visual element that is draggable.
View Draggable.cs
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
/** A visual element that is draggable. Good example of using the
VisualElement's `tranform.position`.
Credit to Crayz for their code:
https://forum.unity.com/threads/creating-draggable-visualelement-and-clamping-it-to-screen.1017715/
@shanecelis
shanecelis / VisualElementExtensions.cs
Last active Oct 25, 2021
Some extensions to Unity's VisualElement class.
View VisualElementExtensions.cs
/* Original code[1] Copyright (c) 2021 Shane Celis[2]
Licensed under the MIT License[3]
This comment generated by code-cite[4].
[1]: https://gist.github.com/shanecelis/343e3159b6dab44b18b53f47a05fd7c7/edit
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
[4]: https://github.com/shanecelis/code-cite
*/