Exemple #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
    }
Exemple #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();
        }
        //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, 100f);
        }
        EditorGUI.EndDisabledGroup();

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

    //    List<Vector3> vertices = new List<Vector3>();
    //    List<int> indices = new List<int>();
    //    Geometry.Icosahedron(vertices, indices);

    //    for (int i = 0; i <= 5; i++)
    //    {
    //        for (int v = 0; v < vertices.Count; v++)
    //        {
    //            vertices[v] = vertices[v].normalized;
    //        }

    //        vertexData[i] = AssetDatabase.LoadAssetAtPath<PlanetVertexData>("Assets/HexPlanet/VertexData/Lvl" + i.ToString() + ".asset");
    //        vertexData[i].Vertices = new List<Vector3>(vertices);
    //        vertexData[i].Indices = new List<int>(indices);
    //        Geometry.Subdivide(vertices, indices, true);
    //    }
    //}

    //void LoadVertexData()
    //{
    //    PlanetVertexData[] vertexData = new PlanetVertexData[6];

    //    for(int i = 0; i <= 5; i++)
    //    {
    //        vertexData[i] = AssetDatabase.LoadAssetAtPath<PlanetVertexData>("Assets/HexPlanet/VertexData/Lvl" + i.ToString() + ".asset");
    //    }
    //}

    #endregion

    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        if (!planet.GenerateAsSingleMesh)
        {
            planet.GenerateTileColliders = EditorGUILayout.Toggle("Generate Tile Colliders", planet.GenerateTileColliders);

            // Drop down for collider type
            if (planet.GenerateTileColliders)
            {
                EditorGUI.indentLevel++;
                planet.TileColliderType = (TileColliderType)EditorGUILayout.EnumPopup("Tile Collider Type: ", planet.TileColliderType);
                EditorGUI.indentLevel--;
            }
        }

        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 Planet"))
        {
            planet.BuildPlanet();
        }

        EditorGUI.EndDisabledGroup();

        EditorGUI.BeginDisabledGroup(!planet.tilesGenerated);
        //Random region generation
        if (GUILayout.Button("Generate Random Regions"))
        {
            planet.generateRandomRegions();
        }
        //Delete tiles
        if (GUILayout.Button("Delete Tiles") && planet.tilesGenerated)
        {
            planet.deleteTiles();
            //Reset the scale slider to 1 when deleting
            planet.setWorldScale(1f);
        }
        EditorGUI.EndDisabledGroup();

        //Scale slider
        planet.planetScale = EditorGUILayout.Slider("Planet Scale", planet.planetScale, 0.011f, 10f);
        planet.setWorldScale(planet.planetScale);

        EditorGUILayout.Space();
        // Save prefab
        EditorGUILayout.BeginHorizontal();
        PrefabPath = EditorGUILayout.TextField("Path to prefab", PrefabPath);
        if (GUILayout.Button("Save to Prefab"))
        {
            string path = PrefabPath + planet.gameObject.name + ".prefab";

            // Check if prefab already exists
            if (AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)))
            {
                //Create dialog to ask if User is sure they want to overwrite existing prefab
                if (EditorUtility.DisplayDialog("Are you sure?", "The prefab already exists. Do you want to overwrite it?", "Yes", "No"))
                {
                    SavePlanetAsPrefab(path);
                }
            }
            else
            {
                SavePlanetAsPrefab(path);
            }
        }
        EditorGUILayout.EndHorizontal();

        //Ensure that the hexplanet's lists arent destroyed when playmode is entered
        if (GUI.changed)
        {
            EditorUtility.SetDirty(planet);
            serializedObject.ApplyModifiedProperties();
        }
    }