void GameManager_OnPlayerCreation(object sender, EventPlayerCreationArgs e) { if (barType == null || barType.Length == 0) { Debug.LogError(this.name + " has no type"); return; } Type t = Type.GetType(barType); // get class type from string if (t == null) // type not found { Debug.LogError(this.name + "'s type is invalid"); return; } Component comp = e.player.GetComponent(t); if (comp == null) // component not found { Debug.LogError(this.name + "'s type does not exists on player"); return; } if (!(comp is IQuantifiable)) // component not quantifiable { Debug.LogError(this.name + "'s type is not quantifiable"); return; } target = comp as IQuantifiable; }
/// <summary> /// This will be called every time a stackable inventory item quantity is changed. /// </summary> /// <param name="quantifiable"> /// Quantifiable Game Foundation object that changed quantity. /// </param> private void OnStackableQuantityChanged(IQuantifiable quantifiable, long _) { if (quantifiable is StackableInventoryItem item && item.definition.key == k_HealthPotionKey) { RefreshUI(); } }
/// <summary> /// This will be called every time a currency balance is changed. /// </summary> /// <param name="quantifiable"> /// Quantifiable Game Foundation object that changed quantity (always Currency in this sample). /// </param> private void OnCoinBalanceChanged(IQuantifiable quantifiable, long _) { if (quantifiable is Currency currency) { if (currency.key == m_CoinDefinition.key) { m_WalletChanged = true; } } }