Skip to content

Instantly share code, notes, and snippets.

@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();
@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": [
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;
@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>
@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())
@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;
@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();
}
}
@JohannesDeml
JohannesDeml / README.md
Last active July 17, 2024 14:38
Remove Unity mobile notification warning for WebGL builds

Remove warning

Unity shows the following warning on mobile devices up to Unity 2019.4: "Please note that Unity WebGL is not currently supported on mobiles. Press OK if you wish to continue anyway." This script helps you remove this warning

Live example

To see live examples see Unity Web GL Loading Test

Logic

The script will run after the build has completed and replace the checks from all generated javascript files.

Support

@bfollington
bfollington / EventManager.cs
Last active August 30, 2023 14:21
EventManager messaging layer designed for Unity
using System.ComponentModel.Design;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System.Linq;
namespace Events
{
@5argon
5argon / ServiceAccountJsonToToken.cs
Last active September 4, 2024 11:57
From service account .json file -> JWT -> OAuth2 service account token with pure REST API in Unity
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
internal class ServiceAccountJsonToToken