private void SpawnNewBlock(BlockObjectWithRandom patternBlock, BlockObjectWithRandom replaceableBlock, titleHolderObject currentTileHolder, String newBlockName = "Pattern Block ")
    {
        var savedLocation = replaceableBlock.currentLocation;

        Destroy(replaceableBlock.prefab);
        var newBlock = Instantiate(patternBlock.prefab, currentTileHolder.tileHolder.transform);

        newBlock.transform.localPosition = savedLocation;
        newBlock.name = newBlockName + savedLocation;
        newBlocks.Add(newBlock);
        if (navOptions.allowNav)
        {
            navOptions.NavMeshAdder(newBlock);
        }
    }
Example #2
0
    private void SelectEdgeBlock(List <BlockObjectWithRandom> blockObs, EdgeType edgeType)
    {
        List <BlockObjectWithRandom> possibleBlocks = new List <BlockObjectWithRandom>();
        Vector3 filterVectorX_Z = new Vector3(edgeX, 0, edgeZ);
        var     filterVector    = replaceRules.endVector;

        if (edgeType == EdgeType.Start)
        {
            filterVector    = replaceRules.startingVector;
            filterVectorX_Z = new Vector3(0, 0, 0);
        }

        if (filterVector == EdgeVector.X)
        {
            possibleBlocks = blockObs.FindAll(block =>
                                              block.currentLocation.x == filterVectorX_Z.x
                                              );
        }
        if (filterVector == EdgeVector.Z)
        {
            possibleBlocks = blockObs.FindAll(block =>
                                              block.currentLocation.z == filterVectorX_Z.z
                                              );
        }
        if (filterVector == EdgeVector.X_And_Z)
        {
            possibleBlocks = blockObs.FindAll(block => block.currentLocation.x == filterVectorX_Z.x && block.currentLocation.z == filterVectorX_Z.z);
        }
        if (filterVector == EdgeVector.X_Or_Z)
        {
            possibleBlocks = blockObs.FindAll(block => block.currentLocation.x == filterVectorX_Z.x || block.currentLocation.z == filterVectorX_Z.z);
        }


        if (edgeType == EdgeType.Start)
        {    //   filterVectorX_Z = new Vector3(0, 0, 0);
            possibleStarts        = possibleBlocks;
            randomlySelectedStart = possibleStarts.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
        }
        else
        {
            possibleEnds        = possibleBlocks;
            randomlySelectedEnd = possibleEnds.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
        }
    }
Example #3
0
    private void addFillerBlocks(BlockObjectWithRandom lastBlock, bool forceZ = true)
    {
        if (lastBlock.currentLocation.x == edgeX && lastBlock.currentLocation.z == edgeZ)
        {
            //return;
        }
        Vector3 newLocation = new Vector3();

        //  if (UnityEngine.Random.value < 0.5f)

        if ((UnityEngine.Random.value < 0.5f) && lastBlock.currentLocation.x != edgeX)
        {
            forceZ      = false;
            newLocation = lastBlock.currentLocation + new Vector3(1, 0, 0);
            // incerment on x
        }
        else if (lastBlock.currentLocation.z != edgeZ)
        //else

        {
            forceZ      = true;
            newLocation = lastBlock.currentLocation + new Vector3(0, 0, 1);

            // incerment on z
        }

        var blockToReplace = cachedLocalBlocks.Find(block => block.currentLocation == newLocation);

        blocksToReplace.Add(blockToReplace);
        if (randomlySelectedEnd == blockToReplace)
        {
            return;
        }

        addFillerBlocks(blockToReplace, forceZ);
    }
Example #4
0
    public void GetBlockPreb(Vector3 vert, out BlockObjectWithRandom blockObjectPrefab)
    {
        var exactPrefab = blockObjectPrefabs.Find(exactMatch => exactMatch.exactSpawnPoint == vert);

        if (exactPrefab != null && exactPrefab.exactSpawner)
        {
            blockObjectPrefab = exactPrefab;
            return;
        }

        blockObjectPrefab = null;
        // newVert = new Vector3(vert.x + indc, 0, vert.z);
        foreach (var blockPreFabThing in blockObjectPrefabs)
        {
            if (blockPreFabThing.canSpawn(vert))
            {
                blockObjectPrefab = blockPreFabThing;
            }
        }
        if (blockObjectPrefab == null)
        {
            blockObjectPrefab = defaultBlock;
        }
    }
Example #5
0
    public List <BlockObjectWithRandom> GeneratePattern(List <BlockObjectWithRandom> blockObs, BlockObjectWithRandom startBlock = null, BlockObjectWithRandom endBlock = null)
    {
        cachedLocalBlocks = blockObs;
        edgeX             = blockObs.Max(x => x.currentLocation.x);
        edgeZ             = blockObs.Max(x => x.currentLocation.z);

        SelectEdgeBlock(blockObs, EdgeType.Start);
        SelectEdgeBlock(blockObs, EdgeType.End);
        addFillerBlocks(randomlySelectedStart);
        // UnityEngine.Random.Range(


        // blocksToReplace.Add(randomlySelectedStart);
        //blocksToReplace.Add(randomlySelectedEnd);
        return(blocksToReplace);
    }
Example #6
0
    public IEnumerator Gen3dTiles(List <Vector3> verticies, int tileHolderIndex)
    {
        if (tileHolders.Count - 1 < tileHolderIndex)
        {
            tileHolders.Add(new titleHolderObject());
        }
        var currentTileHolderObject = tileHolders[tileHolderIndex];

        if (currentTileHolderObject.tileHolder)
        {
            Destroy(currentTileHolderObject.tileHolder);
        }
        currentTileHolderObject.tileHolder = new GameObject("Tile Holder:" + currentTileHolderObject);
        currentTileHolderObject.tileHolder.transform.parent = transform;
        currentTileHolderObject.blocksInGame = new List <BlockObjectWithRandom>();



        foreach (var vert in verticies)
        {
            if (blockObjectPrefabs.Count != 0)
            {
                BlockObjectWithRandom blockObjectPrefab;
                // Vector3 newVert;
                GetBlockPreb(vert, out blockObjectPrefab);

                var newBlockOb = new BlockObjectWithRandom();

                //vert.y = indc;
                newBlockOb.prefab = Instantiate(blockObjectPrefab.prefab, vert, transform.rotation);
                newBlockOb.prefab.transform.parent = currentTileHolderObject.tileHolder.transform;

                newBlockOb.prefab.name     = newBlockOb.prefab.name + vert;
                newBlockOb.currentLocation = vert;
                currentTileHolderObject.blocksInGame.Add(newBlockOb);
            }
            if (blockBuildTime > 0.1f)
            {
                yield return(new WaitForSeconds(blockBuildTime));
            }
        }



        // calculate title holder size

        currentTileHolderObject.titleBounds = new Bounds(currentTileHolderObject.tileHolder.transform.position, Vector3.zero);

        foreach (Renderer r in currentTileHolderObject.tileHolder.GetComponentsInChildren <Renderer>())
        {
            currentTileHolderObject.titleBounds.Encapsulate(r.bounds);
        }

        currentTileHolderObject.tileHolder.transform.localPosition = new Vector3(0, 0, 0);
        currentTileHolderObject.targetRotation = targetRotation;
        //  cube1.transform.
        var newX = currentTileHolderObject.targetRotation.x;
        var newY = currentTileHolderObject.targetRotation.y;
        var newZ = currentTileHolderObject.targetRotation.z;

        currentTileHolderObject.tileHolder.transform.Rotate(newX, newY, newZ, Space.Self);
        PostGenActions();
        yield return(new WaitForSeconds(5));
    }