Skip to content

Instantly share code, notes, and snippets.

@Sov3rain
Sov3rain / ExtendedScriptableObjectDrawer.cs
Created January 24, 2020 10:45 — forked from tomkail/ExtendedScriptableObjectDrawer.cs
Displays the fields of a ScriptableObject in the inspector
// Developed by Tom Kail at Inkle
// Released under the MIT Licence as held at https://opensource.org/licenses/MIT
// Must be placed within a folder named "Editor"
using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
@Sov3rain
Sov3rain / ReadOnlyAttribute.cs
Created June 11, 2020 13:34 — forked from MattRix/ReadOnlyAttribute.cs
Read Only Attribute for Unity (just mark stuff as [ReadOnly] the same way you would use [HideInInspector])
using UnityEngine;
using System;
using System.Reflection;
using System.Text.RegularExpressions;
[AttributeUsage (AttributeTargets.Field,Inherited = true)]
public class ReadOnlyAttribute : PropertyAttribute {}
#if UNITY_EDITOR
[UnityEditor.CustomPropertyDrawer (typeof(ReadOnlyAttribute))]
@Sov3rain
Sov3rain / Example.txt
Last active October 3, 2021 19:01
Custom yield instruction to wait inside a Unity coroutine until a callback is called.
public static class UrlDownloader
{
public static void DownloadText(string url, Action<string> callback);
}
// Brute force way of doing it
IEnumerator MyAsyncFunction()
{
var done = false;
var result = default(string);
@Sov3rain
Sov3rain / ScrollRectExtensions.cs
Last active August 2, 2024 06:28
Tell the Unity Scroll Rect View to snap to the given element (top).
using UnityEngine;
using UnityEngine.UI;
public static class ScrollRectExtensions
{
/// <summary>
/// Tell the Scroll Rect View to snap to the given element (top).
/// </summary>
public static void SnapTo(
this ScrollRect scrollRect,
@Sov3rain
Sov3rain / TouchOverUI.cs
Last active January 5, 2022 16:26
[Unity] Find if a touch is over a UI element
static class TouchHelper
{
// OG version: https://www.reddit.com/r/Unity3D/comments/6o9zsy/comment/dkgxa1i/?utm_source=share&utm_medium=web2x&context=3
public static bool IsOverUI()
{
PointerEventData pointerData = new PointerEventData(EventSystem.current);
pointerData.position = Input.mousePosition;
List<RaycastResult> results = new List<RaycastResult>();
@Sov3rain
Sov3rain / EventManager.cs
Last active August 30, 2025 11:47
Simple 0 dependency Event Bus for Unity C#
using System;
using UnityEngine;
using System.Collections.Generic;
public static class EventManager<T>
{
private static readonly List<Action<T>> _listeners = new List<Action<T>>(8);
public static void AddListener(Action<T> handler)
{
@Sov3rain
Sov3rain / UnityAsyncOperationAwaiter.cs
Created April 16, 2024 20:25 — forked from mattyellen/UnityAsyncOperationAwaiter.cs
Allows the use of async/await (instead of yield) with any Unity AsyncOperation
public static class ExtensionMethods
{
public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)
{
var tcs = new TaskCompletionSource<object>();
asyncOp.completed += obj => { tcs.SetResult(null); };
return ((Task)tcs.Task).GetAwaiter();
}
}
@Sov3rain
Sov3rain / ServiceAccountJsonToToken.cs
Last active September 4, 2024 12:05 — forked from 5argon/ServiceAccountJsonToToken.cs
From service account .json file -> JWT -> OAuth2 service account token with pure REST API in Unity
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
using UnityEngine.Networking;
using static UnityEngine.Networking.UnityWebRequest.Result;
@Sov3rain
Sov3rain / SecurePlayerPrefs.cs
Created February 11, 2025 15:41
SecurePlayerPrefs is a secure wrapper for Unity's PlayerPrefs that provides encrypted data storage for sensitive information in Unity applications.
using System;
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using UnityEngine;
public static class SecurePlayerPrefs
{
private static readonly string _encryptionKey = DeriveKey();