Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Kehos · Jul 24, 2012 at 12:57 PM · c#

How to do a selectable map?

Hello, I'm starting with a board game in C# like Risk and I need a selectable world map to put the armies on each region. I have a Raycasting function to select each country but I need to know how to build the board and make the countries selectable.

I have a board like this: http://2.bp.blogspot.com/-vtEHvcmS-Ac/TtHk0IvsxoI/AAAAAAAAAnw/V6e_eGfmCac/s1600/Risk+II+Game+Board.jpg

And I want to be able to select the countries separately, like they're objects on their own. Do you know any ways to do that?

Thanks for the help!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Bunny83 · Jul 24, 2012 at 03:03 PM

If you want to select countries, i suggest you use a color mask texture. Just an additional texture where each country / region is painted in a different solid color. A grayscale map would be enough. So for example one area that should be selectable is drawn with an RGB value of 20,20,20 the next one would be 21,21,21.

Now you can use the texcoord from your raycast to find the "color" in the colormap. Just use Texture2D.GetPixel to read the color. Just convert it into a Color32 to get byte values for each component. This can be used as index. For this you need of course paint each area / country with a certain color value so you can identify the right area.

This is the most accurate way. Another way is of course to use GUI buttons or Rects, but it won't match the actual shape.

edit

Since some are confused by this approach, here's it a bit more in detail:

I've just created an example selection texture for the map the OP posted. It uses the green channel to specify the "continent" and the red channel (followed by blue) to specify the region. I used a color steps of 20 so each color channel can have 13 different states (12 are only used because 0== black is never used as region). That means i could have 12*12*12 regions which equals 1728.

In my example to get the continent and the region index i just do

     // C#
     int continent  = (int)(pickedColor.g*12.75f+0.5f);
     int regionLow  = (int)(pickedColor.r*12.75f+0.5f);
     int regionHigh = (int)(pickedColor.b*12.75f+0.5f);
     int region = regionHigh*13 + regionLow;

You could use any colorstep but the smaller it gets the more likely errors will come in (see compression issues mentioned in the comments). In theory you could have around 16 million regions in one map. Just to put that in relation: that would be a 4000*4000 texture with every pixel has a distinct color.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Lukas-Barbarossa · Jul 24, 2012 at 03:23 PM 1
Share

Thats such an interesting idea. No use for it right now, but I'll store that for later. Nice one.

avatar image Bunny83 · Jul 24, 2012 at 04:02 PM 1
Share

Here's a monochrome version of the map. I'm not an artist so i kinda suck when it comes to Photoshop ;) You can probably extract the desired areas more accurate.

Now you just need to color each area with a different color. I'm not sure what areas / countries you need / want since this map lacks of many borderlines, especially in europe. All in all the map looks a bit "morphed".

$$anonymous$$eep in $$anonymous$$d that the color map doesn't nees to match perfectly. The user won't see the colormap. It just should match your desired regions.

avatar image Kehos · Jul 24, 2012 at 04:13 PM 0
Share

I think I explianed myself wrong. I have a plane with that picture of the world map attached as an image. I'm looking for some way to make a map where the countries are selectable objects, or in another case a way to make colliders for each one of them onto that.

Is there any way to create planes with the country shapes easily?

avatar image Kehos · Jul 24, 2012 at 04:14 PM 0
Share

Wow that is grat Bunny83, thank you a lot. I'll try with it!! :)

avatar image ScroodgeM · Aug 30, 2012 at 10:09 PM 1
Share

be aware about texture compression 8) built-in compression will make a piece of garbage from texture with such color mask for countries 8) better to disable compression at all for this.

Show more comments
avatar image
1

Answer by Lukas-Barbarossa · Jul 24, 2012 at 02:16 PM

Or, if you want a 3D map, you could make your main landmass a 3D model and then cut it up in Maya or Max into it's constituent territories. Remember though, if you want a 'cliff face' thickness to your map, to make it as a poly not a plane.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Kronnect · Jul 24, 2015 at 07:53 AM

You can use World Political Map which includes source code (C#) for highlighting and choosing countries with just one line call :-) https://www.assetstore.unity3d.com/en/#!/content/41890

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by m.alekseev · Jul 24, 2012 at 01:17 PM

Try to make them buttons or GUITextures.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by jc_lvngstn · Jul 24, 2012 at 07:18 PM

I'd check out NGUI. You know how most board games like this have a map/board with old style drawings on the sides, like a whale or waves in the ocean? With NGUI, you would set up a panel with that background texture. Then, you could have each country as a UI element. NGUI can highlight them, make them bounce a little, etc as you select or mouseover them. You just specify the colors, the effect, etc.

Basically, each country would be a button or some sort of UI element. You could create them using something like blender, or use something from the asset store to trace them. And the cool thing is...they would have shader effects. Make them glow during combat, or something.

Really...once you figure it out, it's incredibly powerful. And you could make the entire MAP/game do things like slide into view, spin on game over, all kinds of stuff. Easy. Zoom down to ground level to watch the fighting, if you want to get fancy!

In a nutshell: User NGUI, and have each country as a part of the UI. NGUI can handle the rest, and tell you which one you have selected, mouseover, etc.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

12 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Initialising List array for use in a custom Editor 1 Answer

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

Flip over an object (smooth transition) 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges