Skip to content

Instantly share code, notes, and snippets.

View phosphoer's full-sized avatar

David Evans phosphoer

View GitHub Profile
@phosphoer
phosphoer / TimeManager.cs
Created February 7, 2025 20:48
Unity Timescale Manager
using UnityEngine;
using System.Collections.Generic;
using System.Collections;
public class TimeManager : Singleton<TimeManager>
{
public static event System.Action TimeScaleChanged;
public float TimeScale => _timeScale;
@phosphoer
phosphoer / RangedFloat.cs
Created January 7, 2025 00:51
Ranged Float Unity
using UnityEngine;
[System.Serializable]
public struct RangedFloat
{
public float MinValue;
public float MaxValue;
public float RangeSize => MaxValue - MinValue;
@phosphoer
phosphoer / MeshCanvasUI.cs
Created December 4, 2024 22:52
Mesh Canvas UI
// The MIT License (MIT)
// Copyright (c) 2024 David Evans @festivevector
// 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 furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O
@phosphoer
phosphoer / MeshPool.cs
Created December 4, 2024 22:45
Unity Mesh Pool
// The MIT License (MIT)
// Copyright (c) 2024 David Evans @festivevector
// 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 furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O
@phosphoer
phosphoer / MeshCombiner.cs
Created December 4, 2024 22:40
Unity Mesh Combiner
// The MIT License (MIT)
// Copyright (c) 2024 David Evans @festivevector
// 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 furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O
@phosphoer
phosphoer / ContextMenuButtons.cs
Created November 17, 2024 22:37
Unity Context Menu Inspector Buttons
// Based heavily on https://github.com/SubjectNerd-Unity/ReorderableInspector
// Pulled out just the relevant bits to make the context menu buttons work
// Put this in an Editor folder and mark a method on a component with [ContextMenu] to get a clickable button in the inspector!
using UnityEngine;
using UnityEditor;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System;
@phosphoer
phosphoer / ScrollRectTransform.cs
Last active October 3, 2024 00:54
Custom Unity ScrollRect
using UnityEngine;
public class ScrollRectTransform : MonoBehaviour
{
public Vector2 ScrollPosition
{
get => _content.anchoredPosition;
set => SetScrollPosition(value);
}
@phosphoer
phosphoer / SceneField.cs
Created August 28, 2024 18:42
SceneField
// Taken from http://wiki.unity3d.com/index.php/SceneField
using UnityEngine;
[System.Serializable]
public class SceneField : ISerializationCallbackReceiver
{
#if UNITY_EDITOR
public UnityEditor.SceneAsset sceneAsset;
@phosphoer
phosphoer / CameraControllerPhoto.cs
Created April 13, 2024 03:13
Camera Mouse Movement
using UnityEngine;
public class CameraControllerPhoto : CameraControllerBase
{
public float Sensitivity = 1.5f;
public float MaxPitch = 45.0f;
public float MoveSpeed = 10;
public float MaxDistance = 30.0f;
public float MinDistToGeometry = 2.0f;
public float MinDistToTerrain = 5.0f;
@phosphoer
phosphoer / EditorSelectionHistory.cs
Created December 6, 2023 22:20
A custom window for Unity that displays a drag and droppable object selection history
// The MIT License (MIT)
// Copyright (c) 2023 David Evans @festivevector
// 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 furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O