Skip to content

Instantly share code, notes, and snippets.

@yCatDev
yCatDev / ScriptableObjectProtector.cs
Last active September 13, 2023 07:59
Simple editor workaround for ScriptableObjects that fix saving changes after play mode.
#if UNITY_EDITOR
using System.Collections.Generic;
using ClickerFramework.Abstract;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public static class ScriptableObjectProtector
{
private static bool _playing = false;
@FlaShG
FlaShG / CanvasPositioningExtensions.cs
Last active May 8, 2024 09:33
A small Unity helper class to convert viewport, screen or world positions to canvas space.
using UnityEngine;
/// <summary>
/// Small helper class to convert viewport, screen or world positions to canvas space.
/// Only works with screen space canvases.
/// </summary>
/// <example>
/// <code>
/// objectOnCanvasRectTransform.anchoredPosition = specificCanvas.WorldToCanvasPoint(worldspaceTransform.position);
/// </code>
@mstevenson
mstevenson / ConfigurableJointExtensions.cs
Last active April 30, 2024 08:05
Unity extension methods for computing a ConfigurableJoint.TargetRotation value from a given local or world rotation.
using UnityEngine;
public static class ConfigurableJointExtensions {
/// <summary>
/// Sets a joint's targetRotation to match a given local rotation.
/// The joint transform's local rotation must be cached on Start and passed into this method.
/// </summary>
public static void SetTargetRotationLocal (this ConfigurableJoint joint, Quaternion targetLocalRotation, Quaternion startLocalRotation)
{
if (joint.configuredInWorldSpace) {