I am looking for suggestions on how to properly program what I am about to describe because I feel if I start setting this up in a wrong manner this may take a lot of time to fix afterwards. So let me know what you think is the best way to approach this. Especially I am having the problems with the fact that this is single and multiplayer with a dedicated server architecture.
The game setup is like this:
Turn-based, single or multiplayer. There is an 8x8 board on which the player can place destroyers to manipulate the board. For each player, there is an instance of his own board which has the same puzzle-units placed on it for every player (the puzzle). Now every player tries to solve the puzzle as fast as possible. This is done by placing destroyers on it. When every player placed his destroyers or time ran out, the second phase starts and the placed destroyers can be triggered to solve the puzzle. For each puzzle (round) there are up to 3 turns per player; all players set their units at the same time and turns start for every player at the same time. My main question is how to properly setup the Player class and prefab and GUI so that every player has his own (indicating mostly the amount of available destroyers) and showing a reduced image of how well the other players are doing (e.g. showing remaining puzzle-units, time, points etc). There must be a singleton GameManager running on the dedicated server (been using this tutorial/impl) but I really don’t know how to connect everything in the Editor when -I think- Player needs to be a class and a prefab. The info sent to the server is mostly where the destroyers were placed, when the turn is over and which destroyer was then triggered. With additional buttons players are also able to send additional puzzle-units to other players.
Maybe I’m thinking too complicated but anyway I don’t know how to set this up, especially how the Player prefab will look like. The tutorial created a local player and a remote player prefab.
The big win for setting up dynamic UI components in Unity is always to set up a scene (or prefab if you insist) with ALL the different parts you might need in there, sized properly, positioned, etc. You might even put extra blank GameObjects into the UI hierarchy representing where key locations are: buttons, grids, corners, etc.
At runtime, your script would have reference to all the pieces and immediately call .SetActive(false) on the ones that are to be later cloned dynamically. Then your clone function will clone one of those “examples”, call .SetActuve(true) on it and move it where it needs to be.
REMEMBER: when you instantiate something in a UI hierarchy, ALWAYS use the overload of Instantiate() that takes two arguments: what to instantiate and what to parent it to. THEN take the reference you get back and move it or rotate it after it has been instantiated and parented. Doing the parenting all in one step will help keep you out of trouble.
What I dont understand from your answer is why I clone my GUI when the left 2/3 of it stay the same for every player every time. You are saying that I need 1 clone of a GUI for each player or are you just referring to the orange part (depends on the other players)?
Can I start with a Player object already present in the scene or do I have to spawn it explicitly?
I was speaking about the pieces as far as spawning them dynamically. You would have the template pieces pre-made and then spawn them for each player, and thee player can manage them from that point.
As far as what is a prefab and what is not, I would try and get it going by cloning objects in the scene first, and once you have a grasp for lifecycle and positioning of cloned UI objects, then introduce the extra hassle and overhead of making prefabs out of them, so that ultimately you could “skin” them if you like. I hate prefabs and find the workflow extremely awkward and error prone (even though it’s the Unity Way™), so unless I need something used in multiple scenes, I never make prefabs.