static public Moba_Camera_Boundary GetClosestBoundary(Vector3 point) { // Contains the info for the closest boundary Moba_Camera_Boundary closestBoundary = null; float closestDistance = 999999.0f; // if pivot is outside the boundries find the closest cube foreach (Moba_Camera_Boundary boundary in cube_boundaries) { if (boundary == null) { continue; } if (boundary.isActive == false) { continue; } BoxCollider boxCollider = boundary.GetComponent <BoxCollider>(); Vector3 pointOnSurface = getClosestPointOnSurfaceBox(boxCollider, point); float distance = (point - pointOnSurface).magnitude; // if the distance is closer calculate the point and set if (distance < closestDistance) { closestBoundary = boundary; closestDistance = distance; } } foreach (Moba_Camera_Boundary boundary in sphere_boundaries) { if (boundary.isActive == false) { continue; } SphereCollider sphereCollider = boundary.GetComponent <SphereCollider>(); Vector3 center = boundary.transform.position + sphereCollider.center; float radius = sphereCollider.radius; Vector3 centerToPoint = point - center; Vector3 pointOnSurface = center + (centerToPoint.normalized * radius); // the distance from the center of the sphere to the posiiton float distance = (point - pointOnSurface).magnitude; // check if it's the closest point if (distance < closestDistance) { closestBoundary = boundary; closestDistance = distance; } } return(closestBoundary); }
static public Vector3 GetClosestPointOnBoundary(Moba_Camera_Boundary boundary, Vector3 point) { Vector3 pointOnBoundary = point; // Find the closest point on the boundary depending on type of boundary if (boundary.type == BoundaryType.cube) { BoxCollider boxCollider = boundary.GetComponent <BoxCollider>(); pointOnBoundary = getClosestPointOnSurfaceBox(boxCollider, point); } else if (boundary.type == BoundaryType.sphere) { SphereCollider sphereCollider = boundary.GetComponent <SphereCollider>(); Vector3 center = boundary.transform.position + sphereCollider.center; float radius = sphereCollider.radius; Vector3 centerToPosition = point - center; // Get point on surface of the sphere pointOnBoundary = center + (centerToPosition.normalized * radius); } return(pointOnBoundary); }
public static bool RemoveBoundary(Moba_Camera_Boundary boundary, Moba_Camera_Boundaries.BoundaryType type) { if (type == Moba_Camera_Boundaries.BoundaryType.cube) { return(Moba_Camera_Boundaries.cube_boundaries.Remove(boundary)); } return(type == Moba_Camera_Boundaries.BoundaryType.sphere && Moba_Camera_Boundaries.cube_boundaries.Remove(boundary)); }
public static bool RemoveBoundary(Moba_Camera_Boundary boundary, BoundaryType type) { if (type == BoundaryType.cube) { return(cube_boundaries.Remove(boundary)); } return((type == BoundaryType.sphere) && cube_boundaries.Remove(boundary)); }
private void CalculateCameraBoundaries() { if (this.settings.useBoundaries && !((!this.inputs.useKeyCodeInputs) ? Input.GetButton(this.inputs.axis.button_camera_move_right) : Input.GetKey(this.inputs.keycodes.CameraMoveRight)) && !Moba_Camera_Boundaries.isPointInBoundary(this.requirements.pivot.position)) { Moba_Camera_Boundary closestBoundary = Moba_Camera_Boundaries.GetClosestBoundary(this.requirements.pivot.position); if (closestBoundary != null) { this.requirements.pivot.position = Moba_Camera_Boundaries.GetClosestPointOnBoundary(closestBoundary, this.requirements.pivot.position); } } }
// Remove a boundary from the list static public bool RemoveBoundary(Moba_Camera_Boundary boundary, BoundaryType type) { if (type == BoundaryType.cube) { return(cube_boundaries.Remove(boundary)); } else if (type == BoundaryType.sphere) { return(cube_boundaries.Remove(boundary)); } else { return(false); } }
void CalculateCameraBoundaries() { if(settings.useBoundaries && ! ((inputs.useKeyCodeInputs)? (Input.GetKey(inputs.keycodes.CameraMoveRight)): (Input.GetButton(inputs.axis.button_camera_move_right)))) { // check if the pivot is not in a boundary if(!Moba_Camera_Boundaries.isPointInBoundary(requirements.pivot.position)) { // Get the closet boundary to the pivot Moba_Camera_Boundary boundary = Moba_Camera_Boundaries.GetClosestBoundary(requirements.pivot.position); if(boundary != null) { // set the pivot's position to the closet point on the boundary requirements.pivot.position = Moba_Camera_Boundaries.GetClosestPointOnBoundary(boundary, requirements.pivot.position); } } } }
public static bool AddBoundary(Moba_Camera_Boundary boundary, BoundaryType type) { if (boundary != null) { if (type == BoundaryType.cube) { cube_boundaries.Add(boundary); return(true); } if (type == BoundaryType.sphere) { sphere_boundaries.Add(boundary); return(true); } } return(false); }
public static Vector3 GetClosestPointOnBoundary(Moba_Camera_Boundary boundary, Vector3 point) { Vector3 result = point; if (boundary.type == Moba_Camera_Boundaries.BoundaryType.cube) { BoxCollider component = boundary.GetComponent <BoxCollider>(); result = Moba_Camera_Boundaries.getClosestPointOnSurfaceBox(component, point); } else if (boundary.type == Moba_Camera_Boundaries.BoundaryType.sphere) { SphereCollider component2 = boundary.GetComponent <SphereCollider>(); Vector3 vector = boundary.transform.position + component2.center; float radius = component2.radius; result = vector + (point - vector).normalized * radius; } return(result); }
public static Vector3 GetClosestPointOnBoundary(Moba_Camera_Boundary boundary, Vector3 point) { Vector3 vector = point; if (boundary.type == BoundaryType.cube) { return(getClosestPointOnSurfaceBox(boundary.GetComponent <BoxCollider>(), point)); } if (boundary.type == BoundaryType.sphere) { SphereCollider component = boundary.GetComponent <SphereCollider>(); Vector3 vector2 = boundary.transform.position + component.center; float radius = component.radius; Vector3 vector3 = point - vector2; vector = vector2 + ((Vector3)(vector3.normalized * radius)); } return(vector); }
public static Moba_Camera_Boundary GetClosestBoundary(Vector3 point) { Moba_Camera_Boundary result = null; float num = 999999f; ListView <Moba_Camera_Boundary> .Enumerator enumerator = Moba_Camera_Boundaries.cube_boundaries.GetEnumerator(); while (enumerator.MoveNext()) { Moba_Camera_Boundary current = enumerator.get_Current(); if (!(current == null)) { if (current.isActive) { BoxCollider component = current.GetComponent <BoxCollider>(); Vector3 closestPointOnSurfaceBox = Moba_Camera_Boundaries.getClosestPointOnSurfaceBox(component, point); float magnitude = (point - closestPointOnSurfaceBox).magnitude; if (magnitude < num) { result = current; num = magnitude; } } } } ListView <Moba_Camera_Boundary> .Enumerator enumerator2 = Moba_Camera_Boundaries.sphere_boundaries.GetEnumerator(); while (enumerator2.MoveNext()) { Moba_Camera_Boundary current2 = enumerator2.get_Current(); if (current2.isActive) { SphereCollider component2 = current2.GetComponent <SphereCollider>(); Vector3 vector = current2.transform.position + component2.center; float radius = component2.radius; Vector3 b = vector + (point - vector).normalized * radius; float magnitude2 = (point - b).magnitude; if (magnitude2 < num) { result = current2; num = magnitude2; } } } return(result); }
public static Moba_Camera_Boundary GetClosestBoundary(Vector3 point) { Moba_Camera_Boundary boundary = null; float num = 999999f; ListView <Moba_Camera_Boundary> .Enumerator enumerator = cube_boundaries.GetEnumerator(); while (enumerator.MoveNext()) { Moba_Camera_Boundary current = enumerator.Current; if ((current != null) && current.isActive) { Vector3 vector = getClosestPointOnSurfaceBox(current.GetComponent <BoxCollider>(), point); Vector3 vector5 = point - vector; float magnitude = vector5.magnitude; if (magnitude < num) { boundary = current; num = magnitude; } } } ListView <Moba_Camera_Boundary> .Enumerator enumerator2 = sphere_boundaries.GetEnumerator(); while (enumerator2.MoveNext()) { Moba_Camera_Boundary boundary3 = enumerator2.Current; if (boundary3.isActive) { SphereCollider component = boundary3.GetComponent <SphereCollider>(); Vector3 vector2 = boundary3.transform.position + component.center; float radius = component.radius; Vector3 vector3 = point - vector2; Vector3 vector4 = vector2 + ((Vector3)(vector3.normalized * radius)); Vector3 vector6 = point - vector4; float num4 = vector6.magnitude; if (num4 < num) { boundary = boundary3; num = num4; } } } return(boundary); }
public static bool AddBoundary(Moba_Camera_Boundary boundary, Moba_Camera_Boundaries.BoundaryType type) { if (boundary == null) { Debug.LogWarning("Name: " + boundary.name + "; Error: AddBoundary() - null boundary passed"); return(false); } if (type == Moba_Camera_Boundaries.BoundaryType.cube) { Moba_Camera_Boundaries.cube_boundaries.Add(boundary); return(true); } if (type == Moba_Camera_Boundaries.BoundaryType.sphere) { Moba_Camera_Boundaries.sphere_boundaries.Add(boundary); return(true); } Debug.LogWarning("Name: " + boundary.name + "; Error: AddBoundary() - Incorrect BoundaryType, boundary will not be used"); return(false); }
// add boundary to list public static bool AddBoundary(Moba_Camera_Boundary boundary, BoundaryType type) { if(boundary == null) { Debug.LogWarning("Name: " + boundary.name + "; Error: AddBoundary() - null boundary passed"); return false; } if(type == BoundaryType.cube) { cube_boundaries.Add(boundary); return true; } else if(type == BoundaryType.sphere) { sphere_boundaries.Add(boundary); return true; } else { Debug.LogWarning ("Name: " + boundary.name + "; Error: AddBoundary() - Incorrect BoundaryType, boundary will not be used"); return false; } }
public static bool isPointInBoundary(Vector3 point) { bool flag = false; ListView <Moba_Camera_Boundary> .Enumerator enumerator = cube_boundaries.GetEnumerator(); while (enumerator.MoveNext()) { Moba_Camera_Boundary current = enumerator.Current; if (current.isActive) { BoxCollider component = current.GetComponent <BoxCollider>(); if (component != null) { bool flag2; calBoxRelations(component, point, false, out flag2); if (flag2) { flag = true; } } } } ListView <Moba_Camera_Boundary> .Enumerator enumerator2 = sphere_boundaries.GetEnumerator(); while (enumerator2.MoveNext()) { Moba_Camera_Boundary boundary2 = enumerator2.Current; if (boundary2.isActive) { SphereCollider collider2 = boundary2.GetComponent <SphereCollider>(); if (collider2 != null) { Vector3 vector = (boundary2.transform.position + collider2.center) - point; if (vector.magnitude < collider2.radius) { flag = true; } } } } return(flag); }
public static bool isPointInBoundary(Vector3 point) { bool result = false; ListView <Moba_Camera_Boundary> .Enumerator enumerator = Moba_Camera_Boundaries.cube_boundaries.GetEnumerator(); while (enumerator.MoveNext()) { Moba_Camera_Boundary current = enumerator.get_Current(); if (current.isActive) { BoxCollider component = current.GetComponent <BoxCollider>(); if (!(component == null)) { bool flag; Moba_Camera_Boundaries.calBoxRelations(component, point, false, out flag); if (flag) { result = true; } } } } ListView <Moba_Camera_Boundary> .Enumerator enumerator2 = Moba_Camera_Boundaries.sphere_boundaries.GetEnumerator(); while (enumerator2.MoveNext()) { Moba_Camera_Boundary current2 = enumerator2.get_Current(); if (current2.isActive) { SphereCollider component2 = current2.GetComponent <SphereCollider>(); if (!(component2 == null)) { if ((current2.transform.position + component2.center - point).magnitude < component2.radius) { result = true; } } } } return(result); }
// Remove a boundary from the list public static bool RemoveBoundary(Moba_Camera_Boundary boundary, BoundaryType type) { if(type == BoundaryType.cube) { return cube_boundaries.Remove(boundary); } else if(type == BoundaryType.sphere) { return cube_boundaries.Remove(boundary); } else { return false; } }
public static Vector3 GetClosestPointOnBoundary(Moba_Camera_Boundary boundary, Vector3 point) { Vector3 pointOnBoundary = point; // Find the closest point on the boundary depending on type of boundary if(boundary.type == BoundaryType.cube) { BoxCollider boxCollider = boundary.GetComponent<BoxCollider>(); pointOnBoundary = getClosestPointOnSurfaceBox(boxCollider, point); } else if(boundary.type == BoundaryType.sphere) { SphereCollider sphereCollider = boundary.GetComponent<SphereCollider>(); Vector3 center = boundary.transform.position + sphereCollider.center; float radius = sphereCollider.radius; Vector3 centerToPosition = point - center; // Get point on surface of the sphere pointOnBoundary = center + (centerToPosition.normalized * radius); } return pointOnBoundary; }