Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Use Texture2D to create an array of Vector2 for Planar/Quad based Strategy Tiles

Discussion in '2D' started by Lamprey, Aug 10, 2017.

  1. Lamprey

    Lamprey

    Joined:
    May 26, 2015
    Posts:
    36
    I did a lot of modding for Paradox's grand strategy games, and I like their semi-static provincial generation system, that being based entirely on building terrain from pixels. I was looking through the Script References on Texture2D and found that there is no functionality on how to find only pixels of a certain color and output their coordinates as a Vector2. The idea behind what I'd use these for is pretty straightforward, yet I need the Vector2 array before I can keep going. Any ideas on how I could accomplish this, or alternate methods I should pursue are welcome, thanks in advance.

    Example sprite of what I want the texture data from:
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
  3. Lamprey

    Lamprey

    Joined:
    May 26, 2015
    Posts:
    36
    Thank you for the reply. I was just about to update this thread, as I solved my own issues. Originally the editor hung on a for loop around the use of GetPixel, but after switching from a Color to Transperancy it began to function again. After that I made my own function to sort the vertices and read about Delaunay Triangulation for Concave Polygons. With the polygons working, I partitioned my map into smaller regions due to the instability of the holes, and it is all functioning correctly. If anyone wants my source, or the articles I read on Delaunay Triangulation, I will link them.
    Only problem remaining is the UV, but I don't need a UV for my project.

    Source File:


    Finished Screenshots from Editor: