void Start()
    {
        // FIXME is new object the way to go?? Or scriptable object without new keyword?? Or static??
        MazeFrameCreator mazeFrameCreator = new MazeFrameCreatorMeshIcosahedron(2, 4)
        {
            Scale  = new Vector3(10, 10, 10),
            Jitter = 0f
        };

        mazeFrame = mazeFrameCreator.GenerateEmptyMazeFrame();
        for (int i = 0; i <= 3; i++)
        {
            mazeFrame.SetActiveQuadrant(i);
            mazeFrameCreator.GenerateMaze(ref mazeFrame);
            mazeFrame.SetOnShortestPath(mazeFrame.Quadrants[i], i); // HACKY
        }
        mazeFrame.ActivateAllNodes();

        //mazeFrame.KeepOnlyShortestPathConnections();

        mazeFrame.AddOffsetStartAndEndNodes(Vector3.Scale(Vector3.forward, mazeFrameCreator.Scale) * 3, true);
        mazeFrame.AddPathSegments();

        //mazeFrameSplines = new MazeFrameSplines(mazeFrame);
        //GameObject mazeObjects = null;
        //MazePopulator.PopulateWithSplineFittedBars(mazeFrame, ref mazeFrameSplines, ref mazeObjects, new Vector3(2, .15f, 1));


        //GameObject player = null;
        //GameObject cameraRig = null;
        //MazePopulator.PlacePlayerAndCamera(ref player, ref cameraRig, mazeFrame.StartNode.Position + (Vector3.Scale(Vector3.forward, mazeFrameCreator.Scale) * 1.5f));
    }
Exemple #2
0
    private IEnumerator BuildNewMaze()
    {
        float mazeFrameElementsBuilt = 0;

        mazeFrameMeshesArePresent = false;
        // Initialize maze creator
        MazeFrameCreator mazeFrameCreator = null;

        switch (mazeShape)
        {
        case 0:
        {
            mazeFrameCreator = new MazeFrameCreatorSquare3D(mazeSize, nQuadrants)
            {
                Scale = mazeScale, Jitter = mazeJitter
            }; break;
        }

        case 1:
        {
            mazeFrameCreator = new MazeFrameCreatorMeshIcosahedron(nDivisions, nQuadrants)
            {
                Scale = mazeScale, Jitter = mazeJitter
            }; break;
        }
        }
        // Set random seed selector
        System.Random randGen = new ConsistentRandom();
        // Randomize order of difficulties
        int[] randomQuadrantIndices = Utilities.RandomIndices(nQuadrants);
        // Generate maze!
        if (nQuadrants != 0 && nQuadrants != difficulties.Length)
        {
            throw new System.ArgumentException("When using quadrants, nQuadrants and nDifficulties should be equal.");
        }
        List <MazeFrame> singleMazeFrames = new List <MazeFrame>(difficulties.Length);

        for (int iDifficulty = 0; iDifficulty < difficulties.Length; iDifficulty++)
        {
            List <MazeFrame> singleFrameSections = new List <MazeFrame>(nSections);
            for (int iSections = 0; iSections < nSections; iSections++)
            {
                // Create sections
                int quadrantInd;
                //if (nQuadrants != 0) { quadrantInd = iDifficulty; }
                if (nQuadrants != 0)
                {
                    quadrantInd = randomQuadrantIndices[iDifficulty];
                }
                else
                {
                    quadrantInd = 0;
                }
                MazeFrame currSection    = null;
                int       currDifficulty = difficulties[iDifficulty];
                int       currSeedInd    = randGen.Next(seedData[quadrantInd].seeds[currDifficulty].Length);
                mazeFrameCreator.RandomSeed = seedData[quadrantInd].seeds[currDifficulty][currSeedInd];
                //mazeFrameCreator.RandomSeed = seedData[quadrantInd].seeds[iDifficulty][iSections];
                if (nQuadrants == 0)
                {
                    currSection = mazeFrameCreator.GenerateMaze();
                }
                else
                {
                    currSection = mazeFrameCreator.GenerateEmptyMazeFrame();
                    mazeFrameCreator.GenerateMaze(ref currSection, quadrantInd);
                    currSection.SetOnShortestPath(currSection.Quadrants[quadrantInd], 0); // HACKY
                }
                //currSection.KeepOnlyShortestPathConnections();
                //currSection.AddPathSegments();
                // DEBUG
                if (nQuadrants != 0)
                {
                    Debug.Log(currSection.GetNIntersectionsOnPath()[0] + "  " + currSection.GetDifficulty(quadrantInd)[0] + " - " + seedData[quadrantInd].difficulties[currDifficulty][currSeedInd]);
                }
                else
                {
                    Debug.Log(currSection.GetNIntersectionsOnPath()[0] + "  " + currSection.GetDifficulty()[0]);
                }
                // DEBUG
                singleFrameSections.Add(currSection);
                mazeFrameElementsBuilt++;
                LevelBuiltProgressPercentage = (mazeFrameElementsBuilt / (difficulties.Length * nSections)) / 2;
                yield return(null);
            }
            MazeFrame currSingleFrame;
            if (singleFrameSections.Count > 1)
            { //MazeFrame currSingleFrame = MazeFrame.Concatenate(singleFrameSections, mazeFrameCreator.Scale, mazeDirection);
                currSingleFrame = MazeFrame.CombineShrink(singleFrameSections, shrinkFactor);
            }
            else
            {
                currSingleFrame = singleFrameSections[0];
            }
            currSingleFrame.AddOffsetStartNode(Vector3.Scale(mazeDirection, mazeScale) * startOffsetFactor, true);
            currSingleFrame.AddOffsetEndNode(Vector3.Scale(mazeDirection, mazeScale) * endOffsetFactor, true);
            for (int iInc = 0; iInc < iDifficulty; iInc++)
            {
                currSingleFrame.IncrementShortestPathIndices();
            }
            singleMazeFrames.Add(currSingleFrame);
        }
        if (singleMazeFrames.Count > 1)
        {
            mazeFrame = MazeFrame.Merge(singleMazeFrames);
        }
        else
        {
            mazeFrame = singleMazeFrames[0];
        }
        //mazeFrame.ConnectUnconnectedNodes();
        mazeFrame.AddPathSegments();
        yield return(null);

        // Populate maze and get return splines and maze objects
        mazePopulator.PopulateWithSplineFittedBars(mazeFrame, ref mazeFrameSplines, ref mazeObjects, objectScaling);
        //mazePopulator.PopulateWithSplineFittedCylinders(mazeFrame, ref mazeFrameSplines, ref mazeObjects, objectScaling);

        // Wait till population is complete
        while (!mazeFrameMeshesArePresent)
        {
            if (mazePopulator.MazeObjectsPlaced == mazeFrameSplines.SplineSegments.Count)
            {
                mazeFrameMeshesArePresent = true;
            }
            yield return(null);
        }

        // Create and Initialize gravity frame
        gravityFrameController = new GravityFrameController(mazeFrame, mazeFrameSplines, gravJunctionDistFactor, gravPlaneWidth);
        yield return(null);


        // Place others
        PlacePlayerAndCamera();
        PlaceEndPortal();
        PlaceCubeOfDeath();
        PlaceMindWarpTriggers();
    }