Skip to content

Instantly share code, notes, and snippets.

@Thaina
Thaina / ConvertTextureToPng.cs
Created July 30, 2023 12:26 — forked from krzys-h/SaveRenderTextureToFile.cs
[Unity] Save RenderTexture to image file
using UnityEngine;
using UnityEditor;
public class ConvertTextureToPng
{
const string MenuName = "Assets/Save Texture to png";
[MenuItem(MenuName)]
public static void SaveRTToFile()
{
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
@Thaina
Thaina / ShowCQT.cs
Last active January 10, 2024 13:15
Convert showcqt.c to ShowCQT.cs
/*
* Copyright (c) 2020 Muhammad Faiz <mfcc64@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
@Thaina
Thaina / CameraController.cs
Last active December 4, 2023 03:24
Unity camera code for calculate PerspectiveOffCenter. Use parent object of camera as screen and camera local position as perspective offset
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Android;
using Mediapipe.Unity;
using Mediapipe.Unity.IrisTracking;
using TMPro;
@Thaina
Thaina / backupdiskimages.bash
Created August 10, 2023 13:05
gcloud backup all disk to images
for data in $(gcloud compute disks list --format="csv[no-heading](NAME,LOCATION)"); do $(gcloud compute images create ${data%%,*} --source-disk="${data%%,*}" --source-disk-zone="${data#*,}" --storage-location=asia-southeast1); done;
@Thaina
Thaina / CursorLock.cs
Created March 26, 2023 13:51
Actual pointer lock value in unity webgl and windows editor
using System.Collections;
using System.Collections.Generic;
#if UNITY_EDITOR_WIN || UNITY_WEBGL
using System.Runtime.InteropServices;
#endif
using UnityEngine;
public static class CursorLock
@Thaina
Thaina / gist:32cbd1e8e180e8e683148a35ef694fda
Created February 21, 2023 08:38
List all git changed files and convert line ending
npm i -g eol-converter-cli
for /F "usebackq delims=" %i in (`git ls-files -m`) do (eolconverter lf "%i")
@Thaina
Thaina / Assets\Editor\TransparentWindowSetting.cs
Last active March 18, 2022 05:42
Unity Setting for transparent background in StandAlone Windows
// origin : Transparent Unity App! : Code Monkey : https://www.youtube.com/watch?v=RqgsGaMPZTw
using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class TransparentWindowSetting : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
// Modified from: http://wiki.unity3d.com/index.php/TextureScale#TextureScale.cs
// Only works on ARGB32, RGB24 and Alpha8 textures that are marked readable
using UnityEngine;
public class TextureScale {
private static Color[] texColors;
private static Color[] newColors;
private static int w;
@Thaina
Thaina / Generic Regex Formatter.cs
Created March 16, 2020 11:48
C# style string formatter using regex to search for key and replace with IFormattable.Format
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class RegexFormatter
{
static readonly Regex FormatterPattern = new Regex(@"\{([^\{\}]+?)(?:\:([^\{\}]*))?\}",RegexOptions.Multiline);
public static string RegexFormat(this string input,Func<string,object> selector)
{
return FormatterPattern.Replace(input,(match) => {