Simple 2D procedural galaxy map

Hello everyone. I’m new to unity, a bit less to programming in general (but far from being an expert).

For a long period, i was in my free time trying to develop a 4x space civilization management game in c# with visual studio. For the last few days i was trying to convert my game to a unity project, but i’m struggling with somes aspects.

I’m liking Unity so far, but that editor make me feel way more stupider that i am (i hope). For example, i’m currently stuck on the galaxy map. What i want is simple enough, just a canvas, which i can change the size with my code (since it depend on the galaxy size parameter), contained in a scrollview so i can zoom and navigate in the map.

Why can’t i simply draw my systemDot (simple sprite render with a white dot) where i want ?

Here is the code :

    galaxyMap.sizeDelta = new Vector2(galaxy.Size, galaxy.Size);
    
foreach(StarSystem system in galaxy.Systems)
{
    Vector2 position = system.Coordinates/100f;
    Instantiate(systemDot, position, transform.rotation, galaxyMap);
    Text systemName = Instantiate(systemNameText, position, transform.rotation, galaxyMap);
    systemName.text = system.Name;
}

galaxyMap is a RectTransform attached to a panel. I don’t know if that the thing to do to set the size of the content of the viewport of a scrollview, but it seems to work.

What i cant get to work is the pixels coordinates.

In the GalaxyGenerator code, the coordinates range from -1000 to 1000, as integer. If i simply instantiate my systemDot with these coordinates, i can’t find my point anywhere. But, if i divide by 100f, i start to see my galaxy, but some of the systemDot are out of the galaxyMap. Heck, a simple instantiate with 0,0 as coordinates and the galaxyMap as parent doesn’t even show on the map.

Do someone has an idea or the right way to generate the sprite where i want ? Sorry if it’s not that clear, to be honest, the whole pixels management in unity is still not to me (i know there are screenPoint, worldPoint, rectPoint… i tried some of these but i had no simple solution for what seems to be a fairly simple problem.)

Here is my hierarchy :
99106-capture.jpg

My canvas is a screen space camera (i don’t know if that important) with constant pixel size and my camera is orthographic.

I’d ask why you’re using a canvas to draw? That’s for user interface stuff like buttons. For a map, I’d use a texture on a quad or sprite. You also shouldn’t be using pixel coordinates because these will change depending on platform. Unity doesn’t work in screen space using pixels like a conventional 2D approach. Use world-space coordinates and set the camera to view it.

From the sounds of it, I think you could do with stepping back from your port and just doing a few tutorials on Unity to see how it’s supposed to work. Then you can come back to your 4X conversion with a good understanding on how differently you may have to do things. Perhaps have one project just dabbling where you learn a technique, then back to 4X to implement it. That’s what I do exploring something new for my game.

Even if the map is just some sprites object on a image background ? I used canvas cause it seemed the only object to be shown to the scene (the scrollview doesn’t show if not under a canvas).

I don’t quite get what you mean by using world-space coordinates instead of pixels. What should i do with say, a system with x:1400 and y:600 as coordinates, for example ?

You’re quite right, i’m fairly underlevel in unity. I already followed easy tutorial but it sure is not enough right now, but i quite like to challenge myself by trying on my own, even though on this case, i’m lost.

Do you think Unity would be a good editor for a full 2D UI game without graphic anyway? The 4x game i’m making has only a galaxymap with dots and a systemmap with simple objects, the rest is complete UI (menu, tabs and labels, no graphic at all).
Visual studio seems to offer a better range of UI component (tabview, listview), but unity is orientated toward game creation, and may offer already done aspect, such as map scrolling by drag (i had to implement it myself in studio).