Ejemplo n.º 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
    }
    void OnEnable()
    {
        planet = (Hexsphere)target;

        if (planet.tilesGenerated && !planet.TileMeshesRestored)
        {
            // Restore Tile Meshes
            foreach (Tile t in planet.tiles)
            {
                t.RestoreMesh();
            }

            planet.TileMeshesRestored = true;
        }
    }
Ejemplo n.º 3
0
        public override bool GenerateTerrain(Hexsphere hexPlanet)
        {
            if (hexPlanet == null)
            {
                return(false);
            }

            //Hack...
            float scale = (hexPlanet.detailLevel == 4) ? 2.0f : 2.8f;

            hexPlanet.setWorldScale(scale);

            this.BuildPlates();

            this.AdjustTerrainHeights();

            this.AssignTerrainTypes();

            return(true);
        }
Ejemplo n.º 4
0
        public void PlateSetup(Hexsphere hexPlanet, Tile center, bool _isWater, float _extrusion, Color color, Dictionary <int, Tile> usedTiles = null)
        {
            this.HexPlanet         = hexPlanet;
            this.Center            = center;
            this.Tiles             = new List <Tile>();
            this.Queue             = new List <Tile>();
            this.TileMap           = new Dictionary <int, Tile>();
            this.EdgeTiles         = new List <Tile>();
            this.PressureEdgeTiles = new List <Tile>();

            this.isWater   = _isWater;
            this.extrusion = _extrusion;

            //this.plateColor = Random.ColorHSV();
            this.plateColor = color;

            this.AddTile(center, usedTiles);

            //center.setColor(Color.red);
            this.PressureDir = Random.insideUnitCircle;
        }
Ejemplo n.º 5
0
    //Build up list of buildings per tile
    public List <List <string> > getTileBuildings()
    {
        List <List <string> > tb    = new List <List <string> > ();
        Transform             world = GameObject.Find("Hexsphere").transform;
        Hexsphere             hex   = world.GetComponent <Hexsphere> ();

        for (int i = 0; i < hex.TileObjects.Count; i++)
        {
            List <string> b = hex.TileObjects [i].GetComponent <Tile> ().buildings;
            if (b != null)
            {
                tb.Add(b);
            }
            else
            {
                tb.Add(new List <string> {
                    "", "", ""
                });
            }
        }
        return(tb);
    }
Ejemplo n.º 6
0
 void OnEnable()
 {
     planet = (Hexsphere)target;
 }
Ejemplo n.º 7
0
 public override bool GenerateTerrain(Hexsphere hexPlanet)
 {
     return(false);
 }
Ejemplo n.º 8
0
    public override void OnInspectorGUI()
    {
        if (PlanetEditor == null)
        {
            PlanetEditor = target as PlanetTools;
        }

        if (Planet == null)
        {
            Planet = PlanetEditor.GetComponent <Hexsphere>();
        }

        if (ToggleButtonStyleNormal == null)
        {
            ToggleButtonStyleNormal  = "Button";
            ToggleButtonStyleToggled = new GUIStyle(ToggleButtonStyleNormal);
            ToggleButtonStyleToggled.normal.background = ToggleButtonStyleToggled.active.background;
        }

        GUILayout.Label("Tile Tools", EditorStyles.boldLabel);
        GUILayout.BeginVertical(EditorStyles.helpBox);
        GUILayout.BeginHorizontal();

        //if(GUILayout.Button("Select", Mode == ToolMode.Select ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        //{
        //    Mode = ToolMode.Select;
        //}

        //if (GUILayout.Button("Paint Material", Mode == ToolMode.PaintMaterial ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        //{
        //    Mode = ToolMode.PaintMaterial;
        //}

        if (GUILayout.Button("Paint Group ID", PlanetEditor.Mode == ToolMode.PaintGroupID ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        {
            PlanetEditor.Mode = ToolMode.PaintGroupID;
        }

        if (GUILayout.Button("Paint Height", PlanetEditor.Mode == ToolMode.PaintHeight ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        {
            PlanetEditor.Mode = ToolMode.PaintHeight;
        }

        if (GUILayout.Button("Paint Object", PlanetEditor.Mode == ToolMode.PaintObject ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        {
            PlanetEditor.Mode = ToolMode.PaintObject;
        }

        if (GUILayout.Button("Paint Nav Weight", PlanetEditor.Mode == ToolMode.PaintNavWeight ? ToggleButtonStyleToggled : ToggleButtonStyleNormal))
        {
            PlanetEditor.Mode      = ToolMode.PaintNavWeight;
            SelectedTileInfoOption = TileDisplayOptions.NavWeight;
        }

        GUILayout.EndHorizontal();
        GUILayout.EndVertical();

        switch (PlanetEditor.Mode)
        {
        case ToolMode.Select:
            break;

        case ToolMode.PaintMaterial:
            DrawPaintMaterialInspector();
            break;

        case ToolMode.PaintHeight:
            DrawPaintHeightInspector();
            break;

        case ToolMode.PaintGroupID:
            DrawPaintGroupInspector();
            break;

        case ToolMode.PaintObject:
            DrawPaintObjectInspector();
            break;

        case ToolMode.PaintNavWeight:
            DrawPaintNavWeightInspector();
            break;
        }
    }
Ejemplo n.º 9
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        Vector2 LatLong = tile.GetCoordinates();

        EditorGUILayout.LabelField("Tile Latitude", LatLong.x.ToString());
        EditorGUILayout.LabelField("Tile Longitude", LatLong.y.ToString());

        EditorGUI.BeginChangeCheck();
        GroupID = EditorGUILayout.IntField("Group ID: ", tile.GroupID);
        if (EditorGUI.EndChangeCheck())
        {
            for (int i = 0; i < targets.Length; i++)
            {
                Tile t = (Tile)targets[i];

                if (t != null)
                {
                    t.SetGroupID(GroupID);
                }
            }
        }

        //Place object interface
        EditorGUILayout.BeginHorizontal();
        objectToPlace = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Object to place", placeObjToolTip), objectToPlace, typeof(GameObject), true);
        if (GUILayout.Button("Place Object") && objectToPlace != null)
        {
            //If its a prefab, spawn it then place it
            if (EditorUtility.IsPersistent(objectToPlace))
            {
                if (targets.Length > 1)
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        GameObject o = Instantiate(objectToPlace) as GameObject;
                        Tile       t = (Tile)targets [i];
                        t.placeObject(o);
                    }
                }
                else
                {
                    GameObject o = Instantiate(objectToPlace) as GameObject;
                    tile.placeObject(o);
                }
            }
            //If it is a scene object, move its current instance to the tile
            else if (objectToPlace.activeInHierarchy)
            {
                // If multiple tiles are selected, clone the object and place on each tile
                if (targets.Length > 1)
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        GameObject o = Instantiate(objectToPlace) as GameObject;
                        Tile       t = (Tile)targets [i];
                        t.placeObject(o);
                    }
                }
                // If only a single tile is selected, move the original object to that tile
                else
                {
                    tile.placeObject(objectToPlace);
                }
            }
            //Clear the object slot
            objectToPlace = null;
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(5);
        //Extrude interface
        GUILayout.Label("Extrusion Tools", EditorStyles.boldLabel);
        // Set Extrusion Height
        EditorGUILayout.BeginHorizontal();
        absoluteExtrusionHeight = (float)EditorGUILayout.FloatField(new GUIContent("Set Absolute Height", absoluteExtrudeToolTip), absoluteExtrusionHeight);
        if (GUILayout.Button("Extrude"))
        {
            if (targets.Length > 1)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    Tile t = (Tile)targets[i];
                    t.SetExtrusionHeight(absoluteExtrusionHeight);
                }
            }
            else
            {
                tile.SetExtrusionHeight(absoluteExtrusionHeight);
            }
        }
        EditorGUILayout.EndHorizontal();
        // Add Height
        EditorGUILayout.BeginHorizontal();
        extrudeHeight = (float)EditorGUILayout.FloatField(new GUIContent("Add/Subtract Height", deltaExtrudeToolTipe), extrudeHeight);
        if (GUILayout.Button("Extrude"))
        {
            if (targets.Length > 1)
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    Tile t = (Tile)targets [i];
                    t.Extrude(extrudeHeight);
                }
            }
            else
            {
                tile.Extrude(extrudeHeight);
            }
        }
        EditorGUILayout.EndHorizontal();

        EditorGUI.indentLevel++;
        EditorGUILayout.LabelField("(Current Height): ", tile.ExtrudedHeight.ToString(), EditorStyles.miniLabel);
        EditorGUI.indentLevel--;

        if (tile.PlacedObjects.Count > 0 || targets.Length > 1)
        {
            if (GUILayout.Button("Delete All Placed Objects"))
            {
                for (int i = 0; i < targets.Length; i++)
                {
                    Tile t = (Tile)targets[i];
                    t.DeletePlacedObjects();
                }
            }
        }

        // Selection Tools
        if (targets.Length == 1)
        {
            ShowSelectionOptions = EditorGUILayout.Foldout(ShowSelectionOptions, "Selection Options");
        }

        if (ShowSelectionOptions)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.LabelField("Select all Tiles with: ", EditorStyles.miniLabel);
            EditorGUILayout.Space();

            SelectSamePathCost      = EditorGUILayout.Toggle("Same Path Cost", SelectSamePathCost);
            SelectSameNavigability  = EditorGUILayout.Toggle("Same Navigability", SelectSameNavigability);
            SelectSameGroupID       = EditorGUILayout.Toggle("Same Group ID", SelectSameGroupID);
            SelectSameExtrudeHeight = EditorGUILayout.Toggle("Same Extrusion Height", SelectSameExtrudeHeight);

            if (GUILayout.Button("Select Tiles") &&
                (SelectSameNavigability || SelectSamePathCost || SelectSameExtrudeHeight || SelectSameGroupID))
            {
                Hexsphere         parentPlanet  = tile.parentPlanet;
                List <GameObject> selectedTiles = new List <GameObject>();

                foreach (Tile t in parentPlanet.tiles)
                {
                    bool include = true;

                    if (SelectSameNavigability)
                    {
                        include &= t.navigable == tile.navigable;
                    }

                    if (SelectSamePathCost)
                    {
                        include &= t.pathCost == tile.pathCost;
                    }

                    if (SelectSameGroupID)
                    {
                        include &= t.GroupID == tile.GroupID;
                    }

                    if (SelectSameExtrudeHeight)
                    {
                        include &= t.ExtrudedHeight == tile.ExtrudedHeight;
                    }

                    if (include)
                    {
                        selectedTiles.Add(t.gameObject);
                    }
                }

                Selection.objects = selectedTiles.ToArray();
            }

            if (GUILayout.Button("Select Connected Group"))
            {
                List <Tile>       connectedGroup = tile.GetConnectedGroup();
                List <GameObject> groupObjs      = new List <GameObject>();
                foreach (Tile t in connectedGroup)
                {
                    groupObjs.Add(t.gameObject);
                }
                Selection.objects = groupObjs.ToArray();
            }
            EditorGUI.indentLevel--;
        }
    }
    private void OnSceneGUI()
    {
        if (PlanetEditor == null)
        {
            PlanetEditor = target as PlanetTools;
        }

        if (Planet == null)
        {
            Planet = PlanetEditor.GetComponent <Hexsphere>();
        }

        int controlId = GUIUtility.GetControlID(FocusType.Passive);

        // Shift to allow editing
        if (Event.current.shift)
        {
            IsEditing = true;

            if (Event.current.type == EventType.MouseDown)
            {
                MouseIsDown           = true;
                GUIUtility.hotControl = controlId;
                // Use the event
                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                MouseIsDown           = false;
                GUIUtility.hotControl = 0;
                // Use the event
                Event.current.Use();
            }

            if (Event.current.type == EventType.ScrollWheel && Event.current.control)
            {
                SetSelectCircleRadius(PlanetEditor.SelectRadius + Event.current.delta.y * 0.01f);
                GUIUtility.hotControl = controlId;
                Event.current.Use();
            }
            else
            {
                GUIUtility.hotControl = 0;
            }

            //RaycastSelect();
            CircleSelect();
        }
        // Shift is released
        else if (IsEditing)
        {
            IsEditing = false;

            if (LastHilightedTile != null)
            {
                LastHilightedTile.SetHighlight(false);
                LastHilightedTile = null;
            }

            foreach (Tile lastT in LastHilightedTiles)
            {
                lastT.SetHighlight(false);
            }
            LastHilightedTiles.Clear();

            AppliedActionTiles.Clear();
        }
    }
Ejemplo n.º 11
0
 public abstract bool GenerateTerrain(Hexsphere hexPlanet);