Skip to content

Instantly share code, notes, and snippets.

import struct
import SocketServer
from base64 import b64encode
from hashlib import sha1
from mimetools import Message
from StringIO import StringIO
# import threading
class WebSocketsHandler(SocketServer.StreamRequestHandler):
@darktable
darktable / Helper.cs
Created June 8, 2019 15:48
A utility script to find every component of a particular type in a scene. Not sure what the results will be if you have multiple additive scenes loaded.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Helper : MonoBehaviour
{
public static List<T> FindThemAll<T>(bool includeInactive = false) where T : UnityEngine.Component
{
var scene = SceneManager.GetActiveScene();
using UnityEngine;
using UnityEditor;
[CustomPropertyDrawer(typeof(Sprite))]
public class SpritePropertyDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent labelN)
{
if (property.objectReferenceValue != null)
{
using System;
using System.IO;
using System.Runtime.CompilerServices;
using UnityEditor;
using UnityEngine;
using UnityEngine.Events;
/// <summary>
/// Hierarchy Window Group Header
/// http://diegogiacomelli.com.br/unitytips-changing-the-style-of-the-hierarchy-window-group-header/
@darktable
darktable / MaterialGradientDrawer.cs
Created October 20, 2021 17:44 — forked from totallyRonja/MaterialGradientDrawer.cs
A Material Property Drawer for the [Gradient] attribute which lets you edit gradients and adds them to the shader as textures. More information here: https://twitter.com/totallyRonja/status/1368704187580682240
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
public class MaterialGradientDrawer : MaterialPropertyDrawer {
private int resolution;
@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 / 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;