Skip to content

Instantly share code, notes, and snippets.

View timsoret's full-sized avatar
🎯
Focusing

Tim Soret timsoret

🎯
Focusing
View GitHub Profile
// c# companion script
// SpriteUVToShader.cs -------------------------------------------------------------------------------------------------------------------------------- //
// Save you your project, add to your SpriteRenderer gameObject
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[ExecuteInEditMode]
@ulrikdamm
ulrikdamm / EditPrefab.cs
Last active May 10, 2023 07:44
Unity editor script for better editing of prefabs. Put in Assets/Editor.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
// Adds a "Edit Prefab" option in the Assets menu (or right clicking an asset in the project browser).
// This opens an empty scene with your prefab where you can edit it.
// Put this script in your project as Assets/Editor/EditPrefab.cs
public class EditPrefab {
static Object getPrefab(Object selection) {
@LotteMakesStuff
LotteMakesStuff / TrafficLightAttribute.cs
Last active February 2, 2024 15:58
TrafficLight control/layout/property drawer: Adds a new editor control that draws lil Traffic Lights in the inspector. its really useful for visualizing state. For example, checkboxes can be hard to read at a glace, but a Red or Green status light is easy! Recommend you use the attached package, as it has all the icon image files.
// Non Editor code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class TrafficLightAttribute : PropertyAttribute
{
public bool DrawLabel = true;
public string CustomLabel;
public bool AlsoDrawDefault;
@MrJul
MrJul / TextureAlphaPremultiplier.cs
Last active May 18, 2023 03:07
Pre-multiply alpha channel when importing Unity textures
using System;
using JetBrains.Annotations;
using UnityEditor;
using UnityEngine;
namespace UnityProject.Editor {
public sealed class TextureAlphaPremultiplier : AssetPostprocessor {
public void OnPreprocessTexture() {
@LotteMakesStuff
LotteMakesStuff / InspectorButtonsTest.cs
Last active November 2, 2023 21:03
Code running pack! two property drawing scripts that make it super easy to trigger code via buttons in the inspector, and get feedback! [TestButton] draws you little buttons that call a method on your MonoBehaviour, and [ProgressBar] give you a great way to show feedback from long running methods. These are *super* helpful for things like proced…
using UnityEngine;
using System.Collections;
public class InspectorButtonsTest : MonoBehaviour
{
[TestButton("Generate world", "DoProcGen", isActiveInEditor = false)]
[TestButton("Clear world", "ClearWorld", 2, isActiveInEditor = false)]
[ProgressBar(hideWhenZero = true, label = "procGenFeedback")]
public float procgenProgress = -1;
@SixWays
SixWays / CursorManager.cs
Last active January 20, 2022 08:39
Nicer cursor hiding/locking for Unity, including automatic alt-tab handling. Tested on 5.4+, probably fine 5.0+.
using UnityEngine;
using System.Collections;
public class CursorManager : MonoBehaviour {
#region Static
#region Singleton
/* Class is a MonoBehaviour to recieve OnApplicationFocus(bool) message
* If no instance already present, one will be created BEFORE scene load
* CursorManager placed in scene will override auto-created instance
* Any created instance will call DontDestroyOnLoad on itself, but still gets overridden by scene
/*
Basic Sprite Shader for aligning pixel art to the same grid, based on the Unity Sprite Shader.
Create one Material where you assign the same Pixels Per Unit value you use on your imported Sprites,
then reuse this Material on all appropriate Sprite Renderers.
(You can use Shader.SetGlobalFloat to set that Pixels Per Unit value for all your shaders:
https://docs.unity3d.com/ScriptReference/Shader.SetGlobalFloat.html)
This is not for scaled or rotated artwork. If you need those features, look at low res render textures.
Use this however you want.
@jackmott
jackmott / FasterGame.cs
Last active August 21, 2020 18:17
Faster CSharp Game
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;
namespace bettercraft
{
using UnityEngine;
using UnityEditor;
using System;
using System.Collections;
using System.Collections.Generic;
public class ColorToCSharp : EditorWindow
{
[SerializeField]
private bool _usedColorPickerOnce = false;