Skip to content

Instantly share code, notes, and snippets.

@all-iver
all-iver / IdleLoop.cs
Created December 29, 2021 01:05
Disable Unity resource usage when idle, but wake instantly on input events
// See https://devlogs.fun/projects/89-femto-paint/log/posts/254-making-a-paint-app-in-unity for context
using UnityEngine;
using UnityEngine.LowLevel;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
/// <summary>This is a singleton to help with using Unity for application development. You have to be using the new
/// InputSystem for this to work (I haven't tried with legacy input). Put an instance of this in your scene. It works
/// by monitoring all input events, and if there hasn't been any event for a short time, it disables all unnecessary
@all-iver
all-iver / Rectangle.cginc
Created December 2, 2019 19:20
Custom round rectangle in Shapes2D
float4 _Roundness; // tl, tr, bl, br
fixed4 customRect(v2f i, float2 pos) {
float radius = min(_XScale, _YScale);
float distToCircle = radius - distance(float2(abs(pos.x), pos.y), float2(_XScale / 2 - radius, _YScale / 2));
float distToSide = _YScale / 2 - abs(pos.y);
float dist = when_ge(abs(pos.x), _XScale / 2 - radius) * min(distToSide, distToCircle)
+ when_le(abs(pos.x), _XScale / 2 - radius) * distToSide;
@all-iver
all-iver / FeedbackUI.cs
Last active October 5, 2019 22:42
Example of using SNS to gather user feedback in Unity
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using Amazon.SimpleNotificationService;
using Amazon.Runtime;
public class FeedbackUI : MonoBehaviour
{
public TMP_InputField feedbackInput; // where the user's message will go
public TMP_Text errorMessage; // we'll display any errors here