Skip to content

Instantly share code, notes, and snippets.

@Xevion
Created November 24, 2020 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xevion/082cfff1c82c0267d0bea9811a487211 to your computer and use it in GitHub Desktop.
Save Xevion/082cfff1c82c0267d0bea9811a487211 to your computer and use it in GitHub Desktop.
// Decompiled with JetBrains decompiler
// Type: UnityEngine.Vector2Int
// Assembly: UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 578B5B67-7E30-45F5-8675-3155BC1864CB
// Assembly location: C:\Program Files\Unity\Hub\Editor\2019.1.1f1\Editor\Data\Managed\UnityEngine\UnityEngine.CoreModule.dll
using System;
using UnityEngine.Scripting;
namespace UnityEngine
{
[UsedByNativeCode]
public struct Vector2Int : IEquatable<Vector2Int>
{
private int m_X;
private int m_Y;
private static readonly Vector2Int s_Zero = new Vector2Int(0, 0);
private static readonly Vector2Int s_One = new Vector2Int(1, 1);
private static readonly Vector2Int s_Up = new Vector2Int(0, 1);
private static readonly Vector2Int s_Down = new Vector2Int(0, -1);
private static readonly Vector2Int s_Left = new Vector2Int(-1, 0);
private static readonly Vector2Int s_Right = new Vector2Int(1, 0);
public Vector2Int(int x, int y)
{
this.m_X = x;
this.m_Y = y;
}
public int x
{
get => this.m_X;
set => this.m_X = value;
}
public int y
{
get => this.m_Y;
set => this.m_Y = value;
}
public void Set(int x, int y)
{
this.m_X = x;
this.m_Y = y;
}
public int this[int index]
{
get
{
if (index == 0)
return this.x;
if (index == 1)
return this.y;
throw new IndexOutOfRangeException(string.Format("Invalid Vector2Int index addressed: {0}!", (object) index));
}
set
{
if (index != 0)
{
if (index != 1)
throw new IndexOutOfRangeException(string.Format("Invalid Vector2Int index addressed: {0}!", (object) index));
this.y = value;
}
else
this.x = value;
}
}
public float magnitude => Mathf.Sqrt((float) (this.x * this.x + this.y * this.y));
public int sqrMagnitude => this.x * this.x + this.y * this.y;
public static float Distance(Vector2Int a, Vector2Int b)
{
float num1 = (float) (a.x - b.x);
float num2 = (float) (a.y - b.y);
return (float) Math.Sqrt((double) num1 * (double) num1 + (double) num2 * (double) num2);
}
public static Vector2Int Min(Vector2Int lhs, Vector2Int rhs) => new Vector2Int(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y));
public static Vector2Int Max(Vector2Int lhs, Vector2Int rhs) => new Vector2Int(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y));
public static Vector2Int Scale(Vector2Int a, Vector2Int b) => new Vector2Int(a.x * b.x, a.y * b.y);
public void Scale(Vector2Int scale)
{
this.x *= scale.x;
this.y *= scale.y;
}
public void Clamp(Vector2Int min, Vector2Int max)
{
this.x = Math.Max(min.x, this.x);
this.x = Math.Min(max.x, this.x);
this.y = Math.Max(min.y, this.y);
this.y = Math.Min(max.y, this.y);
}
public static implicit operator Vector2(Vector2Int v) => new Vector2((float) v.x, (float) v.y);
public static explicit operator Vector3Int(Vector2Int v) => new Vector3Int(v.x, v.y, 0);
public static Vector2Int FloorToInt(Vector2 v) => new Vector2Int(Mathf.FloorToInt(v.x), Mathf.FloorToInt(v.y));
public static Vector2Int CeilToInt(Vector2 v) => new Vector2Int(Mathf.CeilToInt(v.x), Mathf.CeilToInt(v.y));
public static Vector2Int RoundToInt(Vector2 v) => new Vector2Int(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y));
public static Vector2Int operator +(Vector2Int a, Vector2Int b) => new Vector2Int(a.x + b.x, a.y + b.y);
public static Vector2Int operator -(Vector2Int a, Vector2Int b) => new Vector2Int(a.x - b.x, a.y - b.y);
public static Vector2Int operator *(Vector2Int a, Vector2Int b) => new Vector2Int(a.x * b.x, a.y * b.y);
public static Vector2Int operator *(Vector2Int a, int b) => new Vector2Int(a.x * b, a.y * b);
public static bool operator ==(Vector2Int lhs, Vector2Int rhs) => lhs.x == rhs.x && lhs.y == rhs.y;
public static bool operator !=(Vector2Int lhs, Vector2Int rhs) => !(lhs == rhs);
public override bool Equals(object other) => other is Vector2Int other1 && this.Equals(other1);
public bool Equals(Vector2Int other) => this.x.Equals(other.x) && this.y.Equals(other.y);
public override int GetHashCode() => this.x.GetHashCode() ^ this.y.GetHashCode() << 2;
public override string ToString() => UnityString.Format("({0}, {1})", (object) this.x, (object) this.y);
public static Vector2Int zero => Vector2Int.s_Zero;
public static Vector2Int one => Vector2Int.s_One;
public static Vector2Int up => Vector2Int.s_Up;
public static Vector2Int down => Vector2Int.s_Down;
public static Vector2Int left => Vector2Int.s_Left;
public static Vector2Int right => Vector2Int.s_Right;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment