UNITY + PHOTON Sync scene unity in photon cloud - unity3d

How can I synchronize scenes of all players according to the first player who created the room?
Specifically. The items will be randomly generated on the creator's scene. All guests entering the room will sync.

You can use custom room properties for that, where you define all these random elements final state, and players joining the room, will read these custom properties and reproduce these elements as described in the room properties. Players currently in the room can listen to room property change callback and adjust realtime.
doc: https://doc.photonengine.com/en-us/pun/v2/gameplay/synchronization-and-state#custom_properties

Related

With Unity's InputSystem is there a way to discriminate between players when using c# events?

I am experimenting with Unity and have created a multi-player local coop environment. I have a Player Input Manger create a new player whenever a new device connects. These players have a Player Input component that is set to use c# events. Then I have some code that listen for the events and logs to the console. I want to be able to distinguish between players, but at the moment events get fired for every input on every device.
I have watched countless tutorials on the Input System, but local multiplayer never seemns to be addressed. All the solutions I can think off seem nasty. I can get it working with send, broadcast and unity's events, but I would like to know how to achive it with c# events.
I don't think you can through the event system, no.
However, if you use the Input Manager directly (i.e. Input.GetButtonDown()), then you can go into your project settings and set up the buttons and axes to be gamepad specific.
Essentially, what you need to do is duplicate all of the buttons and axes in the Project Settings Input Manager for however many players you want to support, and then go through them and set the Joystick index to a fixed custom value.
Then, instead of having, for example, a "Jump" button, you'll have "Jump 1" through "Jump 4", each unique to its own gamepad.
See the last entry in the Virtual Axes table for more info:
https://docs.unity3d.com/Manual/class-InputManager.html

Realtime Sharing of Pointer/Cursor of Each Player in Game Room Using PUN2/MRTK2 on Hololens 2

Is there a way to share each player's raycast pointer/cursor with the other players in realtime? I'm using PUN2 and MRTK2 and Hololens 2.
Approaches I've tried so far:
I tried a naïve approach of modifying the MRTK provided ShellHandRayPointer to contain a PhotonView and then using that on the MixedRealityToolkit object within the scene, but that seems to have no effect.
I've tried creating a cursor prefab based off of MRTK's CursorFocus in which I add a Surface Magnetism component (tracking the hands) and then instantiate this prefab for each player in PUN2's OnJoinedRoom callback. After the instantiation call, I add the object to a non-rendered layer for the player with the goal of hiding it for the local player but allowing it show up for other players. This seems to hide the object as expected when only one player is in the room, but when a second player joins, the first player then sees a cursor show up that tracks with their hand movement, which seems unexpected to me (of note is that I'm using one Hololens 2 headset with a computer acting as the second player). Though perhaps this "crossed" behavior is due to the Surface Magnetism component?
Thanks!
Step-by-step images of how I modified the ShellHandRayPointer with a PhotonView and then reattached to the MRTK system:
scene:
MRTK system:
MRTK system part 2: reference to cloned ShellHandRayPointer:
my cloned ShellHandRayPointer part 1:
PhotonView components expanded on the cloned ShellHandRayPointer:
Regarding how to share objects in Photon in real time, as far as I know, the real-time shared objects in Photon need to be instantiated by PhotonNetwork.Instantiate, but ShellHandRayPointer in MRTK is instantiated by Input system.
You can customize a copy of ShellHandRayPointer, map the position and rotation of ShellHandRayPointer to the copy at runtime and share this copy in Photon in real time.
The position and rotation of ShellHandRayPointer can be obtained in MixedRealityToolkit.InputSystem.DetectedInputSources. Or you can use Unity's methods to get this Game Object directly.
For the cursor, you can use the same method above to create a copy of the cursor and map its position and rotation.

Unity2D: Mirror Multiplying - How to view an opponent's screen in a match 3 game

I'm making my own match 3 multiplayer game, the concept is to have two people face off against each other person can face off another person by swapping tiles to make a line of the same form. I want to introduce multiplayer by connecting two players together and allowing each person to see their opponent's screen, as well as syncing their moves. So far, I have a simple match 3 game (I created one using different tutorials, mainly this playlist) and followed a simple multiplayer tutorial (Mirror) for a player to host or be a client. My problem is that I have no idea how to show both players their opponent's screen to each other. I even found an example of what I want the multiplayer mode in my game to be like. Can anyone point me in the right direction, please and thank you.
Additional information:
I'm using mirror for multiplayer
I created a network manager gameobject and added the necessary components to it. I also added the game pieces into the 'registered spawnable prefabs' and created an empty gameobject, called player for the player prefab.
Each game piece has a network transform and network identity component attached.
The player prefab object has a camera child under it to.
This is what I want my game to look like:
Overall, I want to have player's view each other's screen:
As you can see, both player's are connected, what I want to do it to allow each player see their opponent's screen. Does anyone have an idea on how I can do it?
Thank you! :)

Photon Multiplayer, Both players create their own rooms

I am using Photon with cocos2dx for making a multiplayer game. When I create room from one player, it creates room successfully and after 4 or 5 seconds when I join room from other player then both player join each other successfully and game starts. The problem comes when I start game from both sides together, both players thinks that there is no room exist they both create their own rooms and unable to join each other.
Thanks in advance.
You might want to use opJoinRoom, setting createIfNotExiststo true.
Doing so will have the first player create the room and the second one joining in.

How to set custom rules like difficulty level for GameCenter to find match

Need to set dynamically some rules of game and inform possible players (while GC searches for players/automatch) about those rules before the player connects. Lets say I want to host/start a game and i want to set some starting amount of betting units (10...1000), level of difficulty(0...10), scoring system (0..3) etc. I imagine this like a table with cells providing this information so player decides if he/she wants to join and play game with such rules. How to implement it?
AFAIK GKMatch uses only min and max number of players while searches for players and thats all. I could provide such information in invite but I need it for other players who r looking for game by themselves, like browsing existing games including rules. My game doesn't allow to join players since game is started but I need somehow to fill needed amount of players for session. Like if I want to play with only one player I start a game with number of players=2 (and some custom rules) so I need the GC to help me to find opposite player. And that player should be informed about my rules set before joining me.
You have 2 possibilities:
Use these properties of GKMatchRequest:
#property(nonatomic, assign) uint32_t playerAttributes
A mask that specifies the role that the local player would like to
play in the game.
If this value is 0 (the default), this property is ignored.
If the value is nonzero, then automatching uses the value as a mask
that restricts the role the player can play in the group. Automatching
with player attributes follows two rules:
A new player can only be added to the match if the bitwise AND of that
player’s mask and the mask of any player already in the match equals
0x00000000. Players are added to the match until the bitwise OR of the
masks of all the players in the match equals 0xFFFFFFFF. For more
information, see Game Kit Programming Guide.
#property(nonatomic, assign) NSUInteger playerGroup
A number identifying a subset of players
allowed to join the match.
If your game sets the playerGroup property, only players whose
requests share the same playerGroup value are automatched by Game
Center. You can use any values you want for player groups. For
example, you could define different playerGroup values to implement
any of the following filters:
A game could restrict players based on skill level. A game that
provides multiple games could use it to filter players into the
specific game they want to play. A game with multiple victory
conditions (for example, Capture-The-Flag, Survival) could match
players to others interested in the same rules. A game that provides
bonus content through in-app purchase could match players who own the
same content with each other.
This allows for some game configuration before searching for players.
For complex rules you need to send the configuration data after the match has been found and the players are connected (see GKMatch API). You need to use the reliable transmission mode here.
You could also combine these 2 ideas.