コード例 #1
0
ファイル: MazeGenerator.cs プロジェクト: Evertras/WGJ68Truth
    private void Start()
    {
        if (!StaticSize)
        {
            Width  = PlayerPrefs.GetInt("size", Width);
            Height = PlayerPrefs.GetInt("size", Height);
        }

        WallLength = CellSize - 3.0f;
        Offset     = new Vector3(-CellSize * 0.5f, 0.0f, -CellSize * 0.5f);

        var edges = KruskalMaze.Generate(Width, Height);

        for (int x = 0; x <= Width; ++x)
        {
            for (int z = 0; z <= Height; ++z)
            {
                var pillar = Instantiate(
                    Pillar,
                    new Vector3(
                        x * CellSize,
                        0.5f * WallHeight,
                        z * CellSize
                        ) + Offset,
                    Quaternion.identity);

                pillar.transform.localScale = new Vector3(1.0f, WallHeight, 1.0f);

                if ((z == 0 || z == Height) && x != 0)
                {
                    var wall = SpawnWallBottom(x, z);

                    wall.Passable = false;
                }

                if ((x == 0 || x == Width) && z != 0)
                {
                    var wall = SpawnWallLeft(x, z);
                    wall.Passable = false;
                }

                if (
                    z != 0 &&
                    x != Width - 1 &&
                    LandmarkProps.Length > 0 &&
                    Random.Range(0.0f, 1.0f) < LandmarkChance)
                {
                    int propIndex = Random.Range(0, LandmarkProps.Length);

                    Instantiate(
                        LandmarkProps[propIndex],
                        new Vector3(
                            pillar.transform.position.x + 1.5f,
                            0.0f,
                            pillar.transform.position.z - 1.5f),
                        Quaternion.identity);
                }
            }
        }

        foreach (var pair in edges)
        {
            var      edge     = pair.Key;
            var      passable = pair.Value;
            MazeWall wall;

            if (edge.A.X == edge.B.X)
            {
                wall = SpawnWallBottom(edge.A.X + 1, edge.A.Y + 1);
            }
            else
            {
                wall = SpawnWallLeft(edge.A.X + 1, edge.A.Y + 1);
            }

            wall.Passable = passable;
        }

        var goal = Instantiate(
            Goal,
            new Vector3(
                CellSize * (Width - 1),
                1.0f,
                CellSize * (Height - 1)
                ),
            Quaternion.identity);

        if (HotCold != null)
        {
            HotCold.GetComponent <ColdHotOrbit>().Goal = goal;
        }

        if (TreasureCamera != null)
        {
            TreasureCamera.Follow = goal.transform;
            TreasureCamera.LookAt = goal.transform;
        }

        if (VictoryTimeline != null)
        {
            goal.GetComponent <GoalGet>().Timeline = VictoryTimeline;
        }

        if (NavMeshSurface != null)
        {
            NavMeshSurface.BuildNavMesh();
        }
    }
コード例 #2
0
 void Bake()
 {
     UnityEngine.AI.NavMeshSurface nav = GetComponent <UnityEngine.AI.NavMeshSurface>();
     nav.BuildNavMesh();
 }
コード例 #3
0
 // Use this for initialization
 private void Bake()
 {
     nav.BuildNavMesh();
 }