theoretical question

Options
I'm starting a new game development and this would be my 3rd photon integrated game so I'm bit familiar with pun.
as for now started building up the single player and moved to the multiplayer and i notice its not the proper way.

1. should i just build the multiplayer first, and in single player just call the rpc method instead of sending rpc other the network? or photon does that automatically? or is there a better way to do so?

2. is there a way to detect photon destroy on client side that didn't call the destroy on that game object right before its being removed? like in showing a mine explosion on all clients when a destroy has been called? i can send rpc that instantiate that explosion on all clients and remove that game object from view to lets say position.x 3k, then invoke the destroy from owner but i was wondering maybe there is a better way?

Comments

  • donnysobonny
    Options
    Personally, I think that it does require some thought when building a game that will at some point be multi player, as there are some things you will want to plan ahead for. I don't think it's really possible to simply take a game that is built for single player and slap PUN on it to make it multi player (at least not without a good bit of work).

    There are a number of things that you need to be aware of when it comes to making your single player game multi player. You mention RPCs already, which is good, as they are a very useful tool to you. There are a number of other options when it comes to building interactions between players while using PUN.

    1. The PhotonView component.

    The PhotonView component is used to easily serialize a GameObject over the network. It's basic usage allows you to add the PhotonView component to a GameObject in Unity, and tell it to serialize the GameObject's position/rotation/scale over the network. It's more complex usage allows you to serialize more complex information over the server such as custom variables and even custom classes.

    2. PhotonNetwork.Instantiate

    This ties closely into the PhotonView component. It replaces Unity's own Instantiate method with a method that allows you to instantiate an object over the network. Objects that you instantiate should have a PhotonView component, as this is required so that the server can identify the object uniquely, and be able to serialize it. Using the PhotonView component and PhotonNetwork.Instantiate methods in combination can be very efficient and powerful.

    3. RPCs

    RPCs are great if you want to call a method on a PhotonNetwork.Instantiate-ed object over the network (provided that the object has a PhotonView). They can be pretty tricky to wrap your head around at first but ultimately I would personally suggest to use RPCs for infrequent interactions between players.

    4. Events

    Events are (to my knowledge) quite new to Photon, and are an alternative to RPCs. An event doesn't require PhotonNetwork.Instantiate-ed object or a PhotonView. Instead, events target PhotonPlayers independently. They work by having one client raise an event (using PhotonNetwork.RaiseEvent), and all other clients listening for events to be raised, and doing something. I personally really like events due to not relying on networked objects and PhotonViews

    5. Custom Properties

    In PUN, you are able to assign custom properties to both the Room and PhotonPlayer objects independently. These custom properties generally have different purposes, but allow you to add bits of information to Rooms and PhotonPlayers which can easily be accessed.

    Custom properties can be a bit tricky to use at times, and I would recommend using them in a case where you want to store information against a Room or PhotonPlayer which doesn't change very often.


    You will find plenty more information on these interaction tools in the PUN tutorials, examples and documentation. This should give you some ideas on how to get started though.
  • vadim
    Options
    Hi,

    1. Check PUN offline mode: http://doc.exitgames.com/zh-cn/pun/curr ... d-un#ompun
    2. You may try handle destroy in OnDestroy method but your current approach is fine, no reasons to change it.