using UnityEngine; using ExitGames.Client.Photon.LoadBalancing; using Hashtable = ExitGames.Client.Photon.Hashtable; /// /// Extensions of Exitgames Hashtable to allow for concise conditional setting logic /// public static class HashtableExtension { /// /// Checks if the hashtable contains key, if so, it will update toSet. Struct version /// /// Key to check for /// Reference to the variable to set /// Type to cast toSet to public static void SetOnKey(this Hashtable h, object key, ref T toSet) where T : struct { if (h.ContainsKey(key)) toSet = (T)h[key]; } public static void AddOrSet(this Hashtable h, object key, T val) where T : struct { if (h.ContainsKey(key)) { h[key] = val; } else { h.Add(key, val); } } /// /// Add a value to the hashtable if and only if it mismatches the previous provided /// Returns true if the replacement was made /// public static bool AddWithDirty(this Hashtable h, char key, T tracked, ref T previous) { if (tracked.Equals(previous)) return false; h.Add (key,tracked); previous = tracked; return true; } /// /// Adds and updates the keys/value based on . /// Any other keys are uneffected. /// /// /// public static void SetHashtable(this Hashtable h, Hashtable propertiesToSet){ var customProps = propertiesToSet.StripToStringKeys() as Hashtable; h.Merge(customProps); h.StripKeysWithNullValues(); } }