예제 #1
0
        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
            }
        }
예제 #2
0
 private void ValidateRelativeBounds(NavGrid parent)
 {
     if (Math.Abs(_relativeBounds.size.magnitude - parent.GetNavUnitSize()) > 0.001) // If size has changed
     {
         ComputeRelativeBounds(parent);
     }
 }
예제 #3
0
        private void Awake()
        {
            Instance = this;

            if (_navUnits.IsCreated)
            {
                _navUnits.Dispose();
            }
            _navUnits = new NativeArray <NavUnit>(1000, Allocator.Persistent);

            ValidateGrid();
            ComputeNeighborOffsets();
        }
예제 #4
0
        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
            };
        }