Skip to content

Instantly share code, notes, and snippets.

@SolidAlloy
SolidAlloy / unity_dark_theme.py
Last active March 4, 2020 21:47
Change the Unity theme to Dark in one command
# 1. Change the path to Unity Editors in the path_to_unity variable below.
# 2. Edit the search and replace patterns in case they don't work for your version of Unity.
# 3. Run a command like this: python unity_dark_theme.py 2019.3.3f1
# 4. In case something goes wrong, remove Unity.exe and rename Unity_bak.exe to Unity.exe.
import binascii
import shutil
import sys
@SolidAlloy
SolidAlloy / style.css
Last active February 8, 2021 09:51
Dark Theme for Tree Style Tab
:root {
--bg-color: #2e3440;
--bg-color-nactive: #e8e8e8;
--shadow-color: #404040;
--shadow-color-inactive: #868686;
--tab-surface-active-color: #94A1C0;
--tab-surface-active-gradient: -moz-linear-gradient(top, #A0B0CF, #7386AB) repeat-x;
--tab-surface-active-gradient-inactive: -moz-linear-gradient(top, #B4B4B4, #8A8A8A) repeat-x;
--tab-text: #e5e9f0;
--tab-text-inverted: #2e3440;
@SolidAlloy
SolidAlloy / fix_unity_template.py
Created May 9, 2020 18:00
Overwrite Unity default template in one command.
# 1. Change the path to Unity Editors in the path_to_unity variable below.
# 2. Put the template you wish to use in the template_content variable.
# 3. Run a command like this: python unity_dark_theme.py 2019.3.3f1
import sys
if len(sys.argv) != 2:
sys.exit("Provide a Unity version as an argument.")
using System;
using UnityEngine;
/// <summary>
/// This is a generic Singleton implementation for Monobehaviours.
/// Create a derived class where the type T is the script you want to "Singletonize"
/// Upon loading it will call DontDestroyOnLoad on the gameobject where this script is contained
/// so it persists upon scene changes.
/// </summary>
/// <remarks>
@SolidAlloy
SolidAlloy / SingleOnScene.cs
Created May 17, 2020 12:59
Unity MonoBehaviour that can be added only once per scene and can be accessed via Instance like a singleton.
using System.Linq;
using UnityEngine;
/// <summary>
/// This is a generic implementation of MonoBehaviour that can be placed only once on a scene.
/// Create a derived class where the type T is the class you want to be single on the scene.
/// It is very similar to the Singleton pattern except the object will be destroyed when the scene is unloaded.
/// Methods still can be called via the static Instance property to avoid using GetComponent().
/// </summary>
/// <typeparam name="T">
@SolidAlloy
SolidAlloy / BoxCastDrawer.cs
Created May 17, 2020 14:36
A class that allows to visualize Unity Physics2D.BoxCast() method.
using UnityEngine;
/// <summary>
/// A class that allows to visualize the Physics2D.BoxCast() method.
/// </summary>
/// <remarks>
/// Use Draw() to visualize an already cast box,
/// and BoxCastAndDraw() to cast a box AND visualize it at the same time.
/// </remarks>
@SolidAlloy
SolidAlloy / FBasic_AddPhysicalImpact.cs
Created June 3, 2020 15:46
More useful version of the AddPhysicalImpact script from the fBasic Asset.
using UnityEngine;
using UnityEngine.Events;
using Random = UnityEngine.Random;
namespace FIMSpace.Basics
{
/// <summary>
/// Simple class which is adding physical impact on target rigidbody for provided time
/// </summary>
public class FBasic_AddPhysicalImpact : MonoBehaviour
@SolidAlloy
SolidAlloy / AutoKeyDictionary.cs
Last active June 18, 2020 08:01
A dictionary implementation that generates keys automatically and returns them in the Add() method.
// A dictionary implementation that generates keys automatically and returns them in the Add() method.
// This is basically a nicely presented copy of the code snippet from this post
// https://stackoverflow.com/a/39104018/9833103
namespace CustomDataStructures
{
using System;
using System.Collections;
using System.Collections.Generic;
@SolidAlloy
SolidAlloy / Identifier.cs
Created October 21, 2020 11:17 — forked from FabienDehopre/Identifier.cs
Validate C# identifier name
using System;
using System.Linq;
using System.Text.RegularExpressions;
public static class IdentifierExtensions
{
// definition of a valid C# identifier: http://msdn.microsoft.com/en-us/library/aa664670(v=vs.71).aspx
private const string FORMATTING_CHARACTER = @"\p{Cf}";
private const string CONNECTING_CHARACTER = @"\p{Pc}";
private const string DECIMAL_DIGIT_CHARACTER = @"\p{Nd}";
@SolidAlloy
SolidAlloy / RoslynDirectoryCreator.cs
Last active May 16, 2022 18:52
Workaround for when Unity complains about the missing RoslynAnalysisRunner folder.
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
internal static class RoslynDirectoryCreator
{
static RoslynDirectoryCreator() => Application.logMessageReceived += OnLogMessageReceived;