Skip to content

Instantly share code, notes, and snippets.

View LongChau's full-sized avatar
😣
Let's do it

Long Châu LongChau

😣
Let's do it
  • VNG
  • Vietnam
  • 17:20 (UTC +07:00)
View GitHub Profile
@Froghut
Froghut / OdinWatchWindow.cs
Last active August 4, 2024 10:25
Odin Watch Window
#if ODIN_INSPECTOR
using System;
using System.Collections.Generic;
using System.Linq;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
@lordlycastle
lordlycastle / DataSerializer.cs
Last active May 9, 2024 22:21
Inspector window that can serialize an object to disk and load it back up. Can use various methods e.g. binary, JSON, nodes. Good for saving data to disk for later use.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Sirenix.OdinInspector;
@lordlycastle
lordlycastle / BaseSingleton.cs
Last active May 7, 2024 14:41
Abstract singleton class for Unity.
using System.Linq;
using UnityEngine;
/// <summary>
/// Abstract singleton class for Unity. Updated with possible errors:
/// - Doesn't create a new singleton if it is in scene.
/// - Singleton has an initialize method which is called on creation, finding one from scene, or awake. Which makes sure initialization always happen before using it.
/// - It doesn't create a new single if you try to access it OnDestroy (e.g. game quit). Returns null instead.
/// </summary>
/// <typeparam name="TSingleton">Type of singleton. (Same as class inheriting from it.)</typeparam>
@lordlycastle
lordlycastle / JsonSerializationTester.cs
Last active February 2, 2024 17:36
Inspector window that can be used to test/see JSON deserialization. Requires [Odin](https://odininspector.com/). Get JSON Formatter from here: https://gist.github.com/lordlycastle/755a9d4e34600bc881fe70d3201e516e
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;
@immrsv
immrsv / StateMachineEventReceiver.cs
Last active August 30, 2019 08:25
Unity Animator as a scene controller
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Sirenix.OdinInspector;
// Add this to the object that holds the Animator
public class StateMachineEventReceiver : MonoBehaviour
{
[System.Serializable]
@ditzel
ditzel / Math3D.cs
Last active June 20, 2023 08:30
Unity Math
static class Math3D
{
private static System.Random rand = new System.Random();
public static float DistanceToLine(Ray ray, Vector3 point)
{
//see:http://answers.unity3d.com/questions/62644/distance-between-a-ray-and-a-point.html
return Vector3.Cross(ray.direction, point - ray.origin).magnitude;
}
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
[ExecuteInEditMode]
public class HandManager : MonoBehaviour
{
/// <summary>
/// The area of a card that should be used to determine whether to select the previous, current, or next card
using UnityEngine;
public class DistanceJoint3D : MonoBehaviour {
public Transform ConnectedRigidbody;
public bool DetermineDistanceOnStart = true;
public float Distance;
public float Spring = 0.1f;
public float Damper = 5f;
@ditzel
ditzel / MathParabola.cs
Last active November 8, 2024 13:48
A simple Math class to calculate a point in 2D or 3D space lying on a parabola. And a more complex parabola controller that you can put on an object.
using UnityEngine;
using System;
public class MathParabola
{
public static Vector3 Parabola(Vector3 start, Vector3 end, float height, float t)
{
Func<float, float> f = x => -4 * height * x * x + 4 * height * x;
@kormyen
kormyen / GyroCamera.cs
Last active September 22, 2023 13:37
Unity3D script for rotating camera with a phone's gyro. Includes smoothing and initial offset. Edited from https://forum.unity3d.com/threads/sharing-gyroscope-camera-script-ios-tested.241825/
using UnityEngine;
using System.Collections;
public class GyroCamera : MonoBehaviour
{
// STATE
private float _initialYAngle = 0f;
private float _appliedGyroYAngle = 0f;
private float _calibrationYAngle = 0f;
private Transform _rawGyroRotation;