Fix Unity warnings

This commit is contained in:
Pascal Serrarens 2026-01-05 11:26:13 +01:00
parent 3611de5142
commit d102fc7b80
4 changed files with 52 additions and 48 deletions

View File

@ -325,26 +325,12 @@ namespace LinearAlgebra {
return new Vector2Float(v1.horizontal * v2.horizontal, v1.vertical * v2.vertical); return new Vector2Float(v1.horizontal * v2.horizontal, v1.vertical * v2.vertical);
} }
/*
/// <summary> /// <summary>
/// Tests if the vector has equal values as the given vector /// Tests if the vector has equal values as the given vector
/// </summary> /// </summary>
/// <param name="v1">The vector to compare to</param> /// <param name="v1">The vector to compare to</param>
/// <returns><em>true</em> if the vector values are equal</returns> /// <returns><em>true</em> if the vector values are equal</returns>
public bool Equals(Vector2Float v1) => horizontal == v1.horizontal && vertical == v1.vertical; //public readonly bool Equals(Vector2Float v1) => horizontal == v1.horizontal && vertical == v1.vertical;
/// <summary>
/// Tests if the vector is equal to the given object
/// </summary>
/// <param name="obj">The object to compare to</param>
/// <returns><em>false</em> when the object is not a Vector2 or does not have equal values</returns>
public override bool Equals(object obj) {
if (!(obj is Vector2Float v))
return false;
return (horizontal == v.horizontal && vertical == v.vertical);
}
*/
/// <summary> /// <summary>
/// Tests if the two vectors have equal values /// Tests if the two vectors have equal values
@ -372,15 +358,25 @@ namespace LinearAlgebra {
return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical); return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical);
} }
/* /// <summary>
/// Tests if the vector is equal to the given object
/// </summary>
/// <param name="obj">The object to compare to</param>
/// <returns><em>false</em> when the object is not a Vector2 or does not have equal values</returns>
public override readonly bool Equals(object obj) {
if (obj is not Vector2Float v)
return false;
return (horizontal == v.horizontal && vertical == v.vertical);
}
/// <summary> /// <summary>
/// Get an hash code for the vector /// Get an hash code for the vector
/// </summary> /// </summary>
/// <returns>The hash code</returns> /// <returns>The hash code</returns>
public override int GetHashCode() { public override readonly int GetHashCode() {
return (horizontal, vertical).GetHashCode(); return HashCode.Combine(horizontal, vertical);
} }
*/
/// <summary> /// <summary>
/// Get the distance between two vectors /// Get the distance between two vectors

View File

@ -60,17 +60,6 @@ namespace LinearAlgebra {
/// <returns><em>true</em> if the vector values are equal</returns> /// <returns><em>true</em> if the vector values are equal</returns>
public readonly bool Equals(Vector2Int v) => this.horizontal == v.horizontal && vertical == v.vertical; public readonly bool Equals(Vector2Int v) => this.horizontal == v.horizontal && vertical == v.vertical;
/// <summary>
/// Tests if the vector is equal to the given object
/// </summary>
/// <param name="obj">The object to compare to</param>
/// <returns><em>false</em> when the object is not a Vector2 or does not have equal values</returns>
public override readonly bool Equals(object obj) {
if (obj is not Vector2Int v)
return false;
return (this.horizontal == v.horizontal && this.vertical == v.vertical);
}
*/ */
/// <summary> /// <summary>
@ -98,6 +87,26 @@ namespace LinearAlgebra {
return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical); return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical);
} }
/// <summary>
/// Tests if the vector is equal to the given object
/// </summary>
/// <param name="obj">The object to compare to</param>
/// <returns><em>false</em> when the object is not a Vector2 or does not have equal values</returns>
public override readonly bool Equals(object obj) {
if (obj is not Vector2Int v)
return false;
return (this.horizontal == v.horizontal && this.vertical == v.vertical);
}
/// <summary>
/// Get an hash code for the vector
/// </summary>
/// <returns>The hash code</returns>
public override readonly int GetHashCode() {
return HashCode.Combine(horizontal, vertical);
}
public readonly float sqrMagnitude => this.horizontal * this.horizontal + this.vertical * this.vertical; public readonly float sqrMagnitude => this.horizontal * this.horizontal + this.vertical * this.vertical;
public static float SqrMagnitudeOf(Vector2Int v) { public static float SqrMagnitudeOf(Vector2Int v) {

View File

@ -250,30 +250,22 @@ namespace LinearAlgebra {
public static Vector3Float operator *(Vector3Float v1, float d) { public static Vector3Float operator *(Vector3Float v1, float d) {
Vector3Float v = new Vector3Float(v1.horizontal * d, v1.vertical * d, v1.depth * d); Vector3Float v = new(v1.horizontal * d, v1.vertical * d, v1.depth * d);
return v; return v;
} }
public static Vector3Float operator *(float d, Vector3Float v1) { public static Vector3Float operator *(float d, Vector3Float v1) {
Vector3Float v = new Vector3Float(d * v1.horizontal, d * v1.vertical, d * v1.depth); Vector3Float v = new(d * v1.horizontal, d * v1.vertical, d * v1.depth);
return v; return v;
} }
public static Vector3Float operator /(Vector3Float v1, float d) { public static Vector3Float operator /(Vector3Float v1, float d) {
Vector3Float v = new Vector3Float(v1.horizontal / d, v1.vertical / d, v1.depth / d); Vector3Float v = new(v1.horizontal / d, v1.vertical / d, v1.depth / d);
return v; return v;
} }
/*
public bool Equals(Vector3Float v) => (horizontal == v.horizontal && vertical == v.vertical && depth == v.depth);
public override bool Equals(object obj) { //public bool Equals(Vector3Float v) => (horizontal == v.horizontal && vertical == v.vertical && depth == v.depth);
if (!(obj is Vector3Float v))
return false;
return (horizontal == v.horizontal && vertical == v.vertical && depth == v.depth);
}
*/
public static bool operator ==(Vector3Float v1, Vector3Float v2) { public static bool operator ==(Vector3Float v1, Vector3Float v2) {
return (v1.horizontal == v2.horizontal && v1.vertical == v2.vertical && v1.depth == v2.depth); return (v1.horizontal == v2.horizontal && v1.vertical == v2.vertical && v1.depth == v2.depth);
@ -283,9 +275,16 @@ namespace LinearAlgebra {
return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical || v1.depth != v2.depth); return (v1.horizontal != v2.horizontal || v1.vertical != v2.vertical || v1.depth != v2.depth);
} }
// public override int GetHashCode() { public override readonly bool Equals(object obj) {
// return (horizontal, vertical, depth).GetHashCode(); if (obj is not Vector3Float v)
// } return false;
return (horizontal == v.horizontal && vertical == v.vertical && depth == v.depth);
}
public override readonly int GetHashCode() {
return HashCode.Combine(horizontal, vertical, depth);
}
/// @brief The distance between two vectors /// @brief The distance between two vectors
/// @param v1 The first vector /// @param v1 The first vector

View File

@ -501,7 +501,7 @@ public static class OpenAssetHandler {
// Called when an asset is double-clicked or opened. // Called when an asset is double-clicked or opened.
[OnOpenAsset] [OnOpenAsset]
public static bool OpenMyScriptableObject(int instanceID, int line) { public static bool OpenMyScriptableObject(int instanceID, int line) {
NanoBrainObj obj = EditorUtility.InstanceIDToObject(instanceID) as NanoBrainObj; NanoBrainObj obj = EditorUtility.EntityIdToObject(instanceID) as NanoBrainObj;
if (obj != null) { if (obj != null) {
NanoBrainEditor.Open(obj); NanoBrainEditor.Open(obj);
return true; // handled return true; // handled