Skip to content

Instantly share code, notes, and snippets.

View AnsisMalins's full-sized avatar

Ansis Māliņš AnsisMalins

View GitHub Profile
@AnsisMalins
AnsisMalins / GUI2.cs
Last active October 23, 2022 23:17
Virtualizing list view for Unity IMGUI
using System;
using System.Reflection;
using UnityEngine;
public static class GUI2
{
#if UNITY_EDITOR
private static readonly MethodInfo _internalRepaintEditorWindow = typeof(GUI).GetMethod(
"InternalRepaintEditorWindow", BindingFlags.Static | BindingFlags.NonPublic);
#endif
@AnsisMalins
AnsisMalins / Matrix4x4Drawer.cs
Created September 27, 2020 20:47
A custom property drawer for matrices
using System;
using UnityEditor;
using UnityEngine;
[CustomPropertyDrawer(typeof(Matrix4x4))]
public sealed class Matrix4x4Drawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return (EditorGUIUtility.singleLineHeight + 2) * 4 - 2;
@AnsisMalins
AnsisMalins / UnsafeStringBuilder.cs
Last active August 12, 2020 21:22
Non-growing, zero allocation string builder
using System.IO;
using UnityEngine;
public sealed class UnsafeStringBuilder
{
public int Capacity => _buffer.Length;
public int Length { get; private set; }
private string _buffer;
@AnsisMalins
AnsisMalins / PathGUI.cs
Created August 6, 2020 09:49
Unity editor inspector fields to browse for paths
using System;
using System.IO;
using UnityEditor;
using UnityEngine;
public static class PathGUI
{
public static void OpenFileField(string label, ref string path)
{
string directory = path;
@AnsisMalins
AnsisMalins / index.html
Last active June 4, 2021 07:04
Unity WebGL template that fills the viewport
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>%UNITY_WEB_NAME%</title>
<style>
body {
margin: 0;
}
@AnsisMalins
AnsisMalins / DialogueGraphEditor.cs
Created January 5, 2020 15:49
How to do a custom node graph editor in Unity 2018.4 or 2019.2
// The commented out parts are for Unity 2018.4
//using System.Reflection;
//using UnityEditor.Experimental.UIElements.GraphView;
//using UnityEngine.Experimental.UIElements;
//using UnityEngine.Experimental.UIElements.StyleEnums;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
@AnsisMalins
AnsisMalins / DependencyTracker.cs
Last active October 3, 2019 15:48
Adds a context menu item in Unity to find where an asset is used
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using Object = UnityEngine.Object;
public static class DependencyTracker
{
private static Dictionary<string, List<string>> dependantCache;
using UnityEditor;
using UnityEngine;
public sealed class AssetBundleLoader : ScriptableWizard
{
public string sourcePath;
[MenuItem("Wizard/Load Asset Bundle")]
private static void CreateWizard()
{
@AnsisMalins
AnsisMalins / ArrayPool.cs
Last active May 19, 2019 11:12
Array Pool
public static class ArrayPool<T>
{
private static readonly List<T[]> pool = new List<T[]>();
public static Item Get(int length)
{
for (int i = pool.Count - 1; i >= 0; i--)
{
var array = pool[i];
if (array.Length >= length)
@AnsisMalins
AnsisMalins / QueryWindow.cs
Last active November 1, 2019 21:44
LINQ Query Window for Unity
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using UnityEditor;