Skip to content

Instantly share code, notes, and snippets.

@JohannesMP
JohannesMP / EnableDiscordDevExperiments.md
Last active April 26, 2024 12:21 — forked from ExordiumX/betaenabler.js
Enabling Discord Dev Experiments on Discord for Windows (2022-02)

Enable Dev Experiments in Discord for Windows

image

This guide shows how to enable dev mode for the Discord desktop application running on Windows (as of February 2022).

This can be used to view beta experiments to try features currently in development that are included but hidden by default in Discord release builds.


@JohannesMP
JohannesMP / UIBlur.shader
Last active April 18, 2024 21:12
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
@JohannesMP
JohannesMP / 2DLineRectIntersection.md
Last active April 18, 2024 00:53
[C#, Unity3D] An optimized solver for intersection between a Line Segment and a Rect in 2D space with spacial partitioning.

Overview

For a 2D Unity Project, I needed a really efficient way to get the intersection points between a line segment (as defined by two Vector2) and an axis-aligned Rect in 2D space, where the intersection points are returned as a parametric fraction of the length of the original line segment:

Note how when the line intersects the rect, the green line represents the portion inside the rect, and the parametric representation of the point of intersection along the line is displayed

In my use case the vast majority of lines are either completely inside or completely outside the rect, and so I needed an approach that was very efficient in cases where there is guaranteed no intersection and avoids unecessary raycasts when possible.

@JohannesMP
JohannesMP / Texture2DTGAExtension.cs
Last active March 26, 2024 05:11
[Unity3d] Add TGA Encoding to Texture2D
using UnityEngine;
// References:
// Quick and Dirty Writeable Bitmap as TGA image: http://nokola.com/blog/post/2010/01/21/Quick-and-Dirty-Output-of-WriteableBitmap-as-TGA-Image.aspx
// TGLoader: https://gist.github.com/mikezila/10557162
// Truevision TGA Specification on Wikipedia: https://en.wikipedia.org/wiki/Truevision_TGA#Technical_details
public static class Texture2DTGAExtension
{
public enum Channel { R, G, B, A, White, Black, Gray }
@JohannesMP
JohannesMP / LICENSE
Last active March 9, 2024 11:26
[Unity3D] A Reliable, user-friendly way to reference SceneAssets by script.
/*******************************************************************************
* Don't Be a Jerk: The Open Source Software License.
* Adapted from: https://github.com/evantahler/Dont-be-a-Jerk
*******************************************************************************
* _I_ am the software author - JohannesMP on Github.
* _You_ are the user of this software. You might be a _we_, and that's OK!
*
* This is free, open source software. I will never charge you to use,
* license, or obtain this software. Doing so would make me a jerk.
*
@JohannesMP
JohannesMP / ExtractMeshToFBX.cs
Last active January 6, 2024 07:22
Using the Unity FBX SDK to save a single Mesh as an FBX. Uses Unity FBX SDK from: https://assetstore.unity.com/packages/essentials/101408
using System.IO;
using UnityEngine;
using UnityEditor;
using Unity.FbxSdk;
using FbxExporters.Editor;
// Place in 'Editor' folder
public static class ExtractMeshToFBX
{
// true: fbx file is easy-to-debug ascii, false: fbx file is binary.
@JohannesMP
JohannesMP / EditorContextMenuCopySerialized.cs
Last active July 17, 2023 11:10
Unity Editor Context Menu Extensions
using UnityEngine;
using UnityEditor;
namespace UnityEditorExtensions
{
public static class EditorContextMenuCopySerialized
{
static SerializedObject sourceValues;
static System.Type sourceType;
Shader "Name" {
Properties {
_Name ("display name", Range (min, max)) = number
_Name ("display name", Float) = number
_Name ("display name", Int) = number
_Name ("display name", Color) = (number,number,number,number)
_Name ("display name", Vector) = (number,number,number,number)
@JohannesMP
JohannesMP / ClosestPointOnEllipse.cs
Last active March 28, 2023 10:13
[C#, Unity3D] Quickly find the closest point on an ellipse centered on the origin.
using UnityEngine;
using Math = System.Math;
public static class NearestPointTo
{
/// <summary>
/// Find the closest point on an ellipse centered on the origin.
/// </summary>
/// Credit:
/// 2015-09 Original Paper by Luc. Maisonobe https://www.spaceroots.org/documents/distance/distance-to-ellipse.pdf
@JohannesMP
JohannesMP / FlyCamera.cs
Last active February 17, 2023 14:10 — forked from RyanBreaker/FlyCamera.cs
Unity Script to give camera WASD + mouse control
using UnityEngine;
using System.Collections;
public class FlyCamera : MonoBehaviour
{
/*
Writen by Windexglow 11-13-10. Use it, edit it, steal it I don't care.
Converted to C# 27-02-13 - no credit wanted.
Reformatted and cleaned by Ryan Breaker 23-6-18
Added Right click for camera by JohannesMP 6-7-18