Пример #1
0
        public void SendNetworkEvent(Enumerators.NetworkEvent networkEvent, object[] data, bool all = true)
        {
            RaiseEventOptions raiseEventOptions = new RaiseEventOptions {
                Receivers = all ? ReceiverGroup.All : ReceiverGroup.Others
            };
            SendOptions sendOptions = new SendOptions {
                Reliability = true
            };

            PhotonNetwork.RaiseEvent((byte)networkEvent, data, raiseEventOptions, sendOptions);
        }
Пример #2
0
        private void NetworkEventReceivedHandler(EventData photonEvent)
        {
            Enumerators.NetworkEvent eventCode = (Enumerators.NetworkEvent)photonEvent.Code;

            switch (eventCode)
            {
            case Enumerators.NetworkEvent.PlayerInfo:
            {
                object[] data = (object[])photonEvent.CustomData;

                var playerInfo = PlayersInRoom.Find(item => item.id == (int)data[0]);

                if (playerInfo != null)
                {
                    var player = GameClient.Get <IGameplayManager>().Players.Find(item => item.Id == playerInfo.id);
                }
            }
            break;

            case Enumerators.NetworkEvent.PlayerHit:
            {
                object[] data = (object[])photonEvent.CustomData;

                var playerInfo = PlayersInRoom.Find(item => item.id == (int)data[0]);

                if (playerInfo != null)
                {
                    var player = GameClient.Get <IGameplayManager>().Players.Find(item => item.Id == playerInfo.id);
                    player?.Hit();
                }
            }
            break;

            case Enumerators.NetworkEvent.PlayerRevive:
            {
                object[] data = (object[])photonEvent.CustomData;

                var playerInfo = PlayersInRoom.Find(item => item.id == (int)data[0]);

                if (playerInfo != null)
                {
                    var player = GameClient.Get <IGameplayManager>().Players.Find(item => item.Id == playerInfo.id);
                    player?.ReviveNetworked((Vector3)data[1]);
                }
            }
            break;

            case Enumerators.NetworkEvent.PlayerTransform:
            {
                object[] data = (object[])photonEvent.CustomData;

                var playerInfo = PlayersInRoom.Find(item => item.id == (int)data[0]);

                if (playerInfo != null)
                {
                    var player = GameClient.Get <IGameplayManager>().Players.Find(item => item.Id == playerInfo.id);
                    player?.SetTransformNetworked((Vector3)data[1], (Quaternion)data[2]);
                }
            }
            break;
            }
        }