150 lines
9.8 KiB
C#
150 lines
9.8 KiB
C#
// AUTHORED SHIM (not copied). Minimal no-op UnityEngine value-type surface. Grows via
|
|
// the M1 compile loop -- members added are exactly those the copied engine references
|
|
// (geometry/math used inside never-run VFX/layout code; IsForecast suppresses playback,
|
|
// so numeric results here never feed authoritative game state).
|
|
using System;
|
|
|
|
namespace UnityEngine
|
|
{
|
|
public struct Vector2
|
|
{
|
|
public float x, y;
|
|
public Vector2(float x, float y) { this.x = x; this.y = y; }
|
|
public static Vector2 zero => new Vector2(0, 0);
|
|
public static Vector2 one => new Vector2(1, 1);
|
|
public static Vector2 up => new Vector2(0, 1);
|
|
public static Vector2 right => new Vector2(1, 0);
|
|
public float magnitude => (float)Math.Sqrt(x * x + y * y);
|
|
public float sqrMagnitude => x * x + y * y;
|
|
public Vector2 normalized { get { float m = magnitude; return m > 1e-6f ? new Vector2(x / m, y / m) : zero; } }
|
|
public static float Distance(Vector2 a, Vector2 b) => (a - b).magnitude;
|
|
public static float Angle(Vector2 from, Vector2 to) => 0f;
|
|
public void Normalize() { var n = normalized; x = n.x; y = n.y; }
|
|
public static Vector2 operator +(Vector2 a, Vector2 b) => new Vector2(a.x + b.x, a.y + b.y);
|
|
public static Vector2 operator -(Vector2 a, Vector2 b) => new Vector2(a.x - b.x, a.y - b.y);
|
|
public static Vector2 operator -(Vector2 a) => new Vector2(-a.x, -a.y);
|
|
public static Vector2 operator *(Vector2 a, float s) => new Vector2(a.x * s, a.y * s);
|
|
public static Vector2 operator *(float s, Vector2 a) => new Vector2(a.x * s, a.y * s);
|
|
public static Vector2 operator /(Vector2 a, float s) => new Vector2(a.x / s, a.y / s);
|
|
public static Vector2 operator *(Vector2 a, Vector2 b) => new Vector2(a.x * b.x, a.y * b.y);
|
|
public static bool operator ==(Vector2 a, Vector2 b) => a.x == b.x && a.y == b.y;
|
|
public static bool operator !=(Vector2 a, Vector2 b) => !(a == b);
|
|
public override bool Equals(object o) => o is Vector2 v && this == v;
|
|
public override int GetHashCode() => x.GetHashCode() ^ (y.GetHashCode() << 2);
|
|
public static implicit operator Vector2(Vector3 v) => new Vector2(v.x, v.y);
|
|
public static implicit operator Vector3(Vector2 v) => new Vector3(v.x, v.y, 0);
|
|
}
|
|
|
|
public struct Vector3
|
|
{
|
|
public float x, y, z;
|
|
public Vector3(float x, float y, float z) { this.x = x; this.y = y; this.z = z; }
|
|
public Vector3(float x, float y) { this.x = x; this.y = y; this.z = 0; }
|
|
public static Vector3 zero => new Vector3(0, 0, 0);
|
|
public static Vector3 one => new Vector3(1, 1, 1);
|
|
public static Vector3 up => new Vector3(0, 1, 0);
|
|
public static Vector3 down => new Vector3(0, -1, 0);
|
|
public static Vector3 left => new Vector3(-1, 0, 0);
|
|
public static Vector3 right => new Vector3(1, 0, 0);
|
|
public static Vector3 forward => new Vector3(0, 0, 1);
|
|
public static Vector3 back => new Vector3(0, 0, -1);
|
|
public float magnitude => (float)Math.Sqrt(x * x + y * y + z * z);
|
|
public float sqrMagnitude => x * x + y * y + z * z;
|
|
public Vector3 normalized { get { float m = magnitude; return m > 1e-6f ? new Vector3(x / m, y / m, z / m) : zero; } }
|
|
public static float Distance(Vector3 a, Vector3 b) => (a - b).magnitude;
|
|
public static float SqrMagnitude(Vector3 a) => a.sqrMagnitude;
|
|
public static float Dot(Vector3 a, Vector3 b) => a.x * b.x + a.y * b.y + a.z * b.z;
|
|
public static Vector3 Scale(Vector3 a, Vector3 b) => new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
|
|
public static Vector3 Lerp(Vector3 a, Vector3 b, float t) => new Vector3(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t);
|
|
public static Vector3 operator +(Vector3 a, Vector3 b) => new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
|
|
public static Vector3 operator -(Vector3 a, Vector3 b) => new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
public static Vector3 operator -(Vector3 a) => new Vector3(-a.x, -a.y, -a.z);
|
|
public static Vector3 operator *(Vector3 a, float s) => new Vector3(a.x * s, a.y * s, a.z * s);
|
|
public static Vector3 operator *(float s, Vector3 a) => new Vector3(a.x * s, a.y * s, a.z * s);
|
|
public static Vector3 operator /(Vector3 a, float s) => new Vector3(a.x / s, a.y / s, a.z / s);
|
|
public static bool operator ==(Vector3 a, Vector3 b) => a.x == b.x && a.y == b.y && a.z == b.z;
|
|
public static bool operator !=(Vector3 a, Vector3 b) => !(a == b);
|
|
public override bool Equals(object o) => o is Vector3 v && this == v;
|
|
public override int GetHashCode() => x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
|
|
}
|
|
|
|
public struct Quaternion
|
|
{
|
|
public float x, y, z, w;
|
|
public Quaternion(float x, float y, float z, float w) { this.x = x; this.y = y; this.z = z; this.w = w; }
|
|
public static Quaternion identity => new Quaternion(0, 0, 0, 1);
|
|
public static Quaternion Euler(float x, float y, float z) => identity;
|
|
public static Quaternion Euler(Vector3 e) => identity;
|
|
public static Quaternion AngleAxis(float angle, Vector3 axis) => identity;
|
|
public static Quaternion Slerp(Quaternion a, Quaternion b, float t) => identity;
|
|
public Vector3 eulerAngles { get => Vector3.zero; set { } }
|
|
public static Vector3 operator *(Quaternion q, Vector3 v) => v;
|
|
public static Quaternion operator *(Quaternion a, Quaternion b) => identity;
|
|
}
|
|
|
|
public struct Color
|
|
{
|
|
public float r, g, b, a;
|
|
public Color(float r, float g, float b, float a) { this.r = r; this.g = g; this.b = b; this.a = a; }
|
|
public Color(float r, float g, float b) { this.r = r; this.g = g; this.b = b; this.a = 1f; }
|
|
public static Color white => new Color(1, 1, 1, 1);
|
|
public static Color black => new Color(0, 0, 0, 1);
|
|
public static Color clear => new Color(0, 0, 0, 0);
|
|
public static Color red => new Color(1, 0, 0, 1);
|
|
public static Color cyan => new Color(0, 1, 1, 1);
|
|
public static Color gray => new Color(0.5f, 0.5f, 0.5f, 1);
|
|
public static Color grey => gray;
|
|
public static Color Lerp(Color a, Color b, float t) => new Color(a.r + (b.r - a.r) * t, a.g + (b.g - a.g) * t, a.b + (b.b - a.b) * t, a.a + (b.a - a.a) * t);
|
|
public static Color operator *(Color c, float s) => new Color(c.r * s, c.g * s, c.b * s, c.a * s);
|
|
public static Color operator *(Color a, Color b) => new Color(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
|
|
public static Color operator +(Color a, Color b) => new Color(a.r + b.r, a.g + b.g, a.b + b.b, a.a + b.a);
|
|
public static implicit operator Color(Color32 c) => new Color(c.r / 255f, c.g / 255f, c.b / 255f, c.a / 255f);
|
|
public static implicit operator Color32(Color c) => new Color32(
|
|
(byte)(Mathf.Clamp01(c.r) * 255f), (byte)(Mathf.Clamp01(c.g) * 255f),
|
|
(byte)(Mathf.Clamp01(c.b) * 255f), (byte)(Mathf.Clamp01(c.a) * 255f));
|
|
public static bool operator ==(Color a, Color b) => a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a;
|
|
public static bool operator !=(Color a, Color b) => !(a == b);
|
|
public override bool Equals(object o) => o is Color c && this == c;
|
|
public override int GetHashCode() => r.GetHashCode() ^ (g.GetHashCode() << 2) ^ (b.GetHashCode() << 4) ^ (a.GetHashCode() << 6);
|
|
}
|
|
|
|
public static class Mathf
|
|
{
|
|
public static float Floor(float f) => (float)Math.Floor(f);
|
|
public static int FloorToInt(float f) => (int)Math.Floor(f);
|
|
public static float Ceil(float f) => (float)Math.Ceiling(f);
|
|
public static float Round(float f) => (float)Math.Round(f);
|
|
public static int RoundToInt(float f) => (int)Math.Round(f);
|
|
public static float Abs(float f) => Math.Abs(f);
|
|
public static int Abs(int f) => Math.Abs(f);
|
|
public static float Max(float a, float b) => Math.Max(a, b);
|
|
public static int Max(int a, int b) => Math.Max(a, b);
|
|
public static float Max(params float[] values) { float m = float.NegativeInfinity; foreach (var v in values) m = Math.Max(m, v); return m; }
|
|
public static int Max(params int[] values) { int m = int.MinValue; foreach (var v in values) m = Math.Max(m, v); return m; }
|
|
public static float Min(float a, float b) => Math.Min(a, b);
|
|
public static int Min(int a, int b) => Math.Min(a, b);
|
|
public static int Min(params int[] values) { int m = int.MaxValue; foreach (var v in values) m = Math.Min(m, v); return m; }
|
|
public static float Clamp(float v, float lo, float hi) => Math.Max(lo, Math.Min(hi, v));
|
|
public static int Clamp(int v, int lo, int hi) => Math.Max(lo, Math.Min(hi, v));
|
|
public static float Clamp01(float v) => Math.Max(0f, Math.Min(1f, v));
|
|
public static float Lerp(float a, float b, float t) => a + (b - a) * Clamp01(t);
|
|
public static float SmoothDamp(float cur, float target, ref float vel, float time) { vel = 0; return target; }
|
|
public static float Sin(float f) => (float)Math.Sin(f);
|
|
public static float Cos(float f) => (float)Math.Cos(f);
|
|
public static float Asin(float f) => (float)Math.Asin(f);
|
|
public static float Atan2(float y, float x) => (float)Math.Atan2(y, x);
|
|
public static float Sqrt(float f) => (float)Math.Sqrt(f);
|
|
public static float Pow(float f, float p) => (float)Math.Pow(f, p);
|
|
public static float Log(float f) => (float)Math.Log(f);
|
|
public static float Sign(float f) => Math.Sign(f);
|
|
public static bool Approximately(float a, float b) => Math.Abs(a - b) < 1e-6f;
|
|
public static float GammaToLinearSpace(float v) => v;
|
|
}
|
|
|
|
public static class Debug
|
|
{
|
|
public static void LogWarning(object m) { }
|
|
public static void LogError(object m) { }
|
|
}
|
|
}
|