Skip to content

Instantly share code, notes, and snippets.

@yCatDev
yCatDev / ScriptableObjectProtector.cs
Last active September 18, 2024 06:22
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 July 12, 2024 20:51
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 September 9, 2024 17:33
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) {