public static float CalculatePathCost(Vector3 sourcePosition, Vector3 targetPosition, int areaMask) { sourcePosition = sourcePosition.Round(_fastCalculatePathGridSize); targetPosition = targetPosition.Round(_fastCalculatePathGridSize); var key = new Tuple3 <Vector3, Vector3, int>(sourcePosition, targetPosition, areaMask); if (_fastCalculatePathCache.ContainsKey(key)) { return(_fastCalculatePathCache[key]); } NavMeshPath path = new NavMeshPath(); float cost; if (NavMesh.CalculatePath(sourcePosition, targetPosition, areaMask, path)) { if (path.status == NavMeshPathStatus.PathComplete) { cost = path.Cost(); } else { cost = float.MaxValue; } } else { cost = float.MaxValue; } _fastCalculatePathCache[key] = cost; return(cost); }
public void TupleTest1() { var t1 = new Tuple3 <Vector3, Vector3, float>(new Vector3(1, 2, 3), new Vector3(1, 2, 3), .5f); var t2 = new Tuple3 <Vector3, Vector3, float>(new Vector3(1, 2, 3), new Vector3(1, 2, 3), .5f); var t3 = new Tuple3 <Vector3, Vector3, float>(new Vector3(1f, 2, 3), new Vector3(1, 2, 3), .5f); var t4 = new Tuple3 <Vector3, Vector3, float>(new Vector3(2f, 2, 3), new Vector3(1, 2, 3), .5f); Assert.AreEqual(t1, t2); Assert.AreEqual(t1.GetHashCode(), t2.GetHashCode()); Assert.AreEqual(t1.GetHashCode(), t3.GetHashCode()); Assert.AreNotEqual(t1.GetHashCode(), t4.GetHashCode()); Assert.AreNotEqual(t1, t4); }
public bool Equals(Tuple3 <T1, T2, T3> other) { return(Equals(items, other.items)); }