// This is function is called: // - when the app opens: for each person present in the room // - when a new person arrives in the room void HandlePersonAdded(object sender, ChildChangedEventArgs args) { // Check errors if (args.DatabaseError != null) { Debug.LogError(args.DatabaseError.Message); return; } // Instanciate the Object from the Firebase JSON data and add it to our array. PersonData person = PersonData.CreateFromJson(serializer, args.Snapshot.GetRawJsonValue()); // Don't add self. if (person.id == SystemInfo.deviceUniqueIdentifier) { return; } // Check last interaction if (lastInteractions.ContainsKey(person.id)) { person.lastInteraction = lastInteractions [person.id]; } // Debug.Log ("CREATE " + person.id); persons.Add(person.id, person); }
// This function is called when an object (already handled in HandleChildAdded) // changes its data. void HandlePersonChanged(object sender, ChildChangedEventArgs args) { // Check errors if (args.DatabaseError != null) { Debug.LogError(args.DatabaseError.Message); return; } // Don't add self. PersonData person = PersonData.CreateFromJson(serializer, args.Snapshot.GetRawJsonValue()); if (person.id == SystemInfo.deviceUniqueIdentifier) { return; } // Update inside the object only to not reset some values. persons [args.Snapshot.Key].updateFromJson(serializer, args.Snapshot.GetRawJsonValue()); }