Skip to content

Instantly share code, notes, and snippets.

View unitycoder's full-sized avatar
✅
‏‏‎

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / ProjectionMapping.cs
Created October 11, 2022 08:08
projection mapping in a shader
// https://forum.unity.com/threads/projection-mapping.1220802/#post-7784367
// c#
Matrix4x4 V = cam.worldToCameraMatrix;
Matrix4x4 P = GL.GetGPUProjectionMatrix(cam.projectionMatrix, false);
Matrix4x4 VP = P*V;
material.SetMatrix("_Custom_Matrix_VP", VP);
@unitycoder
unitycoder / HowToProfilerBuildTime.txt
Created October 9, 2022 11:42 — forked from phi-lira/HowToProfilerBuildTime.txt
How to profile build time for a Unity project
1) Enable Profiler in OnPreprocessBuild like following:
public void OnPreprocessBuild(BuildReport report)
{
Profiler.enabled = true;
Profiler.enableBinaryLog = true;
Profiler.logFile = "profilerlog.raw";
Debug.Log("Enabling Profiler");
}
2) Disable Profiler in OnPostProcessBuild
3) Now put Profiler.Begin/EndSample in the desired code.
@unitycoder
unitycoder / AsIEnumerator.CS
Created October 4, 2022 13:45
Use async method in coroutine
// https://forum.unity.com/threads/use-async-method-in-coroutine.868825/#post-5719195
public static IEnumerator AsIEnumerator(this Task task)
    {
        while (!task.IsCompleted)
        {
            yield return null;
        }
 
        if (task.IsFaulted)
        {
@unitycoder
unitycoder / unity3d-assetstore-publisher-feed.php
Created October 3, 2022 11:00 — forked from jgraup/unity3d-assetstore-publisher-feed.php
PHP - Unity3D Asset Store Publisher Feed. You must supply your own secret key to use this, a key is generated per publisher at https://publisher.assetstore.unity3d.com/info.html
<?php
include_once ( 'unity3d-assetstore.php' );
// Doesn't matter what is used for the publisher name,
// the key still points to only one publisher.
$authArray = array (
'publisher' => '{PUBLISHER_NAME}'
'key' => '{PUBLISHER_KEY}',
);
@unitycoder
unitycoder / MakeGeometryDoubleSided.cs
Created September 22, 2022 10:53 — forked from kurtdekker/MakeGeometryDoubleSided.cs
Makes geometry double-sided by re-winding copies of each triangle to face the other way
using UnityEngine;
// @kurtdekker - quick double-siding mechanism.
//
// Place or add this Component to things with at
// least a MeshFilter on them.
//
// Presently only for single-submesh geometry.
[RequireComponent( typeof( MeshFilter))]
@unitycoder
unitycoder / CloneAndFlipTriangles.cs
Created September 22, 2022 10:53 — forked from kurtdekker/CloneAndFlipTriangles.cs
Clones and flips a piece of geometry, optionally using another material
using UnityEngine;
// @kurtdekker
//
// Place on a MeshFilter / MeshRenderer GameObject.
//
// This will:
// - duplicate the entire GameObject via Instantiate
// (and obviously its children; those are ignored!)
// - parent it to the same place the original was
@unitycoder
unitycoder / Unity-Editor-Slow.md
Created September 13, 2022 08:24
Slow Unity Editor notes
@unitycoder
unitycoder / Comment.cs
Created September 8, 2022 15:17 — forked from apkd/Comment.cs
Use this component to leave comments to other developers (and yourself) on GameObjects, prefabs, etc. Double-click the text area to edit.
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.Callbacks;
#endif
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using S = UnityEngine.SerializeField;
@unitycoder
unitycoder / CCL.cs
Last active September 1, 2022 06:53
Connected-component labeling script test
// https://unitycoder.com/blog/2022/09/01/testing-connected-component-labeling/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CCL : MonoBehaviour
{
Renderer r;
@unitycoder
unitycoder / Standard Double Sided Cutout.shader
Created August 31, 2022 08:25
Standard Double Sided Cutout HDR Emission Shader
// based on https://forum.unity.com/threads/custom-cutout-standard-shader-does-not-cutout-anything.409297/#post-7386134
Shader "Custom/Standard Double Sided Cutout Emissive"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
[HDR]_EmissionColor ("Emission Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0