Skip to content

Instantly share code, notes, and snippets.

@sttz
sttz / SceneLabelsPreserver.cs
Created January 8, 2023 13:18
Workaround for Unity 2022.2 bug where scene asset labels are removed on save
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine.SceneManagement;
using System.IO;
/// <summary>
/// Workaround for bug: https://issuetracker.unity3d.com/issues/scene-asset-label-disappears-when-the-scene-is-saved
/// Saves the scene's label before and re-applies them after saving.
/// Will log if the labels are preserved and this workaround is no longer necessary.
@sttz
sttz / ScrollToCeneter.cs
Last active November 4, 2023 05:10
Method to center an element in a ScrollRect using Unity's new UI system
using UnityEngine;
using UnityEngine.UI;
public static class UIExtensions {
// Shared array used to receive result of RectTransform.GetWorldCorners
static Vector3[] corners = new Vector3[4];
/// <summary>
/// Transform the bounds of the current rect transform to the space of another transform.
/// </summary>
@sttz
sttz / OrbGestureFix.h
Last active March 6, 2022 16:40
iOS touch delay workaround for Unity, caused by 3D Touch app switcher. Put the two files in the Assets/Plugins/iOS folder of your Unity project and build like normal.
#pragma once
#include "UnityAppController.h"
#include "UnityView.h"
/*
This is a workaround for touches delayed by about 1s near the left
screen edge on iOS devices with 3D Touch
The issue is due to the global app switcher, which is invoked with
@sttz
sttz / AndroidKeystoreAuthenticator.cs
Created June 15, 2017 16:16
Unity editor script that stores Android Keystore passwords in the macOS Keychain.
using System;
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEngine;
#if UNITY_EDITOR_OSX
/// <summary>
/// Unity clears Android Keystore and Key Alias passwords when it exits,
@sttz
sttz / yamlmerge-proxy.py
Created June 6, 2017 18:15
Wrapper that finds the latest UnityYAMLMerge installed on your Mac
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# The MIT License (MIT)
#
# Copyright (c) 2017 Adrian Stutz
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@sttz
sttz / gist:48ced67e51f3d5ccdcf8
Created March 19, 2015 23:48
Unity 5 Sprite Shader with Depth Writing
Shader "Sprites/DefaultWithDepth"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
@sttz
sttz / StoppableCoroutine.cs
Last active February 9, 2022 10:12
Simple wrapper around Unity coroutines (generator methods) that allows to stop them from the outside. Unity natively only allows this when starting the coroutine by using its lexical name.
using System;
using System.Collections;
using UnityEngine;
/// <summary>
/// Wrapper around coroutines that allows to start them without using
/// their lexical name while still being able to stop them.
/// </summary>
public class StoppableCoroutine : IEnumerator
{
@sttz
sttz / userstyles.css
Created March 27, 2012 19:52
Google Toolbar Removal User CSS
#gbx3 {
background-color: transparent !important;
border: none !important;
}
#gbzw {
height: 0 !important;
overflow: hidden !important;
}