Exemple #1
0
    void Start()
    {
        transform.position = Vector3.zero;

        finishedLevel = false;

        if (GetLevel() != null)
        {
            terrainGenerator.CreateTerrain(GetLevel().heights);
            anchorPointLocations = GetLevel().anchorPointLocations;
            roadLevel            = GetLevel().roadLevel;
            bridgeBudget         = GetLevel().budget;
        }
        else
        {
            terrainGenerator.CreateTerrain();
            bridgeBudget = 100000;
        }

        snapPoints       = new GameObject();
        snapPoints.name  = "SnapPointsContainer";
        bridgeBeams      = new GameObject();
        bridgeBeams.name = "BridgeBeamsContainer";

        bridgeCost = 0;

        roadLevel = 18;

        int     w    = snapPositionsDimensions._1;
        int     h    = snapPositionsDimensions._2;
        Vector3 dims = new Vector3(w * snapPointSeparations.x, h * snapPointSeparations.y, 0);

        gridOrigin.x = -dims.x / 2.0f + snapPointOffset.x;
        gridOrigin.y = -dims.y / 2.0f + snapPointOffset.y;
        gridOrigin.z = snapPointOffset.z;

        trainGoal = gridOrigin.x + dims.x;

        for (int j = 0; j != h; j++)
        {
            for (int i = 0; i != w; i++)
            {
                bool       foundAnchor = FindAnchorPointIndex(i, j) != -1;
                Vector3    pos         = FromSnapToSpace(new Vector3(i, j, gridOrigin.z));
                GameObject go          = Instantiate((foundAnchor? AnchorPointPrefab: SnapPointPrefab), pos, new Quaternion()) as GameObject;
                go.transform.parent = snapPoints.transform;
                go.layer            = 8;
                go.GetComponent <SnapPoint>().position = Tuple <int, int> .Of(i, j);

                go.GetComponent <SnapPoint>().isBase            = foundAnchor;
                go.GetComponent <SnapPoint>().isBaseTerrain     = foundAnchor;
                go.GetComponent <SnapPoint>().bridgeSetupParent = this;
            }
        }

        LevelStage = eLevelStage.SetupStage;
    }
Exemple #2
0
    public void CreateTerrain()
    {
        locked = true;
        slider.GetComponent <Image>().fillAmount = 0f;
        sliderBackground.SetActive(true);
        sliderText.SetActive(true);

        if (standardTerrainStyle)
        {
            terrainGenerator.CreateTerrain(size, 5, 3);
        }
        else
        {
            terrainGenerator.CreateTerrain(size, 1, 20);
        }
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        Debug.Log(Application.dataPath);

        TerrainGen = new TerrainGenerator();

        /*
         * GoogleElevationPack GoogleElevation;
         *
         * GoogleElevation = new GoogleElevationPack();
         *
         * //ElevationPack.GenerateElevation(39.7391536f, -104.9847034f); // One Point
         *
         * //ElevationPack.GenerateElevation(39.7391536f, -104.9847034f, 36.455556f, -116.866667f); // Two Points
         *
         * //ElevationPack.GenerateElevation(36.578581f, -118.291994f, 36.23998f, -116.83171f, 50); // Path
         *
         * GoogleElevation.GenerateElevation(36.0f, -118f, 35f, -116f, 200); // Path
         *
         * TerrainGen.SetTerrainInfo(GoogleElevation.DataWidth ,GoogleElevation.DataHeight,150);
         *
         * TerrainGen.CreateTerrain(GoogleElevation.GetElevationBy2DFloat() , GoogleElevation.DataWidth , GoogleElevation.DataHeight);
         *
         */

        DEMElevationPack DemElevation;

        DemElevation = new DEMElevationPack();

        DemElevation.ReadFile(Application.dataPath + "/Data/elevation_map100.dem");

        //DemElevation.ReadFile(Application.dataPath+"/Data/elevation_map000.dem");

        TerrainGen.SetTerrainInfo(DemElevation.DataWidth * 30, DemElevation.DataHeight * 30, 4000);

        //TerrainGen.SetTerrainInfo(DemElevation.DataWidth *10,DemElevation.DataHeight * 10,2048);

        //TerrainGen.SetTerrainInfo(10000,10000,2048);

        TerrainGen.CreateTerrain(DemElevation.GetElevationBy2DFloat(), DemElevation.DataWidth, DemElevation.DataHeight);

        TerrainGen.CreateTexture("Grass (Hill)", "Grass&Rock", "Cliff (Layered Rock)");

        TerrainGen.AssignTexture();
    }
Exemple #4
0
    public IEnumerator InitCoroutine()
    {
        WorldSetup worldSetup = null;

        if (!World.CanLoadFromUrl())
        {
            object[] size = new object[] { "Generating procedural map of size ", World.Size, " with seed ", World.Seed };
            UnityEngine.Debug.Log(string.Concat(size));
        }
        else
        {
            UnityEngine.Debug.Log(string.Concat("Loading custom map from ", World.Url));
        }
        ProceduralComponent[] componentsInChildren = worldSetup.GetComponentsInChildren <ProceduralComponent>(true);
        Timing timing = Timing.Start("Downloading World");

        if (World.Procedural && !World.CanLoadFromDisk() && World.CanLoadFromUrl())
        {
            LoadingScreen.Update("DOWNLOADING WORLD");
            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            UnityWebRequest downloadHandlerBuffer = UnityWebRequest.Get(World.Url);
            downloadHandlerBuffer.downloadHandler = new DownloadHandlerBuffer();
            downloadHandlerBuffer.Send();
            while (!downloadHandlerBuffer.isDone)
            {
                float single = downloadHandlerBuffer.downloadProgress * 100f;
                LoadingScreen.Update(string.Concat("DOWNLOADING WORLD ", single.ToString("0.0"), "%"));
                yield return(CoroutineEx.waitForEndOfFrame);
            }
            if (downloadHandlerBuffer.isHttpError || downloadHandlerBuffer.isNetworkError)
            {
                string[] name = new string[] { "Couldn't Download Level: ", World.Name, " (", downloadHandlerBuffer.error, ")" };
                worldSetup.CancelSetup(string.Concat(name));
            }
            else
            {
                File.WriteAllBytes(string.Concat(World.MapFolderName, "/", World.MapFileName), downloadHandlerBuffer.downloadHandler.data);
            }
            downloadHandlerBuffer = null;
        }
        timing.End();
        Timing timing1 = Timing.Start("Loading World");

        if (World.Procedural && World.CanLoadFromDisk())
        {
            LoadingScreen.Update("LOADING WORLD");
            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            World.Serialization.Load(string.Concat(World.MapFolderName, "/", World.MapFileName));
            World.Cached = true;
        }
        timing1.End();
        if (World.Cached && 9 != World.Serialization.Version)
        {
            object[] version = new object[] { "World cache version mismatch: ", (uint)9, " != ", World.Serialization.Version };
            UnityEngine.Debug.LogWarning(string.Concat(version));
            World.Serialization.Clear();
            World.Cached = false;
            if (World.CanLoadFromUrl())
            {
                worldSetup.CancelSetup(string.Concat("World File Outdated: ", World.Name));
            }
        }
        if (World.Cached && string.IsNullOrEmpty(World.Checksum))
        {
            World.Checksum = World.Serialization.Checksum;
        }
        if (World.Cached)
        {
            World.InitSize(World.Serialization.world.size);
        }
        if (worldSetup.terrain)
        {
            TerrainGenerator terrainGenerator = worldSetup.terrain.GetComponent <TerrainGenerator>();
            if (terrainGenerator)
            {
                worldSetup.terrain     = terrainGenerator.CreateTerrain();
                worldSetup.terrainMeta = worldSetup.terrain.GetComponent <TerrainMeta>();
                worldSetup.terrainMeta.Init(null, null);
                worldSetup.terrainMeta.SetupComponents();
                worldSetup.CreateObject(worldSetup.decorPrefab);
                worldSetup.CreateObject(worldSetup.grassPrefab);
                worldSetup.CreateObject(worldSetup.spawnPrefab);
            }
        }
        Timing timing2 = Timing.Start("Spawning World");

        if (World.Cached)
        {
            LoadingScreen.Update("SPAWNING WORLD");
            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            TerrainMeta.HeightMap.FromByteArray(World.GetMap("terrain"));
            TerrainMeta.SplatMap.FromByteArray(World.GetMap("splat"));
            TerrainMeta.BiomeMap.FromByteArray(World.GetMap("biome"));
            TerrainMeta.TopologyMap.FromByteArray(World.GetMap("topology"));
            TerrainMeta.AlphaMap.FromByteArray(World.GetMap("alpha"));
            TerrainMeta.WaterMap.FromByteArray(World.GetMap("water"));
            IEnumerator enumerator = World.Spawn(0.2f, (string str) => LoadingScreen.Update(str));
            while (enumerator.MoveNext())
            {
                yield return(enumerator.Current);
            }
            TerrainMeta.Path.Clear();
            TerrainMeta.Path.Roads.AddRange(World.GetPaths("Road"));
            TerrainMeta.Path.Rivers.AddRange(World.GetPaths("River"));
            TerrainMeta.Path.Powerlines.AddRange(World.GetPaths("Powerline"));
            enumerator = null;
        }
        timing2.End();
        Timing timing3 = Timing.Start("Processing World");

        if (componentsInChildren.Length != 0)
        {
            for (int i = 0; i < (int)componentsInChildren.Length; i++)
            {
                ProceduralComponent proceduralComponent = componentsInChildren[i];
                if (proceduralComponent && proceduralComponent.ShouldRun())
                {
                    uint num = (uint)((ulong)World.Seed + (long)i);
                    LoadingScreen.Update(proceduralComponent.Description.ToUpper());
                    yield return(CoroutineEx.waitForEndOfFrame);

                    yield return(CoroutineEx.waitForEndOfFrame);

                    yield return(CoroutineEx.waitForEndOfFrame);

                    Timing timing4 = Timing.Start(proceduralComponent.Description);
                    if (proceduralComponent)
                    {
                        proceduralComponent.Process(num);
                    }
                    timing4.End();
                    proceduralComponent = null;
                }
            }
        }
        timing3.End();
        Timing timing5 = Timing.Start("Saving World");

        if (ConVar.World.cache && World.Procedural && !World.Cached)
        {
            LoadingScreen.Update("SAVING WORLD");
            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            World.Serialization.world.size = World.Size;
            World.AddPaths(TerrainMeta.Path.Roads);
            World.AddPaths(TerrainMeta.Path.Rivers);
            World.AddPaths(TerrainMeta.Path.Powerlines);
            World.Serialization.Save(string.Concat(World.MapFolderName, "/", World.MapFileName));
        }
        timing5.End();
        Timing timing6 = Timing.Start("Calculating Checksum");

        if (string.IsNullOrEmpty(World.Serialization.Checksum))
        {
            LoadingScreen.Update("CALCULATING CHECKSUM");
            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            yield return(CoroutineEx.waitForEndOfFrame);

            World.Serialization.CalculateChecksum();
        }
        timing6.End();
        if (string.IsNullOrEmpty(World.Checksum))
        {
            World.Checksum = World.Serialization.Checksum;
        }
        Timing timing7 = Timing.Start("Ocean Patrol Paths");

        LoadingScreen.Update("OCEAN PATROL PATHS");
        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        if (!BaseBoat.generate_paths || !(TerrainMeta.Path != null))
        {
            UnityEngine.Debug.Log("Skipping ocean patrol paths, baseboat.generate_paths == false");
        }
        else
        {
            TerrainMeta.Path.OceanPatrolFar = BaseBoat.GenerateOceanPatrolPath(200f, 8f);
        }
        timing7.End();
        Timing timing8 = Timing.Start("Finalizing World");

        LoadingScreen.Update("FINALIZING WORLD");
        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        if (worldSetup.terrainMeta)
        {
            worldSetup.terrainMeta.BindShaderProperties();
            worldSetup.terrainMeta.PostSetupComponents();
            TerrainMargin.Create();
        }
        World.Serialization.Clear();
        timing8.End();
        LoadingScreen.Update("DONE");
        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        yield return(CoroutineEx.waitForEndOfFrame);

        if (worldSetup)
        {
            GameManager.Destroy(worldSetup.gameObject, 0f);
        }
    }
    public IEnumerator InitCoroutine()
    {
        WorldSetup worldSetup = this;

        if (World.CanLoadFromUrl())
        {
            Debug.Log((object)("Loading custom map from " + World.Url));
        }
        else
        {
            Debug.Log((object)("Generating procedural map of size " + (object)World.Size + " with seed " + (object)World.Seed));
        }
        ProceduralComponent[] components = (ProceduralComponent[])((Component)worldSetup).GetComponentsInChildren <ProceduralComponent>(true);
        Timing downloadTimer             = Timing.Start("Downloading World");

        if (World.Procedural && !World.CanLoadFromDisk() && World.CanLoadFromUrl())
        {
            LoadingScreen.Update("DOWNLOADING WORLD");
            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            UnityWebRequest request = UnityWebRequest.Get(World.Url);
            request.set_downloadHandler((DownloadHandler) new DownloadHandlerBuffer());
            request.Send();
            while (!request.get_isDone())
            {
                LoadingScreen.Update("DOWNLOADING WORLD " + (request.get_downloadProgress() * 100f).ToString("0.0") + "%");
                yield return((object)CoroutineEx.waitForEndOfFrame);
            }
            if (!request.get_isHttpError() && !request.get_isNetworkError())
            {
                File.WriteAllBytes(World.MapFolderName + "/" + World.MapFileName, request.get_downloadHandler().get_data());
            }
            else
            {
                worldSetup.CancelSetup("Couldn't Download Level: " + World.Name + " (" + request.get_error() + ")");
            }
            request = (UnityWebRequest)null;
        }
        downloadTimer.End();
        Timing loadTimer = Timing.Start("Loading World");

        if (World.Procedural && World.CanLoadFromDisk())
        {
            LoadingScreen.Update("LOADING WORLD");
            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            World.Serialization.Load(World.MapFolderName + "/" + World.MapFileName);
            World.Cached = true;
        }
        loadTimer.End();
        if (World.Cached && 8U != World.Serialization.get_Version())
        {
            Debug.LogWarning((object)("World cache version mismatch: " + (object)8U + " != " + (object)World.Serialization.get_Version()));
            World.Serialization.Clear();
            World.Cached = false;
            if (World.CanLoadFromUrl())
            {
                worldSetup.CancelSetup("World File Outdated: " + World.Name);
            }
        }
        if (World.Cached && string.IsNullOrEmpty(World.Checksum))
        {
            World.Checksum = World.Serialization.get_Checksum();
        }
        if (World.Cached)
        {
            World.InitSize((uint)((WorldSerialization.WorldData)World.Serialization.world).size);
        }
        if (Object.op_Implicit((Object)worldSetup.terrain))
        {
            TerrainGenerator component = (TerrainGenerator)worldSetup.terrain.GetComponent <TerrainGenerator>();
            if (Object.op_Implicit((Object)component))
            {
                worldSetup.terrain     = component.CreateTerrain();
                worldSetup.terrainMeta = (TerrainMeta)worldSetup.terrain.GetComponent <TerrainMeta>();
                worldSetup.terrainMeta.Init((Terrain)null, (TerrainConfig)null);
                worldSetup.terrainMeta.SetupComponents();
                worldSetup.CreateObject(worldSetup.decorPrefab);
                worldSetup.CreateObject(worldSetup.grassPrefab);
                worldSetup.CreateObject(worldSetup.spawnPrefab);
            }
        }
        Timing spawnTimer = Timing.Start("Spawning World");

        if (World.Cached)
        {
            LoadingScreen.Update("SPAWNING WORLD");
            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            TerrainMeta.HeightMap.FromByteArray(World.GetMap("terrain"));
            TerrainMeta.SplatMap.FromByteArray(World.GetMap("splat"));
            TerrainMeta.BiomeMap.FromByteArray(World.GetMap("biome"));
            TerrainMeta.TopologyMap.FromByteArray(World.GetMap("topology"));
            TerrainMeta.AlphaMap.FromByteArray(World.GetMap("alpha"));
            TerrainMeta.WaterMap.FromByteArray(World.GetMap("water"));
            IEnumerator worldSpawn = World.Spawn(0.2f, (Action <string>)(str => LoadingScreen.Update(str)));
            while (worldSpawn.MoveNext())
            {
                yield return(worldSpawn.Current);
            }
            TerrainMeta.Path.Clear();
            TerrainMeta.Path.Roads.AddRange(World.GetPaths("Road"));
            TerrainMeta.Path.Rivers.AddRange(World.GetPaths("River"));
            TerrainMeta.Path.Powerlines.AddRange(World.GetPaths("Powerline"));
            worldSpawn = (IEnumerator)null;
        }
        spawnTimer.End();
        Timing procgenTimer = Timing.Start("Processing World");

        if (components.Length != 0)
        {
            for (int i = 0; i < components.Length; ++i)
            {
                ProceduralComponent component = components[i];
                if (Object.op_Implicit((Object)component) && component.ShouldRun())
                {
                    uint seed = (uint)((ulong)World.Seed + (ulong)i);
                    LoadingScreen.Update(component.Description.ToUpper());
                    yield return((object)CoroutineEx.waitForEndOfFrame);

                    yield return((object)CoroutineEx.waitForEndOfFrame);

                    yield return((object)CoroutineEx.waitForEndOfFrame);

                    Timing timing = Timing.Start(component.Description);
                    if (Object.op_Implicit((Object)component))
                    {
                        component.Process(seed);
                    }
                    timing.End();
                    component = (ProceduralComponent)null;
                }
            }
        }
        procgenTimer.End();
        Timing saveTimer = Timing.Start("Saving World");

        if (ConVar.World.cache && World.Procedural && !World.Cached)
        {
            LoadingScreen.Update("SAVING WORLD");
            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            ((WorldSerialization.WorldData)World.Serialization.world).size = (__Null)(int)World.Size;
            World.AddPaths((IEnumerable <PathList>)TerrainMeta.Path.Roads);
            World.AddPaths((IEnumerable <PathList>)TerrainMeta.Path.Rivers);
            World.AddPaths((IEnumerable <PathList>)TerrainMeta.Path.Powerlines);
            World.Serialization.Save(World.MapFolderName + "/" + World.MapFileName);
        }
        saveTimer.End();
        Timing checksumTimer = Timing.Start("Calculating Checksum");

        if (string.IsNullOrEmpty(World.Serialization.get_Checksum()))
        {
            LoadingScreen.Update("CALCULATING CHECKSUM");
            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            yield return((object)CoroutineEx.waitForEndOfFrame);

            World.Serialization.CalculateChecksum();
        }
        checksumTimer.End();
        if (string.IsNullOrEmpty(World.Checksum))
        {
            World.Checksum = World.Serialization.get_Checksum();
        }
        Timing oceanTimer = Timing.Start("Ocean Patrol Paths");

        LoadingScreen.Update("OCEAN PATROL PATHS");
        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        if (BaseBoat.generate_paths && Object.op_Inequality((Object)TerrainMeta.Path, (Object)null))
        {
            TerrainMeta.Path.OceanPatrolFar = BaseBoat.GenerateOceanPatrolPath(200f, 8f);
        }
        else
        {
            Debug.Log((object)"Skipping ocean patrol paths, baseboat.generate_paths == false");
        }
        oceanTimer.End();
        Timing finalizeTimer = Timing.Start("Finalizing World");

        LoadingScreen.Update("FINALIZING WORLD");
        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        if (Object.op_Implicit((Object)worldSetup.terrainMeta))
        {
            worldSetup.terrainMeta.BindShaderProperties();
            worldSetup.terrainMeta.PostSetupComponents();
            TerrainMargin.Create();
        }
        World.Serialization.Clear();
        finalizeTimer.End();
        LoadingScreen.Update("DONE");
        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        yield return((object)CoroutineEx.waitForEndOfFrame);

        if (Object.op_Implicit((Object)worldSetup))
        {
            GameManager.Destroy(((Component)worldSetup).get_gameObject(), 0.0f);
        }
    }
Exemple #6
0
    private void Start()
    {
        TerrainSaveData data = TerrainGenerator.TerrainGenerate();

        TerrainGenerator.CreateTerrain(data);
    }