Skip to content

Instantly share code, notes, and snippets.

@elringus
elringus / FileWatcher.cs
Last active April 20, 2024 23:56
Allows executing an editor behaviour in response to file modificatons, even when editor application is not in focus.
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
/// <summary>
/// Uses file system watcher to track changes to specific files in the project directory.
@elringus
elringus / SetTextureProperty.cs
Created January 15, 2022 08:40
Assign main texture property via the BlendModeEffect
using BlendModes;
using UnityEngine;
[RequireComponent(typeof(BlendModeEffect))]
public class SetTextureProperty : MonoBehaviour
{
public Texture2D Texture;
[ContextMenu("Set Texture")]
public void SetTexture ()
@elringus
elringus / BlendModes.c
Last active March 11, 2024 11:32
Popular blend mode algorithms implemented in Nvidia's Cg. https://elringus.me/blend-modes-in-unity/
fixed3 Darken (fixed3 a, fixed3 b)
{
return min(a, b);
}
fixed3 Multiply (fixed3 a, fixed3 b)
{
return a * b;
}
@elringus
elringus / RenderMyCustomPass.cs
Last active April 26, 2023 11:12
Example for adding custom render passes via renderer features for lightweight render pipeline (LWRP)
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.LWRP;
// Inheriting from `ScriptableRendererFeature` will add it to the
// `Renderer Features` list of the custom LWRP renderer data asset.
public class RenderMyCustomPass : ScriptableRendererFeature
{
private class MyCustomPass : ScriptableRenderPass
{
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
namespace Naninovel
Shader "UI/Outline"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
[Toggle]_IsOutlineEnabled("Enable Outline", int) = 0
[HDR]_OutlineColor("Outline Color", Color) = (1,1,1,1)
@elringus
elringus / Item.cs
Last active November 21, 2020 13:28
[System.Serializable]
public class Item
{
private string value = null;
public void SetValue (string value) => this.value = value;
public string GetValue () => value;
}
Shader "Custom/UnlitAlphaRotation"
{
Properties
{
_MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
_RotationY("Rotation over Y-axis", Range(0, 360)) = 45
}
SubShader
@elringus
elringus / ReadOnlyAttribute.cs
Created June 29, 2017 14:06
ReadOnly property drawer for Unity: add a [ReadOnly] attribute to a serialized field to make it show up as read only in the inspector
// Put this outside of an 'Editor' folder.
using UnityEngine;
public class ReadOnlyAttribute : PropertyAttribute { }
@elringus
elringus / rfc5646-language-tags.js
Created December 14, 2018 17:14 — forked from msikma/rfc5646-language-tags.js
RFC 5646 Language Tags
// List of language tags according to RFC 5646.
// See <http://tools.ietf.org/html/rfc5646> for info on how to parse
// these language tags. Some duplicates have been removed.
var RFC5646_LANGUAGE_TAGS = {
'af': 'Afrikaans',
'af-ZA': 'Afrikaans (South Africa)',
'ar': 'Arabic',
'ar-AE': 'Arabic (U.A.E.)',
'ar-BH': 'Arabic (Bahrain)',
'ar-DZ': 'Arabic (Algeria)',