Skip to content

Instantly share code, notes, and snippets.

View mandarinx's full-sized avatar

Thomas Viktil mandarinx

View GitHub Profile
@mandarinx
mandarinx / RasterizeGradient.cs
Created November 28, 2016 07:26
Rasterize a gradient
using UnityEditor;
using UnityEngine;
public class RasterizeGradient : EditorWindow {
private AnimationCurve curve;
private int imageWidth;
[MenuItem("Window/Rasterize Gradient")]
public static void OpenTPImporter() {
@mandarinx
mandarinx / Rnd.cs
Created November 21, 2016 20:22
Random distribution in Unity
using UnityEngine;
public class Rnd : MonoBehaviour {
private float[] results;
private float max;
void Awake() {
max = 0f;
results = new float[1000];
@mandarinx
mandarinx / FnPerfTest.cs
Last active October 21, 2022 23:21
C# function call performance cost
using System;
using System.Diagnostics;
using UnityEngine;
public interface InterfaceFunc {
void InterfaceFn();
}
static public class MonoExtension {
@mandarinx
mandarinx / dod.md
Created October 26, 2016 06:47
Data Oriented Design

Data Oriented Design in game development

DOD is about

  • Understanding your data.

Mike Acton from Insomniac Games said that in order to understand the problem, you need to understand the data. If you don’t understand any of them you will never find the optimal solution.

  • Focusing on the data flow and how data is read and written.
/*
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.
(As far as I know there's no possiblity to get this value automatically.)
This is not for scaled or rotated artwork. If you need those features, look at low res render textures.
Use this however you want.
@mandarinx
mandarinx / NormalsVisualizer.cs
Last active October 19, 2024 22:51
Visualize mesh normals in Unity3D
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(MeshFilter))]
public class NormalsVisualizer : Editor {
private const string EDITOR_PREF_KEY = "_normals_length";
private Mesh mesh;
private MeshFilter mf;
private Vector3[] verts;
@mandarinx
mandarinx / CreateNewInspector.cs
Last active January 17, 2017 11:30
Create Inspector for a MonoBehaviour
using UnityEditor;
using UnityEngine;
using System;
using System.IO;
using System.Collections.Generic;
static public class CreateNewInspector {
[MenuItem("Assets/Create/C# Inspector", false, 82)]
static public void CreateInspector() {
@mandarinx
mandarinx / NewScene.cs
Created September 20, 2016 12:05
Create a custom scene in Unity3D
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
static public class NewScene {
[MenuItem("File/New Custom Scene %&n")]
static public void CreateNewScene() {
if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo()) {
@mandarinx
mandarinx / SimpleGeo.cs
Created September 14, 2016 13:55 — forked from phosphoer/SimpleGeo.cs
Simple Geometry Painter for Unity
// The MIT License (MIT)
// Copyright (c) 2016 David Evans @phosphoer
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
@mandarinx
mandarinx / README.md
Created August 24, 2016 06:53
Sprite outlines shader