Skip to content

Instantly share code, notes, and snippets.

View harunseng's full-sized avatar
🎯

harun seng harunseng

🎯
View GitHub Profile
@harunseng
harunseng / UnityGuidRegenerator.cs
Created September 26, 2023 17:46 — forked from ZimM-LostPolygon/UnityGuidRegenerator.cs
Unity asset GUIDs regenerator
// Drop into Assets/Editor, use "Tools/Regenerate asset GUIDs"
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using UnityEditor;
namespace UnityGuidRegenerator {
public class UnityGuidRegeneratorMenu {
@harunseng
harunseng / MeshRendererSortingEditor.cs
Created November 17, 2022 22:36 — forked from Manamongods/MeshRendererSortingEditor.cs
Expose sorting layer in MeshRenderer inspector, for rendering on top of sprites
using System;
using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Reflection;
/// This just exposes the Sorting Layer / Order in MeshRenderer since it's there
/// but not displayed in the inspector. Getting MeshRenderer to render in front
/// of a SpriteRenderer is pretty hard without this.
/// Adapted from https://gist.github.com/sinbad/bd0c49bc462289fa1a018ffd70d806e3
@harunseng
harunseng / CanvasPositioningExtensions.cs
Created August 11, 2022 07:27 — forked from FlaShG/CanvasPositioningExtensions.cs
A small Unity helper class to convert viewport, screen or world positions to canvas space.
using UnityEngine;
/// <summary>
/// Small helper class to convert viewport, screen or world positions to canvas space.
/// Only works with screen space canvases.
/// </summary>
/// <example>
/// <code>
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </code>
@harunseng
harunseng / MoveCameraInertia.cs
Created July 20, 2022 09:57 — forked from JISyed/MoveCameraInertia.cs
Similar to MoveCamera.cs (https://gist.github.com/JISyed/5017805), except with inertia. This makes the camera gradually come to a smooth stop when stopping the camera movement.
// Credit to damien_oconnell from http://forum.unity3d.com/threads/39513-Click-drag-camera-movement
// for using the mouse displacement for calculating the amount of camera movement and panning code.
using UnityEngine;
using System.Collections;
public class MoveCamera : MonoBehaviour
{
//
@harunseng
harunseng / CustomHoldingInteraction.cs
Created June 21, 2022 14:41 — forked from Invertex/CustomHoldingInteraction.cs
Unity New Input System custom Hold "Interaction" where the .performed callback is constantly triggered while input is held.
using UnityEngine;
using UnityEngine.InputSystem;
//This script should NOT be placed in an "Editor" folder. "Plugins" is ideal but elsewhere is fine too.
namespace Invertex.UnityInputExtensions.Interactions
{
/// <summary>
/// Custom Hold interaction for New Input System.
/// With this, the .performed callback will be called everytime the input system updates.
/// Allowing a purely callback based approach to a button hold instead of polling it in an Update() loop and using bools
/// .started will be called when the 'pressPoint' threshold has been hit.
@harunseng
harunseng / frag.glsl
Created January 21, 2022 05:59 — forked from 983/frag.glsl
hsv rgb conversion glsl shader
// because http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl is often down
vec3 rgb2hsv(vec3 c)
{
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
float d = q.x - min(q.w, q.y);
float e = 1.0e-10;
@harunseng
harunseng / CurveController.cs
Created January 19, 2022 06:52 — forked from herohiralal/CurveController.cs
Add curvature to the rendering without changing simulation code.
using UnityEngine;
namespace AIEngineTest
{
public class CurveController : MonoBehaviour
{
private static CurveController s_Instance = null;
private const float k_StraightDistanceClamp = 50f;
private const float k_CurvatureClamp = 10f;
@harunseng
harunseng / UIBlur.shader
Created June 9, 2021 16:57 — forked from JohannesMP/UIBlur.shader
UI.Image Blur Shader with layering and masking support
Shader "Custom/UIBlur"
{
Properties
{
[Toggle(IS_BLUR_ALPHA_MASKED)] _IsAlphaMasked("Image Alpha Masks Blur", Float) = 1
[Toggle(IS_SPRITE_VISIBLE)] _IsSpriteVisible("Show Image", Float) = 1
// Internally enforced by MAX_RADIUS
_Radius("Blur Radius", Range(0, 64)) = 1
@harunseng
harunseng / PhysicsHelper.cs
Created June 7, 2021 19:44 — forked from ditzel/PhysicsHelper.cs
Unity Helper for Physic Functions
using UnityEngine;
namespace Ditzelgames
{
public static class PhysicsHelper
{
public static void ApplyForceToReachVelocity(Rigidbody rigidbody, Vector3 velocity, float force = 1, ForceMode mode = ForceMode.Force)
{
if (force == 0 || velocity.magnitude == 0)
@harunseng
harunseng / BendMesh.shader
Created February 9, 2021 11:57 — forked from shaggun/BendMesh.shader
Bending a mesh with a shader in Unity
Shader "BendMesh"
{
Properties
{
_Texture("Texture", 2D) = "white" {}
_Color("Color", Color) = (0,0,0,0)
_Amplitude("Amplitude", Float) = 0
_Frequency("Frequency", Float) = 0
_OffsetSin("OffsetSin", Float) = 0