Skip to content

Instantly share code, notes, and snippets.

@darktable
darktable / UnityGetNativeAndroidVersion
Created March 4, 2022 22:03 — forked from kibotu/UnityGetNativeAndroidVersion
Get versionCode and versionName with unity.
//int vesioncode = context().getPackageManager().getPackageInfo(context().getPackageName(), 0).versionCode;
public static int GetVersionCode() {
AndroidJavaClass contextCls = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject context = contextCls.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject packageMngr = context.Call<AndroidJavaObject>("getPackageManager");
string packageName = context.Call<string>("getPackageName");
AndroidJavaObject packageInfo = packageMngr.Call<AndroidJavaObject>("getPackageInfo", packageName, 0);
return packageInfo.Get<int>("versionCode");
}
@darktable
darktable / DoomGlow.cs
Created June 20, 2022 11:53 — forked from TiliSleepStealer/DoomGlow.cs
Doom glow - fake volumetric light glow effect in Unity by Tili_us
// This file is in the public domain. Where
// a public domain declaration is not recognized, you are granted
// a license to freely use, modify, and redistribute this file in
// any way you choose.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Unity remake of a fake volumetric light glow effect
@darktable
darktable / ProjectAssetPostprocessor.cs
Created April 20, 2012 03:37 — forked from hoesing/ProjectAssetPostprocessor.cs
Unity asset pre/postprocessor for applying asset defaults by path.
// Drop this script in the Editor directory in your project (creating the Editor directory if it's not there yet)
// Then re-import the assets in the directories covered by this script (right click and reimport)
//
// I would replace my path checking with the path checking from this gist:
// https://gist.github.com/1842177
//
// The texture settings for icons might want to use some of his settings combined with mine as well
using UnityEngine;
@darktable
darktable / DebugConsole.cs
Created December 1, 2011 00:25
Unity3D: Heavily modified version of Jeremy Hollingsworth's DebugConsole script.
#define DEBUG_CONSOLE
#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR
#if (UNITY_EDITOR || DEVELOPMENT_BUILD)
#define DEBUG
#endif
#if (UNITY_IOS || UNITY_ANDROID)
@darktable
darktable / ServiceLocator.cs
Created April 11, 2023 15:02
Service locator pattern with callback system derived from EventManager script found in Unity FPS Microgame.
/*****************************************************************************
MIT License
Copyright (c) 2023 Calvin Rien
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
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@darktable
darktable / EventManager.cs
Created April 11, 2023 15:04
EventManager script found in the Unity's FPS Micro Game sample. Useful for global event broadcasting.
using System;
using System.Collections.Generic;
namespace Unity.FPS.Game
{
public interface IBroadcastEvent { }
// A simple Event System that can be used for remote systems communication
public static class EventManager
{
@darktable
darktable / DrawingColor.cs
Created July 8, 2023 01:12
A static class you can use in Unity to access all the predefined colors in Microsoft's System.Drawing.Color.
using UnityEngine;
/// <summary>
/// Microsoft has a ton of predefined colors in System.Drawing.Color
/// </summary>
public static class DrawingColor
{
// only Unity color not represented (Unity's "green" is Microsoft's "Lime")
public static readonly Color Clear = Color.clear;
@darktable
darktable / GenerateSceneLoaderMenu.cs
Created July 17, 2023 13:23
Utility script to generate a menu items to load the scenes included in build settings.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.IO;
using System.Text;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
@darktable
darktable / Loggers.cs
Created July 31, 2023 01:47 — forked from thygrrr/Loggers.cs
A zero-boilerplate static logger for Unity in 25 lines of code
//SPDX-License-Identifier: Unlicense OR CC0-1.0+
using System;
using System.Collections.Generic;
using UnityEngine;
using Object = UnityEngine.Object;
// ReSharper disable MemberCanBePrivate.Global
namespace Loggers
{
/// <summary>
@darktable
darktable / SpatialHash.cs
Last active August 29, 2023 13:43
Spatial hash implementation for Unity.
// The contents of this file is free and unencumbered software released into the
// public domain. For more information, please refer to <http://unlicense.org/>
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Assertions;
public class SpatialHash<T>