Skip to content

Instantly share code, notes, and snippets.

@munkbusiness
munkbusiness / EmoPacker.cs
Last active May 29, 2024 16:38 — forked from MattRix/EmoPacker.cs
2022 version of the EmoPacker script that creates a image for a TMP sprite asset to use. There is still some wierd issues, with files needing to be exist already, and the TMP asset is updating wierdly. Specifically instead of using metadata it now uses the new spriterects, which is the replacement.
using System.IO;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using TMPro;
using UnityEditor.U2D.Sprites;
public class EmoPacker
{
@munkbusiness
munkbusiness / EnumerableExtensions
Created March 20, 2018 10:45
Generic type array shuffling based on @fincha solutions
using System.Collections.Generic;
using UnityEngine;
public static class EnumerableExtensions {
public static T[] ShuffleArray<T>(this T[] a) {
// Loops through array
for (int i = a.Length - 1; i > 0; i--) {
// Randomize a number between 0 and i (so that the range decreases each time)
int rnd = UnityEngine.Random.Range(0, i);
@munkbusiness
munkbusiness / Vibration.cs
Last active November 24, 2023 00:42
Vibration for Unity3d with Android native Call that supports both the new vibrationEffectClass and the old simple vibrate, with fallback to Handlheld.Vibrate().
using UnityEngine;
using System.Collections;
public class Vibration : MonoBehaviour {
public static AndroidJavaClass unityPlayer;
public static AndroidJavaObject vibrator;
public static AndroidJavaObject currentActivity;
public static AndroidJavaClass vibrationEffectClass;
public static int defaultAmplitude;