• 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
0
Question by dzed · Aug 13, 2012 at 04:48 PM · map

Best way to create clickable real world map?

Hi, Is there a sample or best practice in creating a clickable real world map? Where you can scroll and select countries or even different parts of the countries.

Here is a screenshot of "HOI III" game from Paradox.

alt text

Comment
Add comment · Show 1
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 Kronnect · Feb 03, 2016 at 10:17 PM 0
Share

There are two goals here: 1- Detecting the country or province 2- Highlighting it.

Problem with using textures is the resolution needed to have sharp frontiers so it looks good. And using big textures will be an issue in mobile.

I'd recommend (I'm the creator) Terrain Grid System or even World $$anonymous$$ap Strategy $$anonymous$$it. You can learn more about them on kronnect.com. Both assets cover what you need and work procedurally for both detecting and highlighting with no Textures involved although they add a transparent layer in real time with color or custom texture to your province in realtime.

3 Replies

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

Answer by Dragonlance · Aug 13, 2012 at 05:35 PM

Yes!

  1. Use a rectangle with(!!) UV mapping on it. (This will be your map)

  2. Use it normal with your diffuse shader or whatever you like to represent it.

  3. Give it a mesh collider!

  4. Have an aspect ratio fitting texture with color encoded shapes (so i.e. 0x00FB0022 would be Berlin area color) - This texture will not be applied anywhere, it is just for looking up the color (and with it the area).

  5. Do a raycast from screen like http://docs.unity3d.com/Documentation/ScriptReference/RaycastHit-textureCoord.html

  6. Use the UV coordinate to look up the color on your reference texture (the one that was not aplied anywhere).

  7. Look up the found color in your Color<->Area Map

  8. ...

  9. Profit?

You know what area the player clicked.

This method can be used with basically any other shape. You only need to have a color encoded lookup texture fitting to the uv coordinates on the object. You could use this for decals, target zone testing etc. But it has to be a mesh collider, what could be a performance problem for very complex objects. But in this case you will be fine.

The bigger problem is to mark the areas as selected. For this you need to have a transparent (for nicer look) detail overlay texture for your map. Use your reference color texture and copy just that colors shape (defined by its color values) out of it, do 0 alpha on the other pixels, give the non alpha pics the color of your desire and copy it additive on the into the detail overlay texture.

Have fun!

Comment
Add comment · Show 3 · 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 Muuskii · Aug 13, 2012 at 06:21 PM 0
Share

As the guy in Peggle said: "Cleverly done!"

avatar image dzed · Aug 13, 2012 at 07:32 PM 0
Share

Just to make sure that I have understood you right. What you are suggesting is to have a huge texture(image) of world where every country or region has a unique color? And then by using Texture2D.getPixel try to match the color with a color table, to find the selected region? And concerning the overlay/selection graphics basically do the same find the x,y pixels of the "selected" color and set the rest pixels to alpha=0.

avatar image Dragonlance · Aug 14, 2012 at 07:18 PM 0
Share

Yes that's pretty much it.

You use uv coords from the RaycastHit to look up on another texture with unique color for each area. This color can be used to a) find out what area was clicked b) extract the shape of the area to paint a selection in another texture.

You can not use Texture2D.getPixel(x,y) directly, because u,v coordinates are not x,y coordinates. Either you calculate u,v to x,y or you use GetPixelBilinear(u,v).

After that you can use GetPixels or GetPixels32 (Color32 is faster because of no need for float conversion) to get the pixels and from that the overlay shape.

There are a lot of things that could be optimized after you did implement the basics.

  • Speed: You can do that GetPixels32 one time at startup of the campaign map scene and leave it i memory. - Then you allways extract shapes from that Color32 array.

  • $$anonymous$$emory: You could have a map of bounding rects for u,v coords and just check the desired bounding rect for fine tuning (many will ovverleap so you could use GetPixels on a bounding rect)

  • $$anonymous$$ore optimizations you may think up yourself, or maybe somebody has other ideas?

avatar image
0

Answer by sketchers1 · Aug 13, 2012 at 06:15 PM

OOH OOH! I did the same thing! So in addition to what dragonlace said or being part of it, this is what I had asked: http://answers.unity3d.com/questions/165131/gui-on-click.html

and It works perfectly!

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 Loius · Aug 13, 2012 at 05:12 PM

I'd recommend OnMouseEnter / OnMouseExit.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Assigning UV Map to model at runtime 0 Answers

Trying to tile terrain, encountering strange axis flipping 0 Answers

Base Map Distance for terrain 1 Answer

Open World RPG Project 5 Answers

Universe Gameworld 0 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