Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / SteamSpyUtil.gs
Created May 7, 2019 12:30
Google Scripts bound spreadsheet script to get data from Steam Spy and place in sheet
function getSteamSpyAppDetails() {
// Get the appId from spreadsheet for now:
var sheet = SpreadsheetApp.getActiveSheet();
var appId = sheet.getDataRange().getCell(1, 1).getValue();
// Build query
var url = 'https://steamspy.com/api.php'
+ '?request=appdetails&appid=' + encodeURIComponent(appId);
Logger.log("Sending: \"%s\"", url);
@Arakade
Arakade / StickCauseMB.cs
Created June 5, 2019 13:55
ECS/DOTS Unity.Physics preview-0.1.0 collision system that creates joints on collisions when a StickCause is present.
using Unity.Burst;
using Unity.Entities;
using Unity.Physics.Authoring;
using UnityEngine;
using UnityEngine.Assertions;
namespace UGS {
/// <summary>
/// Tag component for causing things to stick.
/// Could I also do this with a Physics.Material "Custom Flags" or "Collision Filter" ?
@Arakade
Arakade / ECS-Unity.Physics.dot
Created June 7, 2019 20:00
GraphViz file for Unity3D ECS including new Unity.Physics and showing spaces for its various callback groups.
# GraphViz file for Unity3D ECS including new Unity.Physics and showing spaces for its various callback groups.
# Render with:
# dot -Tpng ECS-Unity.Physics.dot -o ECS-Unity.Physics.png
#
# License: CC-SA (BY appreciated but not required)
# Original version: @Arakade Rupert Key, 2019/06/07
digraph "Unity.Physics" {
label="ECS + Unity.Physics jobs and phases"
compound=true
@Arakade
Arakade / CinemachineDebugger.cs
Created July 19, 2019 12:04
Little debug script for helping investigate Cinemachine blend issues
using System.Text;
using Cinemachine;
using UGS.unityutils.attributes;
using UnityEngine;
namespace UGS.snwscf.camera {
public sealed class CameraDebugger : MonoBehaviour {
#region serialized
[SerializeField, NonNull]
@Arakade
Arakade / CustomJsonSerializationTest.cs
Created March 5, 2020 11:09
Custom JSON.Net Dictionary serialization for when value object contains the key the dictionary uses to map to it.
// See https://unreasonablygoodsoftware.wordpress.com/2020/03/05/json-net-custom-dictionary-serialization/
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using Newtonsoft.Json;
using NUnit.Framework;
using UnityEngine.Scripting;
namespace packageNameRemoved {
@Arakade
Arakade / SleepHelper.cs
Created April 23, 2020 13:03
Log and provide a UnityEvent for when `Rigidbody.IsSleeping` changes.
#if UNITY_EDITOR
using UnityEditor;
#endif
using System;
using UnityEngine;
using UnityEngine.Assertions;
using UnityEngine.Events;
namespace UGS.unityutils {