Exemplo n.º 1
0
        private List <Vector3> CalculateOffsetsForAllTileConnectionsExceptAutofill()
        {
            var offsets = new List <Vector3>(ObjectPlacementPathTileConnectionTypes.Count);
            ObjectPlacementPathTileConnectionSettings tileConnectionSettings = _path.Settings.TileConnectionSettings;

            var tileConnectionYOffsetVectorCalculator = new ObjectPlacementPathTileConnectionYOffsetVectorCalculator();
            List <ObjectPlacementPathTileConnectionType> allTileConnectionTypes = ObjectPlacementPathTileConnectionTypes.GetAllExceptAutofill();

            foreach (ObjectPlacementPathTileConnectionType tileConnectionType in allTileConnectionTypes)
            {
                offsets.Add(tileConnectionYOffsetVectorCalculator.Calculate(tileConnectionSettings.GetSettingsForTileConnectionType(tileConnectionType), _path));
            }

            return(offsets);
        }
        private void RenderPathUnderManualConstructionWhenUsingTileConnections(ObjectPlacementPath path, ObjectPlacementPathTileConnectionSettings tileConnectionSettings)
        {
            List <ObjectPlacementPathTileConnectionGridCell>    tileConnectionGridCells = path.TileConnectionGridCells;
            ObjectPlacementPathManualConstructionRenderSettings renderSettings          = path.RenderSettings.ManualConstructionRenderSettings;
            var tileConnectionYOffsetVectorCalculator = new ObjectPlacementPathTileConnectionYOffsetVectorCalculator();

            // Loop through all tile connection grid cells. Each cell will give us access to all the information
            // that we need to perform the rendering operation.
            foreach (ObjectPlacementPathTileConnectionGridCell tileConnectionGridCell in tileConnectionGridCells)
            {
                // Use the cell to access the tile connection stack. If the stack is overlapped by another stack
                // or if no boxes exist in the stack, we can move on to the next cell.
                ObjectPlacementBoxStack tileConnectionStack = tileConnectionGridCell.TileConnectionStack;
                if (tileConnectionStack.IsOverlappedByAnotherStack || tileConnectionStack.NumberOfBoxes == 0)
                {
                    continue;
                }

                // Calculate the Y offset vector which applies to all tiles in the current stack and then render each
                // box which resides inside the stack.
                Vector3 tileConnectionYOffsetVector = tileConnectionYOffsetVectorCalculator.Calculate(tileConnectionSettings.GetSettingsForTileConnectionType(tileConnectionGridCell.TileConnectionType), path);
                for (int boxIndex = 0; boxIndex < tileConnectionStack.NumberOfBoxes; ++boxIndex)
                {
                    // If the box is hidden, we can move on to the next box
                    ObjectPlacementBox placementBox = tileConnectionStack.GetBoxByIndex(boxIndex);
                    if (placementBox.IsHidden)
                    {
                        continue;
                    }

                    // Retrieve the box and apply the Y offset vector. The render the box.
                    OrientedBox orientedBox = placementBox.OrientedBox;
                    orientedBox.Center += tileConnectionYOffsetVector;
                    GizmosEx.RenderOrientedBoxEdges(orientedBox, renderSettings.BoxBorderLineColor);
                }

                // We have to take tile connection extrusion into account, so we will need to retrieve the extrusion
                // boxes and render those too.
                List <OrientedBox> extrusionOrientedBoxes = ObjectPlacementPathTileConnectionExtrusion.GetTileConnectionExtrusionOrientedBoxes(tileConnectionGridCell);
                foreach (OrientedBox extrusionBox in extrusionOrientedBoxes)
                {
                    GizmosEx.RenderOrientedBoxEdges(extrusionBox, renderSettings.BoxBorderLineColor);
                }
            }
        }
Exemplo n.º 3
0
        public static List <OrientedBox> GetTileConnectionExtrusionOrientedBoxes(ObjectPlacementPathTileConnectionGridCell tileConnectionGridCell)
        {
            ObjectPlacementBoxStack tileConnectionStack = tileConnectionGridCell.TileConnectionStack;
            ObjectPlacementPathTileConnectionTypeSettings tileConnectionTypeSettings = tileConnectionGridCell.TileConnectionPath.Settings.TileConnectionSettings.GetSettingsForTileConnectionType(tileConnectionGridCell.TileConnectionType);

            if (tileConnectionStack != null)
            {
                if (tileConnectionStack.NumberOfBoxes == 0)
                {
                    return(new List <OrientedBox>());
                }
                if (tileConnectionTypeSettings.IsAnyExtrusionNecessary())
                {
                    // Handle upwards extrusion
                    Vector3 nextTilePositionForUpwardsExtrusion;
                    Vector3 extrudeOffset;
                    Vector3 pathExtensionPlaneNormal = tileConnectionGridCell.TileConnectionPath.ExtensionPlane.normal;

                    var     tileConnectionYOffsetVectorCalculator = new ObjectPlacementPathTileConnectionYOffsetVectorCalculator();
                    Vector3 yOffsetVector = tileConnectionYOffsetVectorCalculator.Calculate(tileConnectionTypeSettings, tileConnectionGridCell.TileConnectionPath);

                    extrudeOffset = pathExtensionPlaneNormal * tileConnectionStack.GetBoxSizeAlongNormalizedDirection(pathExtensionPlaneNormal);
                    if (tileConnectionStack.IsGrowingUpwards)
                    {
                        nextTilePositionForUpwardsExtrusion = tileConnectionStack.GetBoxByIndex(tileConnectionStack.NumberOfBoxes - 1).Center + extrudeOffset;
                    }
                    else
                    {
                        nextTilePositionForUpwardsExtrusion = tileConnectionStack.GetBoxByIndex(0).Center + extrudeOffset;
                    }

                    var extrudedBox = new OrientedBox();
                    extrudedBox.Rotation       = tileConnectionStack.Rotation;
                    extrudedBox.ModelSpaceSize = tileConnectionStack.BoxSize;

                    var extrusionOrientedBoxes = new List <OrientedBox>();
                    for (int extrudeIndex = 0; extrudeIndex < tileConnectionTypeSettings.UpwardsExtrusionAmount; ++extrudeIndex)
                    {
                        extrudedBox.Center = nextTilePositionForUpwardsExtrusion + yOffsetVector;
                        extrusionOrientedBoxes.Add(new OrientedBox(extrudedBox));

                        nextTilePositionForUpwardsExtrusion += extrudeOffset;
                    }

                    // Handle downwards extrusion
                    extrudeOffset = -pathExtensionPlaneNormal *tileConnectionStack.GetBoxSizeAlongNormalizedDirection(pathExtensionPlaneNormal);

                    if (tileConnectionStack.IsGrowingDownwards)
                    {
                        nextTilePositionForUpwardsExtrusion = tileConnectionStack.GetBoxByIndex(tileConnectionStack.NumberOfBoxes - 1).Center + extrudeOffset;
                    }
                    else
                    {
                        nextTilePositionForUpwardsExtrusion = tileConnectionStack.GetBoxByIndex(0).Center + extrudeOffset;
                    }

                    for (int extrudeIndex = 0; extrudeIndex < tileConnectionTypeSettings.DownwardsExtrusionAmount; ++extrudeIndex)
                    {
                        extrudedBox.Center = nextTilePositionForUpwardsExtrusion + yOffsetVector;
                        extrusionOrientedBoxes.Add(new OrientedBox(extrudedBox));

                        nextTilePositionForUpwardsExtrusion += extrudeOffset;
                    }

                    return(extrusionOrientedBoxes);
                }
                else
                {
                    return(new List <OrientedBox>());
                }
            }
            else
            {
                return(new List <OrientedBox>());
            }
        }
Exemplo n.º 4
0
        private List <ObjectPlacementData> GetPlacementDataForAutofillTiles(ObjectPlacementPathTileConnectionGrid tileConnectionGrid)
        {
            Prefab      autofillPrefab = _path.Settings.TileConnectionSettings.GetSettingsForTileConnectionType(ObjectPlacementPathTileConnectionType.Autofill).Prefab;
            OrientedBox autoFillPrefabWorldOrientedBox = autofillPrefab.UnityPrefab.GetHierarchyWorldOrientedBox();
            Vector3     autofillPrefabBoxSize          = autoFillPrefabWorldOrientedBox.ScaledSize;
            Plane       extensionPlane   = _path.ExtensionPlane;
            float       objectMissChance = _path.Settings.ManualConstructionSettings.ObjectMissChance;
            bool        usingSprites     = _path.Settings.TileConnectionSettings.UsesSprites();

            var     tileConnectionScaleCalculator         = new ObjectPlacementPathTileConnectionScaleCalculator();
            var     tileConnectionYOffsetVectorCalculator = new ObjectPlacementPathTileConnectionYOffsetVectorCalculator();
            Vector3 worldScale    = tileConnectionScaleCalculator.CalculateWorldScale(_tileConnectionXZSize, autofillPrefabBoxSize, autofillPrefab.UnityPrefab.transform, _path);
            Vector3 yOffsetVector = tileConnectionYOffsetVectorCalculator.Calculate(_path.Settings.TileConnectionSettings.GetSettingsForTileConnectionType(ObjectPlacementPathTileConnectionType.Autofill), _path);

            List <ObjectPlacementPathTileConnectionGridCell> autoFillTileConnectionGridCells = tileConnectionGrid.CreateAndReturnAutofillTileConnectionCells();

            if (autoFillTileConnectionGridCells.Count == 0)
            {
                return(new List <ObjectPlacementData>());
            }

            // Note: All autofill tiles have the same rotation.
            Quaternion worldRotation = (new ObjectPlacementPathTileConnectionRotationCalculator()).Calculate(autoFillTileConnectionGridCells[0]);
            var        objectPlacementDataInstances = new List <ObjectPlacementData>(autoFillTileConnectionGridCells.Count);

            foreach (ObjectPlacementPathTileConnectionGridCell autofillGridCell in autoFillTileConnectionGridCells)
            {
                if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementPathManualConstructionSettings.MinObjectMissChance, ObjectPlacementPathManualConstructionSettings.MaxObjectMissChance))
                {
                    continue;
                }

                Vector3 cellPosition = tileConnectionGrid.CalculateCellPosition(autofillGridCell.CellIndices);
                Vector3 cellPositionOnPathExtensionPlane = extensionPlane.ProjectPoint(cellPosition);

                OrientedBox tileOrientedBox = new OrientedBox(autoFillPrefabWorldOrientedBox);
                tileOrientedBox.Center   = cellPositionOnPathExtensionPlane + extensionPlane.normal * (usingSprites ? 0.0f : autofillPrefabBoxSize.y * 0.5f);
                tileOrientedBox.Rotation = worldRotation;
                tileOrientedBox.Scale    = worldScale;
                if (!_allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(tileOrientedBox, true))
                {
                    continue;
                }

                var objectPlacementData = new ObjectPlacementData();
                objectPlacementData.WorldPosition = ObjectPositionCalculator.CalculateObjectHierarchyPosition(autofillPrefab, tileOrientedBox.Center, worldScale, worldRotation) + yOffsetVector;
                objectPlacementData.WorldScale    = worldScale;
                objectPlacementData.WorldRotation = worldRotation;
                objectPlacementData.Prefab        = autofillPrefab;
                objectPlacementDataInstances.Add(objectPlacementData);

                // Apply extrusion if necessary
                if (!usingSprites)
                {
                    List <OrientedBox> extrusionOrientedBoxes = ObjectPlacementPathTileConnectionExtrusion.GetTileConnectionExtrusionOrientedBoxes(autofillGridCell);
                    foreach (OrientedBox extrusionBox in extrusionOrientedBoxes)
                    {
                        if (ObjectPlacementMissChance.Missed(objectMissChance, ObjectPlacementPathManualConstructionSettings.MinObjectMissChance, ObjectPlacementPathManualConstructionSettings.MaxObjectMissChance))
                        {
                            continue;
                        }
                        if (!_allowObjectIntersection && ObjectQueries.IntersectsAnyObjectsInScene(extrusionBox, true))
                        {
                            continue;
                        }

                        objectPlacementData = new ObjectPlacementData();
                        objectPlacementData.WorldPosition = ObjectPositionCalculator.CalculateObjectHierarchyPosition(autofillPrefab, extrusionBox.Center, worldScale, worldRotation);
                        objectPlacementData.WorldScale    = worldScale;
                        objectPlacementData.WorldRotation = worldRotation;
                        objectPlacementData.Prefab        = autofillPrefab;
                        objectPlacementDataInstances.Add(objectPlacementData);
                    }
                }
            }

            return(objectPlacementDataInstances);
        }