KeyValuePair









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

Featured Snippets


File name: NetworkingPeer.cs Copy
2813     public void RemoveRPCsInGroup(int group)
2814     {
2815         foreach (KeyValuePair kvp in this.photonViewList)
2816         {
2817             PhotonView view = kvp.Value;
2818             if (view.group == group)
2819             {
2820                 this.CleanRpcBufferIfMine(view);
2821             }
2822         }
2823     }
File name: NetworkingPeer.cs Copy
3113     public void NewSceneLoaded()
3114     {
3115         if (this.loadingLevelAndPausedNetwork)
3116         {
3117             this.loadingLevelAndPausedNetwork = false;
3118             PhotonNetwork.isMessageQueueRunning = true;
3119         }
3120         // Debug.Log("OnLevelWasLoaded photonViewList.Count: " + photonViewList.Count); // Exit Games internal log
3121
3122         List removeKeys = new List();
3123         foreach (KeyValuePair kvp in this.photonViewList)
3124         {
3125             PhotonView view = kvp.Value;
3126             if (view == null)
3127             {
3128                 removeKeys.Add(kvp.Key);
3129             }
3130         }
3131
3132         for (int index = 0; index < removeKeys.Count; index++)
3133         {
3134             int key = removeKeys[index];
3135             this.photonViewList.Remove(key);
3136         }
3137
3138         if (removeKeys.Count > 0)
3139         {
3140             if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
3141                 Debug.Log("New level loaded. Removed " + removeKeys.Count + " scene view IDs from last level.");
3142         }
3143     }
File name: NetworkingPeer.cs Copy
3147     public void RunViewUpdate()
3148     {
3149         if (!PhotonNetwork.connected || PhotonNetwork.offlineMode)
3150         {
3151             return;
3152         }
3153
3154         if (this.mActors == null ||
3155#if !PHOTON_DEVELOP
3156             this.mActors.Count <= 1
3157#endif
3158             )
3159         {
3160             return; // No need to send OnSerialize messages (these are never buffered anyway)
3161         }
3162
3163         dataPerGroupReliable.Clear();
3164         dataPerGroupUnreliable.Clear();
3165
3166         /* Format of the data hashtable:
3167          * Hasthable dataPergroup*
3168          * [(byte)0] = this.ServerTimeInMilliSeconds;
3169          * OPTIONAL: [(byte)1] = currentLevelPrefix;
3170          * + data
3171          */
3172
3173         foreach (KeyValuePair kvp in this.photonViewList)
3174         {
3175             PhotonView view = kvp.Value;
3176
3177             if (view.synchronization != ViewSynchronization.Off)
3178             {
3179                 // Fetch all sending photonViews
3180                 if (view.isMine)
3181                 {
3182                     #if UNITY_2_6_1 || UNITY_2_6 || UNITY_3_0 || UNITY_3_0_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5
3183                     if (!view.gameObject.active)
3184                     {
3185                         continue; // Only on actives
3186                     }
3187                     #else
3188                     if (!view.gameObject.activeInHierarchy)
3189                     {
3190                         continue; // Only on actives
3191                     }
3192                     #endif
3193
3194                     if (this.blockSendingGroups.Contains(view.group))
3195                     {
3196                         continue; // Block sending on this group
3197                     }
3198
3199                     // Run it trough its OnSerialize
3200                     Hashtable evData = this.OnSerializeWrite(view);
3201                     if (evData == null)
3202                     {
3203                         continue;
3204                     }
3205
3206                     if (view.synchronization == ViewSynchronization.ReliableDeltaCompressed || view.mixedModeIsReliable)
3207                     {
3208                         if (!evData.ContainsKey((byte)1) && !evData.ContainsKey((byte)2))
3209                         {
3210                             // Everything has been removed by compression, nothing to send
3211                         }
3212                         else
3213                         {
3214                             if (!dataPerGroupReliable.ContainsKey(view.group))
3215                             {
3216                                 dataPerGroupReliable[view.group] = new Hashtable();
3217                                 dataPerGroupReliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3218                                 if (currentLevelPrefix >= 0)
3219                                 {
3220                                     dataPerGroupReliable[view.group][(byte)1] = this.currentLevelPrefix;
3221                                 }
3222                             }
3223                             Hashtable groupHashtable = dataPerGroupReliable[view.group];
3224                             groupHashtable.Add((short)groupHashtable.Count, evData);
3225                         }
3226                     }
3227                     else
3228                     {
3229                         if (!dataPerGroupUnreliable.ContainsKey(view.group))
3230                         {
3231                             dataPerGroupUnreliable[view.group] = new Hashtable();
3232                             dataPerGroupUnreliable[view.group][(byte)0] = this.ServerTimeInMilliSeconds;
3233                             if (currentLevelPrefix >= 0)
3234                             {
3235                                 dataPerGroupUnreliable[view.group][(byte)1] = this.currentLevelPrefix;
3236                             }
3237                         }
3238                         Hashtable groupHashtable = dataPerGroupUnreliable[view.group];
3239                         groupHashtable.Add((short)groupHashtable.Count, evData);
3240                     }
3241                 }
3242                 else
3243                 {
3244                     // Debug.Log(" NO OBS on " + view.name + " " + view.owner);
3245                 }
3246             }
3247             else
3248             {
3249             }
3250         }
3251
3252         //Send the messages: every group is send in it's own message and unreliable and reliable are split as well
3253         RaiseEventOptions options = new RaiseEventOptions();
3254
3255#if PHOTON_DEVELOP
3256         options.Receivers = ReceiverGroup.All;
3257#endif
3258
3259         foreach (KeyValuePair kvp in dataPerGroupReliable)
3260         {
3261             options.InterestGroup = (byte)kvp.Key;
3262             this.OpRaiseEvent(PunEvent.SendSerializeReliable, kvp.Value, true, options);
3263         }
3264         foreach (KeyValuePair kvp in dataPerGroupUnreliable)
3265         {
3266             options.InterestGroup = (byte)kvp.Key;
3267             this.OpRaiseEvent(PunEvent.SendSerialize, kvp.Value, false, options);
3268         }
3269     }
File name: AnimationBuilder.cs Copy
312         private void BuildSpriteChangeCurve(ref AnimationClip clip, KeyValuePair> timeline)
313         {
314             // First you need to create Editor Curve Binding
315             EditorCurveBinding curveBinding = new EditorCurveBinding();
316
317             // I want to change the sprites of the sprite renderer, so I put the typeof(SpriteRenderer) as the binding type.
318             curveBinding.type = typeof(SpriteRenderer);
319
320             // Regular path to the GameObject that will be changed
321             curveBinding.path = timeline.Key;
322
323             // This is the property name to change the sprite of a sprite renderer
324             curveBinding.propertyName = "m_Sprite";
325
326             // An array to hold the object keyframes
327             ObjectReferenceKeyframe[] keyFrames = new ObjectReferenceKeyframe[timeline.Value.Count];
328
329             int i = 0;
330             foreach (var key in timeline.Value)
331             {
332                 keyFrames[i] = new ObjectReferenceKeyframe();
333                 // set the time
334                 keyFrames[i].time = key.Time;
335                 // set reference for the sprite you want
336                 keyFrames[i].value = key.Sprite;
337                 i++;
338
339             }
340
341             AnimationUtility.SetObjectReferenceCurve(clip, curveBinding, keyFrames);
342         }

KeyValuePair 139 lượt xem

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