Skip to content

Instantly share code, notes, and snippets.

View SiarheiPilat's full-sized avatar
🍌
Working from home

spilat12 SiarheiPilat

🍌
Working from home
View GitHub Profile
// Taken from: https://discussions.unity.com/t/inspector-field-for-scene-asset/40763
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[System.Serializable]
public class SceneField
@SiarheiPilat
SiarheiPilat / OpenEditorWindowsTracker.cs
Last active February 27, 2024 19:46
Get all currently open editor windows in Unity.
using UnityEngine;
using UnityEditor;
public class InternalEditorWindowsTracker : MonoBehaviour
{
/// <summary>
/// Get all currently open editor windows including default Unity windows, custom editors and windows that are tabbed.
/// Found here: https://answers.unity.com/questions/1237463/how-do-i-get-a-reference-to-the-default-editor-win.html?_ga=2.133529742.1822843399.1574452927-44739247.1572947128
/// </summary>
public static EditorWindow[] GetAllOpenEditorWindows()
public static T[] Shuffle<T>(T[] array)
{
T[] shuffledArray = new T[array.Length];
Array.Copy(array, shuffledArray, array.Length);
System.Random random = new System.Random();
for (int i = shuffledArray.Length - 1; i > 0; i--)
{
int j = random.Next(0, i + 1);
T temp = shuffledArray[i];
shuffledArray[i] = shuffledArray[j];
@SiarheiPilat
SiarheiPilat / MultiScreenshotCapture.cs
Last active January 13, 2024 11:55 — forked from yasirkula/MultiScreenshotCapture.cs
Capture multiple screenshots with different resolutions simultaneously in Unity 3D
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace MultiScreenshotCaptureNamespace
{
internal static class ReflectionExtensions
@SiarheiPilat
SiarheiPilat / FirebaseTest.cs
Created December 14, 2023 20:56
Simple script to test whether Firebase backend is working.
using UnityEngine;
using Firebase;
using Firebase.Analytics;
public class FirebaseTest : MonoBehaviour
{
void Start()
{
FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => { FirebaseAnalytics.SetAnalyticsCollectionEnabled(true); });
}
@SiarheiPilat
SiarheiPilat / ExcemptFromEncryption.cs
Last active December 12, 2023 20:58
Automates encryption compliance setting for iOS builds.
#if UNITY_IOS
using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using System.IO;
public class ExcemptFromEncryption : IPostprocessBuildWithReport // Will execute after XCode project is built
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
// NOTE: This DOES work, but need to do it twice??
// This is only useful for spritesheets that need to be automatically sliced (Sprite Editor > Slice > Automatic)
public class AutoSpriteSlicer
@SiarheiPilat
SiarheiPilat / CoolButton.cs
Last active August 22, 2023 21:29
Replacement for a TextMeshPRO button that will automatically change button text.
using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// Original: https://gist.github.com/SiarheiPilat/e4fa93c97d31d8d0e2d18f34e0e2abe9
/// Author: Siarhei Pilat
/// Date: 29-05-2022
/// License: MIT
public class CoolButton : MonoBehaviour
@SiarheiPilat
SiarheiPilat / new pre commit
Last active March 15, 2023 18:32
Automatically increment project version on each commit to main (on pre commit)
#!/bin/sh
# new pre commit
# get bundle version
bundle_ver=`cat ./ProjectSettings/ProjectSettings.asset | grep bundleVersion | cut -d ' ' -f 4`
# explanation:
# cat - concatenate the content of multiple files
# cat [option] [file]
# cut command is a fast way to extract parts of lines of text files
@SiarheiPilat
SiarheiPilat / IncrementBuildNumber.cs
Created March 8, 2023 03:32 — forked from martinpi/IncrementBuildNumber.cs
Automatically increment the iOS build number in Unity conforming to Apple's guidelines before every build. Be sure to drop into a folder name "Editor". Worked in autumn 2020.
using UnityEngine;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEditor;
public class IncrementBuildNumber : IPreprocessBuildWithReport {
public int callbackOrder { get { return 0; } } // Part of the IPreprocessBuildWithReport interface
public void OnPreprocessBuild(BuildReport report) {
if (report.summary.platform == BuildTarget.iOS) {