Skip to content

Instantly share code, notes, and snippets.

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

mika unitycoder

✅
‏‏‎
View GitHub Profile
@unitycoder
unitycoder / frame-object.cs
Created June 5, 2022 07:31
fit object into camera view
// https://forum.unity.com/threads/fit-object-exactly-into-perspective-cameras-field-of-view-focus-the-object.496472/#post-8181533
float virtualsphereRadius = Vector3.Magnitude(bounds.max-bounds.center);
float minD = (virtualsphereRadius )/ Mathf.Sin(Mathf.Deg2Rad*cam.fieldOfView/2);
Vector3 normVectorBoundsCenter2CurrentCamPos= (cam.transform.position - bounds.center) / Vector3.Magnitude(cam.transform.position -  bounds.center);
cam.transform.position =  minD*normVectorBoundsCenter2CurrentCamPos;
cam.transform.LookAt(bounds.center);
cam.nearClipPlane = minD- virtualsphereRadius;
@unitycoder
unitycoder / PostProcessSetup.cs
Last active December 12, 2025 18:15
Toggle post processing from script, runtime (birp) : bloom, AO - postprocessing adjust values from scripts
http://answers.unity.com/answers/1483341/view.html
using UnityEngine.Rendering.PostProcessing;
// properties of class
public float bloom = 10f;
public float saturation = 5f;
Bloom bloomLayer = null;
AmbientOcclusion ambientOcclusionLayer = null;
@unitycoder
unitycoder / TouchIt.cs
Created May 20, 2022 08:23
Unity WebGL Detect is device is Mobile (touch screen)
// cannot detect other way, unless would check for mobile browser agents(?)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchIt : MonoBehaviour
{
public GameObject touchOn;
bool isMobile = false;
@unitycoder
unitycoder / context-menu.md
Last active November 6, 2023 10:24
clear context menu
// https://forum.unity.com/threads/how-do-i-implement-decals-into-a-shader-in-hlsl.1282727/
Shader "Unlit/SimpleDecalURP"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Transparent" "Queue"="Transparent"}
@unitycoder
unitycoder / Voronoi.cs
Created April 22, 2022 12:11
Voronoi Texture Generator Unity
// https://forum.unity.com/threads/need-help-cleaning-up-my-cell-noise-texture.1271381/
public static class Voronoi
{
    private static Texture2D tex;
    public static int numberOfCells = 11;
    public static int width = 64, height = 64;
 
    private static Vector2Int[] cell;
 
    public static Texture2D GenerateVoronoi()
@unitycoder
unitycoder / RandomSpeed.cs
Created April 20, 2022 10:18
Performance: UnityEngine.Random VS System.Random
// https://www.youtube.com/watch?v=wDyTtVqW_VY
// https://blog.unity.com/technology/unpredictably-fun-the-value-of-randomization-in-game-design
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RandomSpeed : MonoBehaviour
{
using System.Reflection;
using UnityEditor.ShaderGraph;
using UnityEngine;
[Title("Custom", "Image", "Sobel Edge Detection")]
public class SobelNode : CodeFunctionNode
{
public SobelNode()
{
name = "Sobel Edge Detection";
@unitycoder
unitycoder / VectorRangeAttribute.cs
Created April 12, 2022 10:45 — forked from DGoodayle/VectorRangeAttribute.cs
Limit a Vector2 within a certain range like a boss.
using UnityEngine;
using UnityEditor;
/*
Vector Range Attribute by Just a Pixel (Danny Goodayle @DGoodayle) - http://www.justapixel.co.uk
Copyright (c) 2015
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
@unitycoder
unitycoder / RadialLayout.cs
Created April 12, 2022 10:45 — forked from DGoodayle/RadialLayout.cs
Radial Layouts in Unity
using UnityEngine;
using UnityEngine.UI;
/*
Radial Layout Group by Just a Pixel (Danny Goodayle) - http://www.justapixel.co.uk
Copyright (c) 2015
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