Skip to content

Instantly share code, notes, and snippets.

View Anthelmed's full-sized avatar

Anthelme Dumont Anthelmed

View GitHub Profile
@Anthelmed
Anthelmed / UIAnimationsUtils.cs
Last active April 28, 2023 13:22
A simple utils for fading in and out VisualElements. Code is under the MIT license: https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt
using System;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;
public static class UIAnimationsUtils
{
public static ValueAnimation<float> FadeIn(VisualElement visualElement, int durationMS, Func<float, float> easing, Action callback = null, bool disabledWhenInvisible = true)
{
var fromOpacity = visualElement.style.opacity.value;
@Anthelmed
Anthelmed / UIToolkitAutoReferencesPostprocessor.cs
Last active May 12, 2023 19:20
Automatically generate for you a MonoBehavior script containing reference to all the VisualElements that have the "auto-reference" uss class, this is updating every time you add or remove an "auto-reference" uss class inside your UXML file. Code is under the MIT license: https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt
#if UNITY_EDITOR
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine.UIElements;
namespace Postprocessors
@Anthelmed
Anthelmed / WorldSpaceUIDocument.cs
Last active November 7, 2024 07:31
Until Unity decide to make it official, this is a custom WorldSpaceUIDocument component. Code is under the MIT license: https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Rendering;
using UnityEngine.UIElements;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem.UI;
#endif
#if UNITY_EDITOR
using UnityEditor;
@Anthelmed
Anthelmed / Router.cs
Created April 26, 2022 22:09
Router example
using System;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace Router
{
public static class SceneRouter
{
public enum SceneType
@Anthelmed
Anthelmed / Searchbar
Created March 10, 2022 21:40
Searchbar code example for the medium article on UIToolkit
@Anthelmed
Anthelmed / FileUtils.cs
Last active February 8, 2022 21:35
Unity Read/Write SaveAsync/LoadAsync streamingAssets file utils
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Newtonsoft.Json; // https://docs.unity3d.com/Packages/[email protected]/manual/index.html
using UnityEngine;
public static class FileUtils
{
public static string RootDirectory
{
@Anthelmed
Anthelmed / MainMenu.cs
Created January 28, 2022 09:52
MainMenu
using System;
using System.Collections.Generic;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.UIElements;
public class MainMenu : MonoBehaviour
{
[SerializeField] private UIDocument mainMenuUIDocument;
[SerializeField] private Material buttonHoverMaterial;
@Anthelmed
Anthelmed / Menu Button Custom Render Texture.shader
Last active January 28, 2022 09:52
Menu Button Custom Render Texture
Shader "CustomRenderTexture/Menu Button Custom Render Texture"
{
Properties
{
_NoiseScale("Noise Scale", float) = 1
_NoiseStrength("Noise Strength", float) = 0.1
_NoiseSpeed("Noise Speed", float) = 0.1
_NoiseOffset("Noise Offset", float) = 0
}
@Anthelmed
Anthelmed / Animation
Created December 10, 2021 18:44
Using Unity UIToolkit transition animation system to animate a GameObject
using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.UIElements.Experimental;
public class Animation : MonoBehaviour
{
[SerializeField] private Transform transform;
[SerializeField] private UIDocument uiDocument;
[SerializeField] private int durationMs = 3000;
@Anthelmed
Anthelmed / RaymarchSDF.hlsl
Last active October 18, 2023 21:26
A Texture3D SDF function to be used inside Unity shader graph
#ifndef RAYMARCHSDFINCLUDE_INCLUDED
#define RAYMARCHSDFINCLUDE_INCLUDED
#define STEPS 256
#define MAX_DISTANCE 500
#define MIN_DISTANCE 0.001
#if !SHADERGRAPH_PREVIEW
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"