Skip to content

Instantly share code, notes, and snippets.

@mrcarriere
mrcarriere / iPhone 14 Pro Max.device
Last active May 29, 2024 10:10
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;
@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())
@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 September 16, 2023 01:55
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
{
@lawrence-laz
lawrence-laz / BaseBehaviour.cs
Created November 30, 2018 18:00
Automatically get components in Unity using [GetComponent] attribute
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
public class BaseBehaviour : MonoBehaviour
{
protected virtual void OnEnable()
{
@SeanMcTex
SeanMcTex / PinToSafeArea.cs
Last active March 2, 2024 07:27
Restrict Unity UI to an iPhone X or other Mobile Device's Safe Area
using UnityEngine;
/// <summary>
/// Resizes a UI element with a RectTransform to respect the safe areas of the current device.
/// This is particularly useful on an iPhone X, where we have to avoid the notch and the screen
/// corners.
///
/// The easiest way to use it is to create a root Canvas object, attach this script to a game object called "SafeAreaContainer"
/// that is the child of the root canvas, and then layout the UI elements within the SafeAreaContainer, which
/// will adjust size appropriately for the current device./// </summary>
@jminor
jminor / Standard-DoubleSided.shader
Created June 1, 2017 16:30
Unity Standard-DoubleSided.shader
Shader "Standard-DoubleSided"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo", 2D) = "white" {}
_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
_Glossiness("Smoothness", Range(0.0, 1.0)) = 0.5
using System;
using UnityEngine;
namespace UnityRest
{
public static class JsonHelper
{
public static T[] FromJson<T>(string jsonArray)
{
jsonArray = WrapArray (jsonArray);