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
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 / 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); });
}
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 / 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 / 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) {
@SiarheiPilat
SiarheiPilat / CsvReader.cs
Last active February 18, 2023 14:50
A lightweight CSV reader for Unity.
using UnityEngine;
using System.Collections.Generic;
using System.Text.RegularExpressions;
// original: https://github.com/tikonen/blog/blob/master/csvreader/CSVReader.cs
// IMPORTANT: CSV FILE MUST BE IN THE RESOURCES FOLDER
// USAGE EXAMPLE FOR A 3 COLUMN CSV FILE:
//
// [ContextMenu("test csv data")]
using UnityEditor;
using UnityEngine;
public class BuildToDesktop
{
[MenuItem("File/Build to Desktop")]
public static void BuildGame()
{
string dateTime = System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss");
string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop) + "/Build_" + dateTime;
@SiarheiPilat
SiarheiPilat / NcSimpleDialogueUi.cs
Created January 23, 2023 03:08
Simple UI script for NodeCanvas dialogue tree.
using System.Collections.Generic;
using UnityEngine;
using NodeCanvas.DialogueTrees;
using TMPro;
using UnityEngine.UI;
using NodeCanvas.Framework;
public class NcSimpleDialogueUi : MonoBehaviour
{
public TextMeshProUGUI NarrationText;
@SiarheiPilat
SiarheiPilat / FindCustomScriptsEditor.cs
Last active January 23, 2023 03:56
Find all custom scripts in the hierarchy of the current scene, show as a list of buttons, user can ping the object by clicking a button. Omits native Unity components.
using UnityEngine;
using UnityEditor;
using System;
namespace Suasor
{
public class FindCustomScriptsEditor : EditorWindow
{
Vector2 scrollPosition;
public string[] Strings = new string[4] {"BreakableHelper", "ObjectColor", "StickerController", "Obi" }; // REPLACE THIS WITH LIST EDITABLE