Profiler









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

Featured Snippets


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     }

Profiler 188 lượt xem

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