This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class QuaternionExt { | |
const float Tolerance = 1e-10f; | |
public static readonly Quaternion zero = new Quaternion(0f, 0f, 0f, 0f); | |
public static Quaternion FromToRotation(Vector3 from, Vector3 to) { | |
float theta = Vector3.Dot(from.normalized, to.normalized); | |
if (theta >= 1f) | |
return Quaternion.identity; | |
if (theta <= -1f) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[System.Serializable] | |
public struct AffineTransform | |
{ | |
public Vector3 translation; | |
public Quaternion rotation; | |
public AffineTransform(Vector3 t, Quaternion r) | |
{ | |
translation = t; | |
rotation = r; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Sensor : MonoBehaviour | |
{ | |
public CapsuleCollider Collider; | |
public LayerMask Mask ; | |
void OnValidate() | |
{ | |
Asr.IsTrue(Mask.value != 0); | |
Asr.IsTrue(Collider); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ExecuteAlways] | |
public class Avoidance : MonoBehaviour | |
{ | |
public float avoidanceFactor = 1f; | |
public float sensorLength = 20; | |
public float sensorThickness = 2; | |
public float sensorOffset = 5; | |
public float horizontalAngle = 23; | |
public float upAngle = 23; | |
public float downAngle = 23; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static Transform FindInChildren(this Transform self, string name) | |
{ | |
int count = self.childCount; | |
for (int i = 0; i < count; i++) | |
{ | |
Transform child = self.GetChild(i); | |
if (child.name == name) return child; | |
Transform subChild = child.FindInChildren(name); | |
if (subChild != null) return subChild; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_EDITOR | |
using UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using System; | |
using System.IO; | |
using System.Text; | |
public class LayerGenerator : EditorWindow { | |
[MenuItem("Edit/Rebuild LAYERS.cs %&L")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SpeedOMeter { | |
public AverageVector3 AngularVelocity; | |
public AverageVector3 Velocity; | |
Quaternion _lastRotation; | |
Vector3 _lastPos; | |
Transform _t; | |
public SpeedOMeter(Transform t) { | |
_t = t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Pool<T> : IDisposable where T : class { | |
static Action<T> Empty { get; } = _ => { }; | |
Func<T> _ctor; | |
readonly Stack<T> _stack; | |
// todo place asserts on app quit | |
Action<T> _reset; | |
Action<T> _destroy; | |
public Pool(Func<T> ctor, Action<T> reset, Action<T> destroy = null) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class PoseUtils { | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static Pose GetPose(this Transform transform) { | |
return new Pose() {position = transform.position, rotation = transform.rotation}; | |
} | |
[MethodImpl(MethodImplOptions.AggressiveInlining)] | |
public static void SetPose(this Transform transform, Pose pose) { | |
transform.position = pose.position; | |
transform.rotation = pose.rotation; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShotView : MonoBehaviour { | |
public Transform HoleRoot; | |
public Renderer SubtractRenderer; | |
public AnimationCurve ScaleXY; | |
public AnimationCurve ScaleZ; | |
public float TimeLen = 0.3f; | |
public void Render(CompShotData data) { | |
var linear = data.Progress; | |
var xy = ScaleXY.Evaluate(linear); |
OlderNewer