Skip to content

Instantly share code, notes, and snippets.

View TJHeuvel's full-sized avatar

Tijmen van den Heuvel TJHeuvel

View GitHub Profile
@TJHeuvel
TJHeuvel / DrawInstancedCustomCB.cs
Created April 4, 2023 12:16
DrawInstancedCustomCB
class DrawInstancedCustomCB : MonoBehaviour
{
[SerializeField] private Mesh mesh;
[SerializeField] private Material mat;
private MaterialPropertyBlock propBlock;
private GraphicsBuffer objectToWorlds;
void Start()
@TJHeuvel
TJHeuvel / NewInput.cs
Created January 4, 2021 19:53
Wrapper for unity's new Input System to the old one
using UnityEngine;
using UnityEngine.InputSystem;
/// <summary>
/// Input system wrapper for the new input system. Poorly wraps old system to the new, so you can at least see something
/// </summary>
public static class Input
{
public static bool GetKeyDown(KeyCode key) => Keyboard.current[keyCodeToKey(key)].wasPressedThisFrame;
public static bool GetKey(KeyCode key) => Keyboard.current[keyCodeToKey(key)].isPressed;
@TJHeuvel
TJHeuvel / test.cs
Created October 6, 2020 19:11
Hexes
using System;
using UnityEditor;
using UnityEngine;
using UnityEngine.InputSystem;
using System.Linq;
class Test : MonoBehaviour
{
[SerializeField, Range(0, 1)] private float[] chances = new float[6];
@TJHeuvel
TJHeuvel / ModelImporterEditor.cs
Created September 22, 2020 11:19
ModelImporter
using System.Reflection;
using UnityEditor;
using UnityEditor.AssetImporters;
using UnityEngine;
[CustomEditor(typeof(ModelImporter))]
[CanEditMultipleObjects]
//https://github.com/Unity-Technologies/UnityCsReference/blob/9034442437e6b5efe28c51d02e978a96a3ce5439/Modules/AssetPipelineEditor/ImportSettings/ModelImporterEditor.cs
using System.Reflection;
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
[CustomEditor(typeof(TextureImporter))]
[CanEditMultipleObjects]
//https://github.com/Unity-Technologies/UnityCsReference/blob/9034442437e6b5efe28c51d02e978a96a3ce5439/Editor/Mono/ImportSettings/TextureImporterInspector.cs
internal class TextureImporterEditor : AssetImporterEditor
{
@TJHeuvel
TJHeuvel / CustomPrefabImporterEditor.cs
Last active November 9, 2019 18:30
Custom inspector window for Unity prefabs that allows you to (multi) edit them.
using UnityEditor;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
using System.Reflection;
using System;
using System.Collections;
using System.Linq;
using Object = UnityEngine.Object;
using System.Collections.Generic;
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
Shader "Sprites/Default"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
_AnimationSpeed ("AnimationSpeed", Vector) = (1,1,0,0) //EDIT: Add speed here
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
@TJHeuvel
TJHeuvel / MeshVisualizeWindow.cs
Last active June 17, 2021 09:03
Visualizes the mesh vertices and triangles
using UnityEngine;
using UnityEditor;
using System.Collections;
using System;
public class MeshVisualizeWindow : EditorWindow
{
[MenuItem("Window/Mesh visualizer")]
public static void OpenWindow()
{