Skip to content

Instantly share code, notes, and snippets.

@mattyellen
mattyellen / UnityAsyncOperationAwaiter.cs
Created July 26, 2020 19:36
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();
}
}
@XEonAX
XEonAX / GameState.cs
Created February 12, 2022 17:32 — forked from selalipop/GameState.cs
Using Server-Sent-Events in Unity
using Newtonsoft.Json;
///Use of Newtonsoft.Json is fully optional
namespace Backend
{
[JsonObject]
public struct GameState
{
[JsonProperty("maxPlayers")] public int MaxPlayers;
[JsonProperty("imposterCount")] public int ImposterCount;
@Sov3rain
Sov3rain / IfNotNull.cs
Last active April 13, 2022 15:42
Monad in c#
using System;
void Main()
{
string foo = "Hello";
// a.then(f).then(g).then(j)
foo.Then(x => x.Trim().Ret())
.Then(x => x.Substring(0, 5).Ret())
.Then(x => x.Length.Ret())
@rent-a-developer
rent-a-developer / ActionExtensions.cs
Created June 5, 2022 21:01
An implementation of a debounce and a throttle logic in C#
/// <summary>
/// Provides extension methods for the <see cref="Action" /> type.
/// </summary>
public static class ActionExtensions
{
/// <summary>
/// Creates a debounced version of the given function <paramref name="action" />.
/// Use this method when you want a function to be executed after a certain amount of time has passed since it was called the last time.
/// </summary>
/// <param name="action">The function to debounce.</param>
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unity.Services.CloudSave;
using UnityEngine;
public class CloudSaveClient : ISaveClient
{
private readonly ICloudSaveDataClient _client = CloudSaveService.Instance.Data;
@mrcarriere
mrcarriere / iPhone 14 Pro Max.device
Last active January 23, 2025 08:38
iPhone 14 Pro & Pro Max Device Definitions
{
"friendlyName": "Apple iPhone 14 Pro Max",
"version": 1,
"screens": [
{
"width": 1290,
"height": 2796,
"navigationBarHeight": 0,
"dpi": 460.0,
"orientations": [
@prodigga
prodigga / SSE_Download_Handler.md
Last active January 27, 2025 15:35
SSE's (Server-Sent Events) Download Handler

Whats this?

This is a custom UnityWebRequest Download Handler to support SSE's (Server-Sent Events) in Unity!

How to use it

Simply inhert SseDownloadHandlerBase and supply your own logic (Deserialise incoming lines, expose events, etc).

Then set the download handler to be an instance of your class.

webRequest.downloadHandler = new LogSseExampleDownloadHandler();