Skip to content

Instantly share code, notes, and snippets.

View shanecelis's full-sized avatar

Shane Celis shanecelis

View GitHub Profile
@shanecelis
shanecelis / CoroutineTests.cs
Last active July 15, 2022 15:03
I was curious about how one could manually drive Unity's coroutines without necessarily putting them into Unity's scheduler.
/*
CoroutineTests.cs -- Shane Celis
I was curious about how one could manually drive Unity's coroutines
without necessarily putting them into Unity's scheduler. At the
heart of it, it's really easy to manually drive them:
// Get the coroutine.
IEnumerator ienum = MyCoroutine();
// Run it until it yields.
@shanecelis
shanecelis / MyEnumerable.cs
Created May 10, 2022 02:40
Demonstration of how to make an allocation-less struct IEnumerator.
/** 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 / SurfaceMeshProcessor.cs
Created April 3, 2022 06:49
Not intended for real distribution. Just enabling a twitter discussion.
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 March 26, 2022 12:41
Copy your dotnet libraries to your Unity game project
<?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 / coupling.md
Last active December 26, 2021 03:08
In Defense of Coupling (a programming talk sketch)

In Defense of Coupling

One of the truisms in software development is that decoupling is good.

Often the most useful patterns I’ve come across are ones that add a new decoupling tool into my toolbox. But coupling exists on a spectrum and tight coupling is not necessarily bad. Tight coupling is often benign and proper as you will see.

So I want to share the many ways that two statements of code may be variously coupled starting from the simplest, tightest coupling to a looser and looser coupling. And some Unity Engine specific decoupling will also be shown, but those can be ignored if you're not familiar with Unity.

Here are the many couplings of statements A and B.

@shanecelis
shanecelis / RawButton.cs
Created November 21, 2021 03:41
A style-less Button for Unity's UIToolkit.
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 November 10, 2021 06:31
A visual element that is draggable.
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 / TriangleElement.cs
Last active October 30, 2021 06:02
Render a triangle element in addition to the regular rectangular visual element.
/* Original code[1] Copyright (c) 2021 Shane Celis[1]
Licensed under the MIT License[1]
This comment generated by code-cite[1].
[1]: https://gist.github.com/shanecelis/7407d0809c114be5d20f089dfe3aa47a
[1]: https://twitter.com/shanecelis
[1]: https://opensource.org/licenses/MIT
[1]: https://github.com/shanecelis/code-cite
*/
@shanecelis
shanecelis / VisualElementExtensions.cs
Last active October 25, 2021 08:07
Some extensions to Unity's VisualElement class.
/* 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
*/
@shanecelis
shanecelis / DebugOnce.cs
Last active October 21, 2021 08:59
DebugOnce.Log() logs only once from each source code location.
/* 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/549ee612b67b13620cd0f9c95e34c853
[2]: https://twitter.com/shanecelis
[3]: https://opensource.org/licenses/MIT
[4]: https://github.com/shanecelis/code-cite
*/