Skip to content

Instantly share code, notes, and snippets.

View phosphoer's full-sized avatar

David Evans phosphoer

View GitHub Profile
@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
@phosphoer
phosphoer / AssetScratchpad.cs
Last active November 27, 2023 20:47
A drag and droppable 'scratchpad' for unity objects, useful as a palette or a quick select window.
using UnityEditor;
using UnityEngine;
using System.Collections.Generic;
public class AssetScratchpad : EditorWindow
{
private List<Object> _referenceList = new();
private Vector2 _scrollPosition;
[MenuItem("Window/Asset Scratchpad")]
@phosphoer
phosphoer / EpicGameClient.cs
Last active January 12, 2024 21:21
Epic Game SDK Unity Integration
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if BUILD_EPIC
using PlayEveryWare.EpicOnlineServices;
using Epic.OnlineServices;
using Epic.OnlineServices.Achievements;
using Epic.OnlineServices.Auth;
using Epic.OnlineServices.Presence;
using UnityEngine;
using UnityEngine.AI;
using System.Collections.Generic;
public class PathFindManager : Singleton<PathFindManager>
{
public bool IsBuilt => _isBuilt;
[SerializeField]
private LayerMask _obstacleMask = Physics.DefaultRaycastLayers;
@phosphoer
phosphoer / Tween.cs
Last active February 15, 2023 15:49
Simple set of coroutine helpers and tweening functions
using UnityEngine;
using System.Collections;
public static class Tween
{
public static IEnumerator Tween(float duration, System.Action<float> tweenFunc)
{
for (float timer = 0; timer < duration; timer += Time.deltaTime)
{
tweenFunc?.Invoke(timer / duration);
@phosphoer
phosphoer / HexMath.cs
Created May 27, 2022 18:00
Hex Grid Math
using UnityEngine;
public struct HexCoord
{
public float q;
public float r;
public float s;
public HexCoord(float q, float r)
{
@phosphoer
phosphoer / RenderToCPU.cs
Created April 27, 2022 05:17
AsyncGPUReadback Class
using Unity.Collections;
using UnityEngine;
using UnityEngine.Rendering;
[System.Serializable]
public class RenderToCPU
{
public event System.Action ErrorOccurred;
public int Width => _renderTarget.width;