예제 #1
0
    //World loading sequence
    public void loadSavedWorld(List <TileStat> ts, int worldSeed)
    {
        Hexsphere world = GameObject.Find("Hexsphere").GetComponent <Hexsphere> ();

        world.setWorldScale(1);       //Shrink world (to handle resizing issue);
        world.deleteTiles();          //Clear world
        world.BuildPlanet();          //Build base tiles

        //If no save, generate new world
        if (ts == null)
        {
            int seed = (int)UnityEngine.Random.Range(0, Mathf.Pow(2, 16)); //New random world seed
            UnityEngine.Random.InitState(seed);
            world.generateRandomRegions();                                 //Generate biomes randomly
            world.randomizeAllItems();                                     //Generate food placements randomly
        }

        //If save, load tile stats
        else
        {
            UnityEngine.Random.InitState(worldSeed);
            int count = 0;
            //Loop through tile objects of parent planet
            foreach (Transform t in world.transform)
            {
                if (t.GetComponent <Tile> ())
                {
                    t.GetComponent <Tile> ().setColor(ts [count].biome);                //Update tile biome from save
                    t.GetComponent <Tile> ().item         = ts [count].item;            //Update tile food from save
                    t.GetComponent <Tile> ().itemRevealed = ts [count].revealed;        //Show food if tile is searched
                    t.GetComponent <Tile> ().buildings    = ts [count].buildings;       //Update tile buildings from save
                    count++;
                }
            }
        }
        world.setWorldScale(5);       //Resize planet to full
        world.extrudeLand();          //Raise tiles based on biome

        //Placing food and building models
        foreach (Transform t in world.transform)
        {
            if (t.GetComponent <Tile> ())
            {
                if (t.GetComponent <Tile> ().itemRevealed)
                {
                    PlaceResourceDecoration(t.GetComponent <Tile> ()); //If tile is searched, place food model
                    PlaceBuildingDecorations(t);                       //If tile has buildings, place models for those
                }
            }
        }

        lc.ManageWorldLights();          //After placing buildings, update their lights for daytime
        mc.calculateEarnings();          //Update money-per-second based on loaded buildings
    }
예제 #2
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EditorGUILayout.LabelField("Planet ID", planet.planetID.ToString());
        //mainPlanet.detailLevel = EditorGUILayout.IntSlider ("Detail Level", mainPlanet.detailLevel, 1, 4);
        EditorGUILayout.LabelField("Tile Count", planet.TileCount.ToString());

        EditorGUI.BeginDisabledGroup(planet.tilesGenerated);
        //Generate Planet
        if (GUILayout.Button("Generate Tiles") && !planet.tilesGenerated)
        {
            planet.BuildPlanet();
        }
        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(!planet.tilesGenerated);
        //Random region generation
        if (GUILayout.Button("Generate Random Regions") && planet.tilesGenerated)
        {
            planet.generateRandomRegions();
        }
        if (GUILayout.Button("Randomize Resources") && planet.tilesGenerated)
        {
            planet.randomizeAllItems();
        }
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Clear Decorations") && planet.tilesGenerated)
        {
            planet.clearDecorations();
        }
        if (GUILayout.Button("Place Decorations") && planet.tilesGenerated)
        {
            planet.placeDecorations();
        }
        EditorGUILayout.EndHorizontal();
        if (GUILayout.Button("Color Tiles") && planet.tilesGenerated)
        {
            planet.colorAllTiles();
        }
        if (GUILayout.Button("Count Biomes") && planet.tilesGenerated)
        {
            planet.countBiomes();
        }
        if (GUILayout.Button("Extrude Land") && planet.tilesGenerated)
        {
            planet.extrudeLand();
        }
        //Delete tiles
        if (GUILayout.Button("Delete Tiles") && planet.tilesGenerated)
        {
            planet.deleteTiles();
            //Reset the scale slider to 1 when deleting
            planet.setWorldScale(1f);
            EditorGUILayout.Slider("Planet Scale", 1f, 1f, 10f);
        }
        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(Application.isPlaying);
        //Scale slider
        planet.setWorldScale(EditorGUILayout.Slider("Planet Scale", planet.planetScale, 1f, 10f));
        EditorGUI.EndDisabledGroup();
        //Ensure that the hexplanet's lists arent destroyed when playmode is entered
        if (GUI.changed)
        {
            EditorUtility.SetDirty(planet);
            serializedObject.ApplyModifiedProperties();
        }
    }