SendOutgoingCommands









How do I use Send Outgoing Commands
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: NetworkingPeer.cs Copy
3657     protected internal void SetLevelInPropsIfSynced(object levelId)
3658     {
3659         if (!PhotonNetwork.automaticallySyncScene || !PhotonNetwork.isMasterClient || PhotonNetwork.room == null)
3660         {
3661             return;
3662         }
3663         if (levelId == null)
3664         {
3665             Debug.LogError("Parameter levelId can't be null!");
3666             return;
3667         }
3668
3669         // check if "current level" is already set in props
3670         if (PhotonNetwork.room.customProperties.ContainsKey(NetworkingPeer.CurrentSceneProperty))
3671         {
3672             object levelIdInProps = PhotonNetwork.room.customProperties[NetworkingPeer.CurrentSceneProperty];
3673             if (levelIdInProps is int && Application.loadedLevel == (int)levelIdInProps)
3674             {
3675                 return;
3676             }
3677             if (levelIdInProps is string && Application.loadedLevelName.Equals((string)levelIdInProps))
3678             {
3679                 return;
3680             }
3681         }
3682
3683         // current level is not yet in props, so this client has to set it
3684         Hashtable setScene = new Hashtable();
3685         if (levelId is int) setScene[NetworkingPeer.CurrentSceneProperty] = (int)levelId;
3686         else if (levelId is string) setScene[NetworkingPeer.CurrentSceneProperty] = (string)levelId;
3687         else Debug.LogError("Parameter levelId must be int or string!");
3688
3689         PhotonNetwork.room.SetCustomProperties(setScene);
3690         this.SendOutgoingCommands(); // send immediately! because: in most cases the client will begin to load and not send for a while
3691     }
File name: PhotonHandler.cs Copy
59     protected void Update()
60     {
61         if (PhotonNetwork.networkingPeer == null)
62         {
63             Debug.LogError("NetworkPeer broke!");
64             return;
65         }
66
67         if (PhotonNetwork.connectionStateDetailed == PeerState.PeerCreated || PhotonNetwork.connectionStateDetailed == PeerState.Disconnected || PhotonNetwork.offlineMode)
68         {
69             return;
70         }
71
72         // the messageQueue might be paused. in that case a thread will send acknowledgements only. nothing else to do here.
73         if (!PhotonNetwork.isMessageQueueRunning)
74         {
75             return;
76         }
77
78         bool doDispatch = true;
79         while (PhotonNetwork.isMessageQueueRunning && doDispatch)
80         {
81             // DispatchIncomingCommands() returns true of it found any command to dispatch (event, result or state change)
82             UnityEngine.Profiling.Profiler.BeginSample("DispatchIncomingCommands");
83             doDispatch = PhotonNetwork.networkingPeer.DispatchIncomingCommands();
84             UnityEngine.Profiling.Profiler.EndSample();
85         }
86
87         int currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000); // avoiding Environment.TickCount, which could be negative on long-running platforms
88         if (PhotonNetwork.isMessageQueueRunning && currentMsSinceStart > this.nextSendTickCountOnSerialize)
89         {
90             PhotonNetwork.networkingPeer.RunViewUpdate();
91             this.nextSendTickCountOnSerialize = currentMsSinceStart + this.updateIntervalOnSerialize;
92             this.nextSendTickCount = 0; // immediately send when synchronization code was running
93         }
94
95         currentMsSinceStart = (int)(Time.realtimeSinceStartup * 1000);
96         if (currentMsSinceStart > this.nextSendTickCount)
97         {
98             bool doSend = true;
99             while (PhotonNetwork.isMessageQueueRunning && doSend)
100             {
101                 // Send all outgoing commands
102                 UnityEngine.Profiling.Profiler.BeginSample("SendOutgoingCommands");
103                 doSend = PhotonNetwork.networkingPeer.SendOutgoingCommands();
104                 UnityEngine.Profiling.Profiler.EndSample();
105             }
106
107             this.nextSendTickCount = currentMsSinceStart + this.updateInterval;
108         }
109     }
File name: PhotonNetwork.cs Copy
2231     public static void SendOutgoingCommands()
2232     {
2233         if (!VerifyCanUseNetwork())
2234         {
2235             return;
2236         }
2237
2238         while (networkingPeer.SendOutgoingCommands())
2239         {
2240         }
2241     }

SendOutgoingCommands 166 lượt xem

Gõ tìm kiếm nhanh...