예제 #1
0
        IEnumerator DoWork()
        {
            yield return(new WaitForSeconds(0.2f));

            Columns = (int)(Size.x / 5);
            Rows    = (int)(Size.y / 5);

            TileMap          = new GameObject[Columns, Rows];
            TileOriginOffset = new Vector3(5 * Columns * -0.5f, 0, 5 * Rows * -0.5f);

            // Start Coroutines
            yield return(DiscoverStructures());

            if (MakeRoads)
            {
                RoadMap = new bool[Columns, Rows];

                // Make Parent
                var go = Instantiate(Resources.Load <GameObject>("EmptyPrefab"), transform);
                go.name = "Roads";
                Roads   = go.transform;

                // Populate Roads
                yield return(GenerateRoads());
            }
            // Make Structures
            {
                // Make Parent
                var go = Instantiate(Resources.Load <GameObject>("EmptyPrefab"), transform);
                go.name    = "Structures";
                Structures = go.transform;

                // Poluate Structures
                yield return(GenerateStructures());
            }


            if (MakeSkyway)
            {
                // Make Skyway (Has no children, so leave at top-level)
                var go = Instantiate(Resources.Load <GameObject>("SkywayPrefab"), transform);
                go.name = "Skyway";
                Skyway  = go.transform;

                // Move and size Skyway
                Skyway.position  += new Vector3(0, SkywayHeight, 0);
                Skyway.localScale = new Vector3(5 * Columns, 10, 5 * Rows) / 10;
            }


            if (MakeRoadNavmesh && Roads != null)
            {
                NavMeshGen.BuildNavMesh(Roads, new Bounds(transform.position, new Vector3(5 * Columns, 1, 5 * Rows)));
            }

            if (Skyway != null)   // Always generate NavMesh if Skyway exists
            {
                NavMeshGen.BuildNavMesh(Skyway, new Bounds(Skyway.transform.position, new Vector3(5 * Columns, 1, 5 * Rows)));
            }
        }
예제 #2
0
        void Start()
        {
            // Generate Roads
            // Fill buildings
            // Genenerate Road and Skyway Navmeshes


            Structures = transform.Find("Structures") ?? transform; // Find "Structures" child, else use "this" transform
            Roads      = transform.Find("Roads") ?? transform;
            var Skyway = transform.Find("Skyway");

            TileOriginOffset = new Vector3(5 * bounds.x * -0.5f, 0, 5 * bounds.y * -0.5f);
            GenerateGrid();

            NavMeshGen.BuildNavMesh(Roads, new Bounds(transform.position, new Vector3(5 * bounds.x, 1, 5 * bounds.y)));

            if (Skyway != null)
            {
                NavMeshGen.BuildNavMesh(Skyway, new Bounds(Skyway.transform.position, new Vector3(5 * bounds.x, 1, 5 * bounds.y)));
            }
        }
예제 #3
0
 void OnDestroy()
 {
     NavMeshGen.ClearNavMesh();
 }