Exemplo n.º 1
0
    private void ParseUpdate(string message)
    {
        MessageUpdate update;

        try
        {
            update = JsonConvert.DeserializeObject <MessageUpdate>(message);
        }
        catch (Exception)
        {
            Debug.Log("Parse error");
            return;
        }
        if (update.rfids != null)
        {
            rfids = update.rfids;
        }
        if (update.toys != null)
        {
            List <string> toyConnected = update.toys.Select(x => x.Id).ToList();
            List <string> toyToDelete  = toys.Keys.Where(x => !toyConnected.Contains(x)).ToList();
            foreach (string toy in toyToDelete)
            {
                Destroy(toys[toy]);
                toys.Remove(toy);
            }
            foreach (SmartToyDescription toy in update.toys)
            {
                if (toys.TryGetValue(toy.Id, out GameObject value))
                {
                    value.GetComponent <SmartToy>().state = toy;
                }
                else
                {
                    GameObject toyAdded = new GameObject(toy.Name);
                    toyAdded.transform.parent = SmartObjectSpawn.transform;
                    SmartToy description = toyAdded.AddComponent <SmartToy>();
                    description.state = toy;
                    toys.Add(toy.Id, toyAdded);
                }
            }
        }
    }
 private void Start()
 {
     passaPorta = GameObject.Find("Passaporta").GetComponent <SmartToy>();
     MagicRoomSmartToyManager.instance.openEventChannelSmartToy("Passaporta");
 }