Skip to content

Instantly share code, notes, and snippets.

@Arakade
Arakade / PhysXCCDEditorHelper.cs
Created December 22, 2018 14:29
Unity3D 2018.3 Editor script to find PhysX CCD problems
////////////////////////////////////////
// Find PhysX components that will trigger the Unity 2018 complaint about
// kinematic with Continuous Collision Detection:
//
// ERROR: [Physics.PhysX] RigidBody::setRigidBodyFlag: kinematic bodies with CCD enabled are not supported! CCD will be ignored.
//
// Use the script to find troublesome components in the scene or in the project
// then manually change them to a valid value, likely ContinuousSpeculative
//
// See https://docs.unity3d.com/ScriptReference/CollisionDetectionMode.ContinuousSpeculative.html
@Arakade
Arakade / MyInternalClass.cs
Created October 22, 2018 21:07
Friend assembly allows access to internals from different assembly! (for Unity Editors or unit tests and when using assembly definition files = .asmdefs)
/*
* File "MyInternalClass.cs"
* in "MyName" assembly (defined by a "MyName.asmdef"):
*/
using System.Runtime.CompilerServices;
// Make this class available to its Unity PropertyDrawer despite being 'internal'
[assembly: InternalsVisibleTo("MyName_Editor")]
namespace my.name {
@Arakade
Arakade / SkyBoxRotation.cs
Last active March 22, 2018 22:24
Unity3D script to rotate the skybox
using System.Collections;
using UnityEngine;
namespace UGS.environ {
/// <summary>
/// Rotates the skybox of the scene or camera.
/// Requires a special shader.
/// </summary>
internal sealed class SkyBoxRotation : MonoBehaviour {
@Arakade
Arakade / rayCastConditional.py
Last active January 4, 2023 09:03
Blender Python (bpy) code to iterate raycast until a predicate passes
import bpy
import bmesh
import mathutils
from math import radians, degrees
from mathutils.bvhtree import BVHTree
def rayCastConditional(ray, rayTarget, increment, predicate):
"""Cast multiple rays until 'predicate' passes.
ray: (p, direction)
rayTarget: something with ray_cast() such as:
@Arakade
Arakade / ScreenCaptureUtil.cs
Last active January 24, 2018 13:00
Utility to capture screenshots at crazily large sizes required by printers for floor standing banners, etc prior to 2017.03.0p1
using System;
using UnityEngine;
namespace UGS {
/// <summary>
/// See <seealso cref="http://docs.unity3d.com/ScriptReference/Application.CaptureScreenshot.html"/>.
/// N.b. docs now say "Removed in version 2017.3.0p1"
/// Now API call includes super-size facility https://docs.unity3d.com/ScriptReference/ScreenCapture.CaptureScreenshot.html
/// </summary>
@Arakade
Arakade / NonNullAttribute.cs
Last active January 24, 2018 12:28
Unity3D NonNull attribute + colouring PropertyDrawer
using UnityEngine;
namespace UGS.unityutil.attributes {
/// <summary>
/// Checks non-null (and non-empty if applied to a string, non-zero if a scalar or Vector, etc) in a custom inspector.
/// Colours red if any problems.
/// </summary>
public sealed class NonNullAttribute : PropertyAttribute {
}
@Arakade
Arakade / dropbox-restore.py
Created November 9, 2017 11:18
Tweaked version of https://github.com/clark800/dropbox-restore with updated DropBox API, list revision error fix included and option to disable recursion (enabled here) (for Python 2). Good as of 2017/11/08
#!/usr/bin/env python
import sys, os, dropbox, time
from datetime import datetime
APP_KEY = 'API_KEY' # INSERT APP_KEY HERE
APP_SECRET = 'APP_SECRET' # INSERT APP_SECRET HERE
DELAY = 0.2 # delay between each file (try to stay under API rate limits)
HELP_MESSAGE = \
"""Note: You must specify the path starting with "/", where "/" is the root
@Arakade
Arakade / Example output
Created April 22, 2017 18:32
BASH script to port a Git commit from one Git repo to another unrelated Git repo (can run with BASH on Windows)
$ GitPortPatch.sh 22b7f80c22ac1861e945ddf30e30671c46b53d6e
Getting commit message
Getting patch
Getting affected filenames
Getting current status of those files...
Checking them...
Ensuring affected files are ready for patching...
Preparing Assets/TerraVolPack/TerraVol/Scripts/Data/MeshData.cs
Preparing Assets/TerraVolPack/TerraVol/Scripts/Map/Chunk.cs
Apply patch? y/n : y
@Arakade
Arakade / SizeTesting.cs
Last active March 31, 2017 21:11
Unity3D / C# coder? Can you guess the answers? What's your score?
using System;
using UnityEngine;
namespace UGS {
class SizeTesting : MonoBehaviour {
private const string msgFmt = "{0}:\t\t{1:0.000} bytes";
public void Awake() {
v<byte>();
v<int>();
@Arakade
Arakade / SaveWithJsonDotNet.cs
Created March 19, 2017 15:57
Save something with JsonDotNet (Json.Net) using Serializable attribute
static void save(string filePath) {
// ...
using (TextWriter writer = File.CreateText(filePath)) {var serializer = getSerializer(errors);
var errors = new List<string>();
var serializer = getSerializer(errors);
serializer.Serialize(writer, snapshot);
logErrors(errors);
}
// ...