Esempio n. 1
0
        private int GetFallDistance()
        {
            var fallDistance        = 100;
            var objectsProfile      = Room.Instance.ObjectsVolume.GetHighProfile();
            var furnitureLowProfile = _target.Volume.GetLowProfile();

            foreach (var kvp in furnitureLowProfile)
            {
                var voxelFurniture     = new Vector3Int(kvp.Key.x, kvp.Value, kvp.Key.y);
                var voxelWorldFuniture = VoxelSpace.GetWorldVoxelFromLocalVoxel(_target.transform.position,
                                                                                voxelFurniture - _target.Volume.Pivot);

                var voxelLocalRoom = VoxelSpace.GetLocalVoxelFromWorldVoxel(Room.Instance.transform.position,
                                                                            voxelWorldFuniture + Room.Instance.ObjectsVolume.Pivot);
                var roomXz = new Vector2Int(voxelLocalRoom.x, voxelLocalRoom.z);
                if (objectsProfile.ContainsKey(roomXz))
                {
                    Debug.DrawRay(VoxelSpace.GetWorldPositionCenter(voxelWorldFuniture), Vector3.up, Color.red, 1f);
                    var localH         = objectsProfile[roomXz];
                    var voxelWorldRoom = VoxelSpace.GetWorldVoxelFromLocalVoxel(Room.Instance.transform.position,
                                                                                new Vector3Int(roomXz.x, localH, roomXz.y) - Room.Instance.ObjectsVolume.Pivot);

                    fallDistance = Mathf.Min(Mathf.Abs(voxelWorldRoom.y - voxelWorldFuniture.y) - 1, fallDistance);
                    fallDistance = Mathf.Max(fallDistance, 0);
                }

                fallDistance = Mathf.Min(voxelWorldFuniture.y, fallDistance);
            }

            if (fallDistance == 100)
            {
                return(0);
            }
            return(fallDistance);
        }
Esempio n. 2
0
        public Bounds GetWorldBounds()
        {
            Volume.RecalculateBounds();
            var minBounds    = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, Volume.MinBounds - Volume.Pivot));
            var maxBounds    = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, Volume.MaxBounds - Volume.Pivot));
            var boundsCenter = Vector3.Lerp(minBounds, maxBounds, 0.5f);
            var boundSize    = new Vector3(
                Mathf.Abs(maxBounds.x - minBounds.x),
                Mathf.Abs(maxBounds.y - minBounds.y),
                Mathf.Abs(maxBounds.z - minBounds.z)
                );

            return(new Bounds(boundsCenter, boundSize + VoxelSpace.VoxelSize3D));
        }
Esempio n. 3
0
        private void OnDrawGizmos()
        {
            if (!DrawGizmos)
            {
                return;
            }

            const float opacity = 0.5f;

            // Voxels
            //Gizmos.color = new Color(1f, 1f, 1f, Opacity);
            Gizmos.color = CellColor;
            foreach (var kvp in Volume.Data)
            {
                var pos = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, kvp.Key - Volume.Pivot));
                Gizmos.DrawWireCube(pos, VoxelSpace.VoxelSize3D);
            }

            // Pivot
            Gizmos.color = new Color(1f, 0f, 0f, opacity);
            var pivotPos = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, Volume.Pivot - Volume.Pivot));

            Gizmos.DrawCube(pivotPos, VoxelSpace.VoxelSize3D * 0.9f);
        }
Esempio n. 4
0
        public BoxCollider UpdateCollider()
        {
            var col = GetComponent <BoxCollider>();

            if (col == null)
            {
                col = gameObject.AddComponent <BoxCollider>();
            }

            Volume.RecalculateBounds();
            var minBounds    = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, Volume.MinBounds - Volume.Pivot));
            var maxBounds    = VoxelSpace.GetWorldPositionCenter(VoxelSpace.GetWorldVoxelFromLocalVoxel(transform.position, Volume.MaxBounds - Volume.Pivot));
            var boundsCenter = Vector3.Lerp(minBounds, maxBounds, 0.5f);
            var boundSize    = new Vector3(
                Mathf.Abs(maxBounds.x - minBounds.x),
                Mathf.Abs(maxBounds.y - minBounds.y),
                Mathf.Abs(maxBounds.z - minBounds.z)
                );

            col.center = transform.InverseTransformPoint(boundsCenter);
            col.size   = boundSize + VoxelSpace.VoxelSize3D;

            return(col);
        }