void OnGUI() { if (avoidGUI) { return; } // Do autoresizing of GUI layer GUIResizer.AutoResize(); // Check whether a country or city is selected, then show a label with the entity name and its neighbours (new in V4.1!) if (map.countryHighlighted != null || map.cityHighlighted != null || map.provinceHighlighted != null) { string text; if (map.cityHighlighted != null) { if (!map.cityHighlighted.name.Equals(map.cityHighlighted.province)) // show city name + province & country name { text = "City: " + map.cityHighlighted.name + " (" + map.cityHighlighted.province + ", " + map.countries[map.cityHighlighted.countryIndex].name + ")"; } else // show city name + country name (city is a capital with same name as province) { text = "City: " + map.cityHighlighted.name + " (" + map.countries[map.cityHighlighted.countryIndex].name + ")"; } } else if (map.provinceHighlighted != null) { text = map.provinceHighlighted.name + ", " + map.countryHighlighted.name; List <Province> neighbours = map.ProvinceNeighboursOfCurrentRegion(); if (neighbours.Count > 0) { text += "\n" + EntityListToString <Province>(neighbours); } } else if (map.countryHighlighted != null) { text = map.countryHighlighted.name + " (" + map.countryHighlighted.continent + ")"; List <Country> neighbours = map.CountryNeighboursOfCurrentRegion(); if (neighbours.Count > 0) { text += "\n" + EntityListToString <Country>(neighbours); } } else { text = ""; } float x, y; if (minimizeState) { x = Screen.width - 130; y = Screen.height - 140; } else { x = Screen.width / 2.0f; y = Screen.height - 40; } // shadow GUI.Label(new Rect(x - 1, y - 1, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 1, y + 2, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 2, y + 3, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 3, y + 4, 0, 10), text, labelStyleShadow); // texst face GUI.Label(new Rect(x, y, 0, 10), text, labelStyle); } // Assorted options to show/hide frontiers, cities, Earth and enable country highlighting GUI.Box(new Rect(0, 0, 150, 200), ""); map.showFrontiers = GUI.Toggle(new Rect(10, 20, 150, 30), map.showFrontiers, "Toggle Frontiers"); map.showEarth = GUI.Toggle(new Rect(10, 50, 150, 30), map.showEarth, "Toggle Earth"); map.showCities = GUI.Toggle(new Rect(10, 80, 150, 30), map.showCities, "Toggle Cities"); map.showCountryNames = GUI.Toggle(new Rect(10, 110, 150, 30), map.showCountryNames, "Toggle Labels"); map.enableCountryHighlight = GUI.Toggle(new Rect(10, 140, 170, 30), map.enableCountryHighlight, "Enable Highlight"); // buttons background color GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); // Add button to toggle Earth texture if (GUI.Button(new Rect(10, 170, 160, 30), " Change Earth style", buttonStyle)) { map.earthStyle = (EARTH_STYLE)(((int)map.earthStyle + 1) % 4); } // Add buttons to show the color picker and change colors for the frontiers or fill if (GUI.Button(new Rect(10, 210, 160, 30), " Change Frontiers Color", buttonStyle)) { colorPicker.showPicker = true; changingFrontiersColor = true; } if (GUI.Button(new Rect(10, 250, 160, 30), " Change Fill Color", buttonStyle)) { colorPicker.showPicker = true; changingFrontiersColor = false; } if (colorPicker.showPicker) { if (changingFrontiersColor) { map.frontiersColor = colorPicker.setColor; } else { map.fillColor = colorPicker.setColor; } } // Add a button which demonstrates the navigateTo functionality -- pass the name of a country // For a list of countries and their names, check map.Countries collection. if (GUI.Button(new Rect(10, 290, 180, 30), " Fly to Australia (Country)", buttonStyle)) { FlyToCountry("Australia"); } if (GUI.Button(new Rect(10, 325, 180, 30), " Fly to Mexico (Country)", buttonStyle)) { FlyToCountry("Mexico"); } if (GUI.Button(new Rect(10, 360, 180, 30), " Fly to New York (City)", buttonStyle)) { FlyToCity("New York", "United States of America"); } if (GUI.Button(new Rect(10, 395, 180, 30), " Fly to Madrid (City)", buttonStyle)) { FlyToCity("Madrid", "Spain"); } // Slider to show the new set zoom level API in V4.1 GUI.Button(new Rect(10, 430, 85, 30), " Zoom Level", buttonStyle); float prevZoomLevel = zoomLevel; GUI.backgroundColor = Color.white; zoomLevel = GUI.HorizontalSlider(new Rect(100, 445, 80, 85), zoomLevel, 0, 1, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); if (zoomLevel != prevZoomLevel) { prevZoomLevel = zoomLevel; map.SetZoomLevel(zoomLevel); } if (GUI.Button(new Rect(10, 475, 180, 30), " Alpha Texture Fill", buttonStyle)) { TransparentTextureFill(); } // Add a button to colorize countries if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 20, 180, 30), " Colorize Europe", buttonStyle)) { for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++) { if (map.countries[countryIndex].continent.Equals("Europe")) { Color color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0.5f); map.ToggleCountrySurface(countryIndex, true, color); } } } // Colorize random country and fly to it if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 60, 180, 30), " Colorize Random", buttonStyle)) { int countryIndex = Random.Range(0, map.countries.Length); Color color = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f)); map.ToggleCountrySurface(countryIndex, true, color); map.BlinkCountry(countryIndex, Color.green, Color.black, 0.8f, 0.2f); } // Add a button to colorize countries if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 100, 180, 30), " Colorize Continents", buttonStyle)) { Dictionary <string, Color> continentColors = new Dictionary <string, Color>(); for (int countryIndex = 0; countryIndex < map.countries.Length; countryIndex++) { Country country = map.countries[countryIndex]; Color continentColor; if (continentColors.ContainsKey(country.continent)) { continentColor = continentColors[country.continent]; } else { continentColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 0.5f); continentColors.Add(country.continent, continentColor); } map.ToggleCountrySurface(countryIndex, true, continentColor); } } // Button to clear colorized countries if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 140, 180, 30), " Reset countries", buttonStyle)) { map.HideCountrySurfaces(); } // Tickers sample if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 180, 180, 30), " Tickers Sample", buttonStyle)) { TickerSample(); } // Decorator sample if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 220, 180, 30), " Texture Sample", buttonStyle)) { TextureSample(); } // Moving the Earth sample if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 260, 180, 30), " Toggle Minimize", buttonStyle)) { ToggleMinimize(); } // Add marker sample (Sprite) if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 300, 180, 30), " Add Marker (2D Sprite)", buttonStyle)) { AddMarkerSpriteOnRandomCity(); } // Add marker sample (Game Object) if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 340, 180, 30), " Add Marker (Game Object)", buttonStyle)) { AddMarker3DObjectOnRandomCity(); } // Add marker sample (Text) if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 380, 180, 30), " Add Marker (Text)", buttonStyle)) { AddMarkerTextOnRandomPlace(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 420, 180, 30), " Add Trajectories", buttonStyle)) { AddTrajectories(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 460, 180, 30), " One Country Borders", buttonStyle)) { ShowCountryBorders(); } }
// Update is called once per frame void OnGUI () { // Do autoresizing of GUI layer GUIResizer.AutoResize (); // Check whether a country or city is selected, then show a label with the entity name and its neighbours (new in V4.1!) if (map.cellHighlighted != null) { int cellIndex = map.cellHighlightedIndex; string text = "Cell index = " + cellIndex + ", row = " + map.cells [cellIndex].row + ", col = " + map.cells [cellIndex].column + ", center = " + map.cells [cellIndex].center; // shadow float x, y; x = Screen.width / 2.0f; y = Screen.height - 40; GUI.Label (new Rect (x - 1, y - 1, 0, 10), text, labelStyleShadow); GUI.Label (new Rect (x + 1, y + 2, 0, 10), text, labelStyleShadow); GUI.Label (new Rect (x + 2, y + 3, 0, 10), text, labelStyleShadow); GUI.Label (new Rect (x + 3, y + 4, 0, 10), text, labelStyleShadow); // texst face GUI.Label (new Rect (x, y, 0, 10), text, labelStyle); } // Assorted options to show/hide frontiers, cities, Earth and enable country highlighting GUI.Box (new Rect (5, 0, 175, 180), ""); map.showGrid = GUI.Toggle (new Rect (10, 20, 170, 30), map.showGrid, "Toggle Grid"); map.enableCellHighlight = GUI.Toggle (new Rect (10, 50, 170, 30), map.enableCellHighlight, "Enable Cell Highlighting"); if (GUI.Toggle (new Rect (10, 80, 170, 30), mode == ACTION_MODE.FadeOut, "Toggle Fade Circle")) { mode = ACTION_MODE.FadeOut; } if (GUI.Toggle (new Rect (10, 110, 170, 30), mode == ACTION_MODE.Flash, "Toggle Flash Circle")) { mode = ACTION_MODE.Flash; } if (GUI.Toggle (new Rect (10, 140, 170, 30), mode == ACTION_MODE.Blink, "Toggle Blink Circle")) { mode = ACTION_MODE.Blink; } if (GUI.Toggle (new Rect (10, 170, 170, 30), mode == ACTION_MODE.Paint, "Toggle Colorize Cell")) { mode = ACTION_MODE.Paint; } if (GUI.Toggle (new Rect (10, 200, 170, 30), mode == ACTION_MODE.FadeCountry, "Toggle Fade Country")) { mode = ACTION_MODE.FadeCountry; } // buttons background color GUI.backgroundColor = new Color (0.1f, 0.1f, 0.3f, 0.95f); // Clear painted cells if (GUI.Button (new Rect (10, 230, 160, 30), " Clear Cells", buttonStyle)) { map.HideCellSurfaces (); } // Add buttons to show the color picker and change colors for the cells if (GUI.Button (new Rect (10, 265, 160, 30), " Change Grid Color", buttonStyle)) { colorPicker.showPicker = true; } if (colorPicker.showPicker) { map.gridColor = colorPicker.setColor; } // Slider to show the new set zoom level API in V4.1 GUI.Button (new Rect (10, 300, 85, 30), " Cells", buttonStyle); GUI.backgroundColor = Color.white; int prevCellsCount = (int)cellsCount; cellsCount = (int)GUI.HorizontalSlider (new Rect (100, 315, 80, 30), cellsCount, 32, 512, sliderStyle, sliderThumbStyle); if ((int)cellsCount != prevCellsCount) { map.gridColumns = (int)cellsCount; map.gridRows = map.gridColumns / 2; cellsCount = map.gridColumns; } GUI.backgroundColor = new Color (0.1f, 0.1f, 0.3f, 0.95f); // Slider to show the new set zoom level API in V4.1 GUI.Button (new Rect (10, 335, 85, 30), " Zoom Level", buttonStyle); float prevZoomLevel = zoomLevel; GUI.backgroundColor = Color.white; zoomLevel = GUI.HorizontalSlider (new Rect (100, 350, 80, 30), zoomLevel, 0, 1, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color (0.1f, 0.1f, 0.3f, 0.95f); if (zoomLevel != prevZoomLevel) { prevZoomLevel = zoomLevel; map.SetZoomLevel (zoomLevel); } }
void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); string msg = "Select destination cell!"; GUI.Label(new Rect(10, 10, 300, 20), msg, labelStyle); if (map.cellHighlightedIndex >= 0) { msg = "Current cell: " + map.cellHighlightedIndex; GUI.Label(new Rect(10, 30, 300, 20), msg, labelStyle); } if (GUI.Button(new Rect(10, 60, 100, 20), "Draw Barrier", buttonStyle)) { // Very basic sample of how to draw some lines to create a visual barrier over the edges of some hexagonal cells map.AddLine(101133, CELL_SIDE.Top, Color.cyan, 0.1f); map.AddLine(101134, CELL_SIDE.TopLeft, Color.cyan, 0.1f); map.AddLine(101134, CELL_SIDE.Top, Color.cyan, 0.1f); map.AddLine(101134, CELL_SIDE.TopRight, Color.cyan, 0.1f); map.AddLine(101135, CELL_SIDE.Top, Color.cyan, 0.1f); map.AddLine(101136, CELL_SIDE.TopLeft, Color.cyan, 0.1f); map.AddLine(101136, CELL_SIDE.Top, Color.cyan, 0.1f); map.AddLine(101136, CELL_SIDE.TopRight, Color.cyan, 0.1f); // Set crossing costs for barrier for each edge. Note that here I'm using the hard coded cell numbers for this example. If you change the number of rows or columns of the grid // this will obviously fail. int cost = 10000; map.PathFindingCellSetSideCost(101133, 101645, cost); map.PathFindingCellSetSideCost(101134, 101645, cost); map.PathFindingCellSetSideCost(101134, 101646, cost); map.PathFindingCellSetSideCost(101134, 101647, cost); map.PathFindingCellSetSideCost(101135, 101647, cost); map.PathFindingCellSetSideCost(101136, 101647, cost); map.PathFindingCellSetSideCost(101136, 101648, cost); map.PathFindingCellSetSideCost(101136, 101649, cost); } if (GUI.Button(new Rect(130, 60, 120, 20), "Show Mountains", buttonStyle)) { ShowMountains(); } GUI.Label(new Rect(10, 100, 250, 30), "Non colored terrain cost: 1 point"); GUI.Label(new Rect(10, 120, 250, 30), "Green movement cost: 2 point"); GUI.Label(new Rect(10, 140, 250, 30), "Gray movement cost: 3 points"); GUI.Label(new Rect(10, 160, 250, 30), "Press R to show movement range."); if (tank.maxSearchCost > 5 || ((int)Time.time) % 2 != 0) { GUI.Label(new Rect(10, 180, 250, 30), "Tank move points: " + tank.maxSearchCost); } if (tank.maxSearchCost < 5) { GUI.Label(new Rect(10, 200, 250, 30), "Press M to add more move points."); } if (GUI.Button(new Rect(270, 60, 120, 20), " Build Road", buttonStyle)) { BuildRoad(); } }
/// <summary> /// UI Buttons /// </summary> void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); GUI.Box(new Rect(0, 0, 160, 160), ""); bool prev = showLinearPath; showLinearPath = GUI.Toggle(new Rect(10, 20, 150, 30), showLinearPath, "Show Linear Path"); if (showLinearPath != prev && showLinearPath) { showRoutePath = false; pathArcElevation = 2f; } prev = showRoutePath; showRoutePath = GUI.Toggle(new Rect(180, 20, 150, 30), showRoutePath, "Show Route Path"); if (showRoutePath != prev && showRoutePath) { showLinearPath = false; pathArcElevation = 0; } enableClickToMoveTank = GUI.Toggle(new Rect(350, 20, 200, 30), enableClickToMoveTank, "Enable Move Tank On Click"); showCircle = GUI.Toggle(new Rect(570, 20, 120, 30), showCircle, "Show Circle"); showEndCap = GUI.Toggle(new Rect(690, 20, 120, 30), showEndCap, "Show End Cap"); // Path line controls GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(10, 50, 150, 30), " Drawing Duration", buttonStyle); GUI.backgroundColor = Color.white; pathDrawingDuration = GUI.HorizontalSlider(new Rect(10, 85, 150, 35), pathDrawingDuration, 0, 3f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(10, 120, 150, 30), " Arc Elevation", buttonStyle); GUI.backgroundColor = Color.white; pathArcElevation = GUI.HorizontalSlider(new Rect(10, 155, 150, 35), pathArcElevation, 0, 10f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(10, 190, 150, 30), " Line Width", buttonStyle); GUI.backgroundColor = Color.white; pathLineWidth = GUI.HorizontalSlider(new Rect(10, 225, 150, 35), pathLineWidth, 0.05f, 1f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(10, 260, 150, 30), " Dash Size", buttonStyle); GUI.backgroundColor = Color.white; pathDashInterval = GUI.HorizontalSlider(new Rect(10, 295, 150, 35), pathDashInterval, 0, 0.01f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(10, 330, 150, 30), " Dash Speed", buttonStyle); GUI.backgroundColor = Color.white; pathDashAnimationDuration = GUI.HorizontalSlider(new Rect(10, 365, 150, 35), pathDashAnimationDuration, 0, 2f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 50, 150, 30), " Circle Radius", buttonStyle); GUI.backgroundColor = Color.white; circleRadius = GUI.HorizontalSlider(new Rect(GUIResizer.authoredScreenWidth - 190, 85, 150, 35), circleRadius, 0, 1000f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 120, 150, 30), " Circle Ring Start", buttonStyle); GUI.backgroundColor = Color.white; circleRingStart = GUI.HorizontalSlider(new Rect(GUIResizer.authoredScreenWidth - 190, 155, 150, 35), circleRingStart, 0, 1f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 190, 150, 30), " Circle Ring End", buttonStyle); GUI.backgroundColor = Color.white; circleRingEnd = GUI.HorizontalSlider(new Rect(GUIResizer.authoredScreenWidth - 190, 225, 150, 35), circleRingEnd, 0, 1f, sliderStyle, sliderThumbStyle); GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); }
void Start() { // Get a reference to the World Map API: map = WMSK.instance; // UI Setup - non-important, only for this demo labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D>("GUI/thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; // Prepare line texture lineMaterialAerial = Instantiate(Resources.Load <Material>("PathLine/aerialPath")); lineMaterialGround = Instantiate(Resources.Load <Material>("PathLine/groundPath")); // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); // plug our mouse click listener - it will be used to move the tank to target destination map.OnClick += (float x, float y, int buttonIndex) => { if (enableClickToMoveTank) { MoveTankWithPathFinding(new Vector2(x, y)); } }; // plug our mouse move listener - it received the x,y map position of the mouse map.OnMouseMove += (float x, float y) => { // while tank is moving avoid showing paths if (tank.isMoving) { return; } // if show linear path is enabled, then just show a straight (or curved line if arc elevation is specified) from tank to destination if (showLinearPath) { UpdateLinearPathLine(x, y); } else { // show route path is enabled, then we'll compute the path and draw a line that pass through those points UpdateRoutePathLine(x, y); } }; map.CenterMap(); // Drop the tank on the Tibet DropTankOnCity(); }
void OnGUI() { GUIResizer.AutoResize(); GUI.Box(new Rect(10, 10, 460, 40), "Click on any cell to add it to the country", labelStyle); }
// Update is called once per frame void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); // Check whether a country or city is selected, then show a label with the entity name and its neighbours (new in V4.1!) if (map.countryHighlighted != null || map.cityHighlighted != null || map.provinceHighlighted != null) { string text; if (map.cityHighlighted != null) { if (!map.cityHighlighted.name.Equals(map.cityHighlighted.province)) // show city name + province & country name { text = "City: " + map.cityHighlighted.name + " (" + map.cityHighlighted.province + ", " + map.countries[map.cityHighlighted.countryIndex].name + ")"; } else // show city name + country name (city is a capital with same name as province) { text = "City: " + map.cityHighlighted.name + " (" + map.countries[map.cityHighlighted.countryIndex].name + ")"; } } else if (map.provinceHighlighted != null) { text = map.provinceHighlighted.name + ", " + map.countryHighlighted.name; List <Province> neighbours = map.ProvinceNeighboursOfCurrentRegion(); if (neighbours.Count > 0) { text += "\n" + EntityListToString <Province>(neighbours); } } else if (map.countryHighlighted != null) { text = map.countryHighlighted.name + " (" + map.countryHighlighted.continent + ")"; List <Country> neighbours = map.CountryNeighboursOfCurrentRegion(); if (neighbours.Count > 0) { text += "\n" + EntityListToString <Country>(neighbours); } } else { text = ""; } float x, y; x = Screen.width / 2.0f; y = Screen.height - 40; // shadow GUI.Label(new Rect(x - 1, y - 1, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 1, y + 2, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 2, y + 3, 0, 10), text, labelStyleShadow); GUI.Label(new Rect(x + 3, y + 4, 0, 10), text, labelStyleShadow); // text face GUI.Label(new Rect(x, y, 0, 10), text, labelStyle); } Rect rect = new Rect(10, 10, 500, 20); if (!autoExpand) { GUI.Box(rect, ""); GUI.Label(rect, " Left click to select principal country. Right click another country to merge."); } // buttons background color GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); // Add button to toggle Earth texture if (autoExpand) { string countryName = (principalCountryIndex >= 0 && principalCountryIndex < map.countries.Length) ? map.countries[principalCountryIndex].name : ""; if (GUI.Button(new Rect(10, 10, 300, 30), " Stop Expansion of " + countryName, buttonStyle)) { autoExpand = false; } } else { if (GUI.Button(new Rect(10, 40, 160, 30), " Automate Expansion", buttonStyle)) { autoExpand = true; StartCoroutine(StartExpansion()); } if (GUI.Button(new Rect(10, 75, 160, 30), " Transfer Country Demo", buttonStyle)) { StartCoroutine(TransferCountry()); } if (GUI.Button(new Rect(10, 110, 80, 30), " Reset Map", buttonStyle)) { map.ReloadData(); map.Redraw(); } } }
/// <summary> /// UI Buttons /// </summary> void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); GUI.Box(new Rect(0, 0, 160, 160), ""); bool prev = enableAddTowerOnClick; enableAddTowerOnClick = GUI.Toggle(new Rect(10, 20, 150, 30), enableAddTowerOnClick, "Enable Tower On Click"); if (enableAddTowerOnClick && prev != enableAddTowerOnClick) { enableClickToMoveTank = false; enableClickToMoveShip = false; } prev = enableClickToMoveTank; enableClickToMoveTank = GUI.Toggle(new Rect(180, 20, 200, 30), enableClickToMoveTank, "Enable Move Tank On Click"); if (enableClickToMoveTank && prev != enableClickToMoveTank) { enableAddTowerOnClick = false; enableClickToMoveShip = false; } prev = enableClickToMoveShip; enableClickToMoveShip = GUI.Toggle(new Rect(390, 20, 200, 30), enableClickToMoveShip, "Enable Move Ship On Click"); if (enableClickToMoveShip && prev != enableClickToMoveShip) { enableAddTowerOnClick = false; enableClickToMoveTank = false; } // buttons background color GUI.backgroundColor = new Color(0.1f, 0.1f, 0.3f, 0.95f); if (GUI.Button(new Rect(10, 50, 150, 30), " Add Random Tower", buttonStyle)) { AddRandomTower(); } if (GUI.Button(new Rect(10, 90, 150, 30), " Add Random Sprite", buttonStyle)) { AddRandomSprite(); } if (GUI.Button(new Rect(10, 130, 150, 30), " Drop Tank on Paris", buttonStyle)) { DropTankOnCity(); } if (GUI.Button(new Rect(10, 170, 150, 30), " Move Tank & Follow", buttonStyle)) { MoveTankAndFollow(); } if (ship != null) { if (GUI.Button(new Rect(10, 210, 150, 30), " Destroy Ship", buttonStyle)) { DestroyImmediate(ship.gameObject); ship = null; } } else { if (GUI.Button(new Rect(10, 210, 150, 30), " Launch Ship", buttonStyle)) { LaunchShip(); } } if (GUI.Button(new Rect(10, 250, 150, 30), " Start Flight", buttonStyle)) { ShowAirplane(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 50, 180, 30), " Mass Create", buttonStyle)) { MassCreate(50); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 90, 180, 30), " Find France Coast", buttonStyle)) { FindFranceCoast(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 130, 180, 30), " Find France-Germany Line", buttonStyle)) { FindFranceGermanyLine(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 170, 180, 30), " Find France-Germany Provinces", buttonStyle)) { FindFranceGermanyProvinces(); } if (GUI.Button(new Rect(GUIResizer.authoredScreenWidth - 190, 210, 180, 30), " Add Sphere", buttonStyle)) { AddSphere(); } }
void Start() { // Get a reference to the World Map API: map = WMSK.instance; // UI Setup - non-important, only for this demo labelStyle = new GUIStyle(); labelStyle.alignment = TextAnchor.MiddleCenter; labelStyle.normal.textColor = Color.white; labelStyleShadow = new GUIStyle(labelStyle); labelStyleShadow.normal.textColor = Color.black; buttonStyle = new GUIStyle(labelStyle); buttonStyle.alignment = TextAnchor.MiddleLeft; buttonStyle.normal.background = Texture2D.whiteTexture; buttonStyle.normal.textColor = Color.white; colorPicker = gameObject.GetComponent <ColorPicker>(); sliderStyle = new GUIStyle(); sliderStyle.normal.background = Texture2D.whiteTexture; sliderStyle.fixedHeight = 4.0f; sliderThumbStyle = new GUIStyle(); sliderThumbStyle.normal.background = Resources.Load <Texture2D>("GUI/thumb"); sliderThumbStyle.overflow = new RectOffset(0, 0, 8, 0); sliderThumbStyle.fixedWidth = 20.0f; sliderThumbStyle.fixedHeight = 12.0f; // setup GUI resizer - only for the demo GUIResizer.Init(800, 500); /* Register events: this is optionally but allows your scripts to be informed instantly as the mouse enters or exits a country, province or city */ map.OnCellEnter += (int cellIndex) => Debug.Log("Entered cell #" + cellIndex + " at row " + map.cells[cellIndex].row + ", column " + map.cells[cellIndex].column); map.OnCellExit += (int cellIndex) => Debug.Log("Exited cell #" + cellIndex + " at row " + map.cells[cellIndex].row + ", column " + map.cells[cellIndex].column); map.OnCellClick += (int cellIndex, int buttonIndex) => { int row = map.cells[cellIndex].row; int col = map.cells[cellIndex].column; Debug.Log("Clicked cell #" + cellIndex + " at row " + row + ", column " + col + ", center = " + map.cells[cellIndex].center); switch (mode) { case ACTION_MODE.Blink: case ACTION_MODE.FadeOut: case ACTION_MODE.Flash: AnimateCells(row, col); break; case ACTION_MODE.Paint: PaintCurrentCell(); break; case ACTION_MODE.FadeCountry: PaintCurrentCountry(); break; } }; map.SetZoomLevel(0.3f); map.showGrid = true; cellsCount = map.gridColumns; // Simple benchmark // Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt")); // map.gridMinDistance = 0; // map.gridMaxDistance = 100; // map.gridRows = 128; // map.gridColumns = 256; // Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt")); // for (int k=0;k<map.cells.Length;k++) { // map.ToggleCellSurface(k, true, Color.red); // } // Debug.Log (System.DateTime.Now.ToString("hh:mm:ss.fff tt")); }
/// <summary> /// UI Buttons /// </summary> void OnGUI() { // Do autoresizing of GUI layer GUIResizer.AutoResize(); GUI.Box(new Rect(10, 10, 460, 40), "Left click: look at. Right click: fire!", labelStyle); }