Skipping









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

Featured Snippets


File name: NetworkingPeer.cs Copy
3339     private void OnSerializeRead(Hashtable data, PhotonPlayer sender, int networkTime, short correctPrefix)
3340     {
3341         // read view ID from key (byte)0: a int-array (PUN 1.17++)
3342         int viewID = (int)data[(byte)0];
3343
3344
3345         PhotonView view = this.GetPhotonView(viewID);
3346         if (view == null)
3347         {
3348             Debug.LogWarning("Received OnSerialization for view ID " + viewID + ". We have no such PhotonView! Ignored this if you're leaving a room. State: " + this.State);
3349             return;
3350         }
3351
3352         if (view.prefix > 0 && correctPrefix != view.prefix)
3353         {
3354             Debug.LogError("Received OnSerialization for view ID " + viewID + " with prefix " + correctPrefix + ". Our prefix is " + view.prefix);
3355             return;
3356         }
3357
3358         // SetReceiving filtering
3359         if (view.group != 0 && !this.allowedReceivingGroups.Contains(view.group))
3360         {
3361             return; // Ignore group
3362         }
3363
3364
3365         if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed)
3366         {
3367             if (!this.DeltaCompressionRead(view, data))
3368             {
3369                 // Skip this packet as we haven't got received complete-copy of this view yet.
3370                 if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
3371                     Debug.Log("Skipping packet for " + view.name + " [" + view.viewID + "] as we haven't received a full packet for delta compression yet. This is OK if it happens for the first few frames after joining a game.");
3372                 return;
3373             }
3374
3375             // store last received for delta-compression usage
3376             view.lastOnSerializeDataReceived = data[(byte)1] as object[];
3377         }
3378
3379         if (sender.ID != view.ownerId)
3380         {
3381             if (!view.isSceneView || !sender.isMasterClient)
3382             {
3383                 // obviously the owner changed and we didn't yet notice.
3384                 Debug.Log("Adjusting owner to sender of updates. From: " + view.ownerId + " to: " + sender.ID);
3385                 view.ownerId = sender.ID;
3386             }
3387         }
3388
3389         object[] contents = data[(byte)1] as object[];
3390         PhotonStream pStream = new PhotonStream(false, contents);
3391         PhotonMessageInfo info = new PhotonMessageInfo(sender, networkTime, view);
3392
3393         view.DeserializeView( pStream, info );
3394     }
File name: AnimationBuilder.cs Copy
222         private void SetGameObjectForRef(GameObject root, Ref childRef, float time)
223         {
224             TimelineKey key = childRef.Referenced;
225             if (time < 0) time = key.Time;
226
227             TimelineKey lastKey;
228             lastKeyframeCache.TryGetValue(key.Timeline, out lastKey);
229
230             //Get the relative path based on the current hierarchy
231             var relativePath = childRef.RelativePath;
232
233             //If this is the root, skip it
234             if (string.IsNullOrEmpty(relativePath))
235             {
236                 Debug.Log("Skipping root node in SetGameObjectForRef (SHOULD NEVER HAPPEN)");
237                 return;
238             }
239
240
241             //Find the gameObject based on relative path
242             var transform = root.transform.Find(relativePath);
243             if (transform == null)
244             {
245                 Debug.LogError("ERROR: Unable to find GameObject at relative path " + relativePath);
246                 return;
247             }
248
249             var gameObject = transform.gameObject;
250             gameObject.SetActive(true);
251
252             //Get transform data from ref
253             Vector3 localPosition;
254             Vector3 localScale;
255             Vector3 localEulerAngles;
256
257             childRef.BakeTransforms(out localPosition, out localEulerAngles, out localScale);
258
259             //Set the current GameObject's transform data
260             transform.localPosition = localPosition;
261             transform.localScale = localScale;
262
263             //Spin the object in the correct direction
264             var oldEulerAngles = transform.localEulerAngles;
265
266             if (oldEulerAngles.z - localEulerAngles.z > 180) localEulerAngles.z += 360;
267             else if (localEulerAngles.z - oldEulerAngles.z > 180) localEulerAngles.z -= 360;
268             /*
269             switch(childRef.Unmapped.Spin)
270             {
271                 case SpinDirection.Clockwise:
272                     while (oldEulerAngles.z > localEulerAngles.z) localEulerAngles.z += 360;
273                     break;
274                 case SpinDirection.CounterClockwise:
275                     while (oldEulerAngles.z < localEulerAngles.z) localEulerAngles.z -= 360;
276                     break;
277             }*/
278             transform.localEulerAngles = localEulerAngles;
279
280             int zIndex = -1;
281             var spriteKey = key as SpriteTimelineKey;
282             if (spriteKey != null)
283             {
284                 zIndex = ((ObjectRef)childRef).ZIndex;
285                 //transform.GetComponent().sortingOrder = zIndex;
286             }
287
288             acb.SetCurve(root.transform, transform, time, lastKey, zIndex);
289
290
291             //Get last-used game object for this Timeline - needed to clean up reparenting
292             GameObject lastGameObject;
293             if (lastGameObjectCache.TryGetValue(key.Timeline, out lastGameObject) && gameObject != lastGameObject)
294             {
295                 //Let Unity handle the global->local position cruft for us
296                 lastGameObject.transform.position = transform.position;
297                 lastGameObject.transform.eulerAngles = transform.eulerAngles;
298
299                 //TODO: Also need to do something about scale - this is a little more tricky
300                 lastGameObject.transform.localScale = localScale;
301
302                 //Deactivate the old object
303                 lastGameObject.SetActive(false);
304
305                 acb.SetCurve(root.transform, lastGameObject.transform, time, lastKey);
306             }
307
308             //Set cached value for last keyframe
309             lastKeyframeCache[key.Timeline] = key;
310         }

Skipping 191 lượt xem

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