Skip to content

Instantly share code, notes, and snippets.

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityToolbarExtender;
/// <summary>
@danieldownes
danieldownes / gist:784af25818c3e7f8b118360d6663eb11
Created November 11, 2023 08:55
Resolve GIT LTS - file that should have been a pointer, but wasn't
git lfs migrate import --no-rewrite "broken file.jpg"
# OR older, and slower way:
git rm --cached -r .
git reset --hard
@danieldownes
danieldownes / Bash Merge files into single
Created April 12, 2023 22:08
Collapse many files into a single file
To collapse a whole project into a single file:
"cat files in current folder and all subfolders"
find . -type f -exec cat {} +
cat accepts multiple arguments:
cat * */*
@danieldownes
danieldownes / SceneLikeCamera
Created January 10, 2023 09:49
Camera controls like Unity Editor
using UnityEngine;
/// <summary>
/// Camera controls like Unity Editor.
/// </summary>
public class SceneLikeCamera : MonoBehaviour
{
[Header("Focus Object")]
[SerializeField, Tooltip("Enable double-click to focus on objects?")]
private bool doFocus = false;
@danieldownes
danieldownes / SearchForComponents.cs
Last active March 5, 2023 06:04
UnityEditor: Search For Components
//Assets/Editor/SearchForComponents.cs
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class SearchForComponents : EditorWindow
{
[MenuItem("Tools/Search For Components")]
static void Init ()
@danieldownes
danieldownes / ToolsMenu.cs
Last active March 5, 2023 06:04
Unity Tools Menu - Clear PlayPrefs and Screenshot
using System;
using UnityEngine;
using UnityEditor;
public class ToolsMenu
{
[MenuItem("Tools/Clear PlayerPrefs")]
private static void ClearPlayerPrefs()
{
PlayerPrefs.DeleteAll();
@danieldownes
danieldownes / github-ci-unity-hololens2-windows-uwp.yml
Created March 30, 2022 10:19 — forked from cookieofcode/github-ci-unity-hololens2-windows-uwp.yml
Github Actions CI Unity HoloLens 2 Build (Windows, UWP)
# GitHub Actions CI for Unity Hololens 2 UWP running on windows.
name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
@danieldownes
danieldownes / commitFilesByModificationDate.sh
Last active February 15, 2024 17:32
Commit file and use last modified date as author commit date
#!/bin/bash
# Get list of all files in all folders and subfolders
# ignore file and '.git' folder
# Sort by modification date, desc
find . -type f \( ! -iname "Thumbs.db" \) ! -path "./.git/*" -printf "%TY-%Tm-%TdT%TH:%TM:%.2TS%Tz$%p\n" |
sort -n |
@danieldownes
danieldownes / RandomPointOnMesh.cs
Last active April 9, 2024 12:14 — forked from v21/gist:5378391
Random point on a mesh, for Unity3D
using UnityEngine;
using System.Collections.Generic;
/// <summary>
/// Get total area of each triangle.
/// Find a random point within that total area.
/// Lookup which triangle that point relates to
/// Find a randiom point which point that triangle
/// This works for all mesh types, and gives fully distributed results.
/// Gist: https://gist.github.com/danieldownes/b1c9bab09cce013cc30a4198bfeda0aa
@danieldownes
danieldownes / ConvertRange.cs
Created March 11, 2022 13:01
ConvertRange oldValue, oldMin, oldMax, newMin, newMax
public static float ConvertRange(float oldValue, float oldMin, float oldMax, float newMin = 0, float newMax = 1)
{
float oldRange = (oldMax - oldMin);
if (oldRange == 0)
return newMin;
else
return (((oldValue - oldMin) * (newMax - newMin)) / oldRange) + newMin;
}