private void CheckForColliders(NavGrid parent) { Vector3 transformedCenter = parent.transform.TransformPoint(_relativeBounds.center); Vector3 transformedExtents = parent.transform.TransformVector(_relativeBounds.extents); Collider[] hitColliders = Physics.OverlapBox(transformedCenter, transformedExtents, parent.transform.rotation); _navigable = true; foreach (Collider col in hitColliders) { if (col.gameObject.GetComponent <NavGridObstacle>() != null) { _navigable = false; break; } #if UNITY_EDITOR if (GameObjectUtility.AreStaticEditorFlagsSet(col.gameObject, StaticEditorFlags.NavigationStatic)) { _navigable = false; break; } #endif } }
private void ValidateRelativeBounds(NavGrid parent) { if (Math.Abs(_relativeBounds.size.magnitude - parent.GetNavUnitSize()) > 0.001) // If size has changed { ComputeRelativeBounds(parent); } }
private void Awake() { Instance = this; if (_navUnits.IsCreated) { _navUnits.Dispose(); } _navUnits = new NativeArray <NavUnit>(1000, Allocator.Persistent); ValidateGrid(); ComputeNeighborOffsets(); }
private void ComputeRelativeBounds(NavGrid parent) { float navUnitSize = parent.GetNavUnitSize(); Vector3 unitLocalCenter = new Vector3(navUnitSize, navUnitSize, navUnitSize) / 2f; Vector3 unitCenter = Vector3.zero; unitCenter += Vector3.right * Row; unitCenter += Vector3.up * Col; unitCenter += Vector3.forward * Depth; unitCenter *= navUnitSize; unitCenter += unitLocalCenter; _relativeBounds = new Bounds { center = unitCenter, extents = unitLocalCenter }; }