Skip to content

Instantly share code, notes, and snippets.

@keijiro
keijiro / FpsCapper.cs
Last active November 5, 2024 06:53
FpsCapper - Limits the frame rate of the Unity Editor in Edit Mode
using UnityEditor;
using UnityEngine;
using UnityEngine.LowLevel;
using System.Linq;
using System.Threading;
namespace EditorUtils {
//
// Serializable settings
@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
@bgolus
bgolus / MatCapTechniques.shader
Created January 29, 2022 00:37
Showing multiple matcap techniques, including a proposed improved method that's no more expensive than the usual fix if you're starting with the world position and world normal.
Shader "Unlit/MatCap Techniques"
{
Properties
{
[NoScaleOffset] _MatCap ("MatCap", 2D) = "white" {}
[KeywordEnum(ViewSpaceNormal, ViewDirectionCross, ViewDirectionAligned)] _MatCapType ("Matcap UV Type", Float) = 2
}
SubShader
{
Tags { "RenderType"="Opaque" }
@staggartcreations
staggartcreations / GlobalShaderParams.cs
Last active January 18, 2024 08:40
Component for passing values through Shader.SetGlobalXXX
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteInEditMode]
public class GlobalShaderParams : MonoBehaviour
{
@bgolus
bgolus / CameraFacingBoxRaycast.shader
Created July 6, 2020 00:07
A "single triangle" cube shader. Really a shader that orients a flat mesh towards the camera and uses a box ray intersection to draw a cube in the interior.
Shader "Unlit/CameraFacingBoxRaycast"
{
Properties
{
_Cube ("Texture", Cube) = "" {}
_MeshScale ("Mesh Scale", Float) = 1.0
[Toggle] _DisableCameraFacing ("Disable Camera Facing", Float) = 0.0
}
SubShader
{
@unitycoder
unitycoder / unity-workflow-issues.md
Last active May 9, 2024 15:52
Unity WorkFlow Issues And Bugs

RANDOM (TO BE SORTED..Latest issues at bottom, maybe more relevant)

  • Folded box colliders keep unfolding here and there
  • No alpha in generated Sprite (circle) when assigned to UI Image
  • Never know for sure what version works best with VR and post processing..
  • Sprite slicer doesnt work with small sprites (support said wont fix)
  • Shadergraph: how to move node with all its connected parent nodes?
  • Tried to update oculus package, failed due to dll in use, restarting didnt help, deleted whole oculus folder, alt tab and back, deleted folder appread back! (multiple tiles, until deleted library and some other folder also)
  • Cannot drag objects to another folder, if target folder already contains same filename, but there is no info to user that its the case
  • More than once a week, sign into unity dialog
  • Doing multiselect DeSelect in project window, it jumps to first item on every deselect
@FreyaHolmer
FreyaHolmer / FlyCamera.cs
Last active November 6, 2024 13:53
A camera controller for easily flying around a scene in Unity smoothly. WASD for lateral movement, Space & Ctrl for vertical movement, Shift to move faster. Add this script to an existing camera, or an empty game object, hit play, and you're ready to go~
using UnityEngine;
[RequireComponent( typeof(Camera) )]
public class FlyCamera : MonoBehaviour {
public float acceleration = 50; // how fast you accelerate
public float accSprintMultiplier = 4; // how much faster you go when "sprinting"
public float lookSensitivity = 1; // mouse look sensitivity
public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input
public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable
@yasirkula
yasirkula / SlicedFilledImage.cs
Last active October 27, 2024 11:21
Combining UI Image's Sliced+Filled features together in Unity
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_2017_4 || UNITY_2018_2_OR_NEWER
using UnityEngine.U2D;
#endif
using Sprites = UnityEngine.Sprites;
#if UNITY_EDITOR
@staggartcreations
staggartcreations / CinemachinePathShape.cs
Created January 5, 2020 08:51
Unity script for creating a circular, arched or spiraling cinemachine path
using UnityEngine;
using Cinemachine;
using Waypoint = Cinemachine.CinemachineSmoothPath.Waypoint;
public class CinemachinePathShape : MonoBehaviour
{
public CinemachineSmoothPath path;
[Space]
@staggartcreations
staggartcreations / CreatePlaneStack.cs
Created December 31, 2019 12:02
Unity script for creating a stacked plane mesh
using UnityEngine;
[ExecuteInEditMode]
public class CreatePlaneStack : MonoBehaviour
{
public MeshFilter meshFilter;
[Range(1, 64)]
public int layers = 4;
[Space]