/// <summary> /// Sets an item to 'deselected' in the database. /// </summary> public static void SetToDeselected(IAPItem item) { //pass argument to DBManager and invoke deselect event DBManager.SetDeselected(item.productId); if (itemDeselectedEvent != null) { itemDeselectedEvent(item.productId); } }
/// <summary> /// Refreshes the visual representation of a specific shop item. /// This is called automatically because of subscribing to the DBManager update event. /// It also means saving performance due to not refreshing all items every time. /// </summary> public void Refresh(string id) { //this method is based on data from the database, //so if we don't have a DBManager instance don't continue if (!DBManager.GetInstance()) { return; } IAPObject obj = IAPManager.GetIAPObject(id); IAPItem item = instance.IAPItems.ContainsKey(id) ? instance.IAPItems[id] : null; if (obj == null || item == null || item.productId != id) { return; } bool isSelected = DBManager.GetSelected(id); bool isPurchased = DBManager.GetPurchase(id) > 0; //double check that selected items are actually owned //if not, correct the entry by setting it to deselected if (isSelected && !isPurchased) { DBManager.SetDeselected(id); isSelected = false; } if (isPurchased) { item.Purchased(true); //in case the item has been selected before, but also auto-select one item per group //more items per group can be pre-selected manually e.g. on app launch if (isSelected || (item.selectButton && !item.deselectButton && DBManager.GetSelectedGroup(IAPManager.GetIAPObjectGroupName(id)).Count == 0)) { item.IsSelected(true); } } else if (!string.IsNullOrEmpty(obj.req.entry) && DBManager.isRequirementMet(obj.req)) { //check if a requirement is set up for this item, //then unlock if the requirement has been met if (IAPManager.isDebug) { Debug.Log("requirement met for: " + obj.id); } item.Unlock(); } }