protected override void OnInitialize() { _antivirus = null; _capture = null; _timedActivation = null; _consumableActivation = null; if (Entity.TryGetComponent(out _itemType) && Entity.TryGetComponent(out _currentLocation) && Entity.TryGetComponent(out _owner) && Entity.TryGetComponent(out _activation)) { _selectionOptions.SetActive(false); var spriteName = _itemType.GetType().Name.ToLowerInvariant(); _descriptionText.GetComponent <TextLocalization>().Key = spriteName.ToUpperInvariant() + "_DESCRIPTION"; LogProxy.Info($"Creating item type: {spriteName}"); gameObject.name = $"{Name}_{spriteName}"; _foregroundSprite.sprite = Resources.Load <Sprite>(spriteName); _foregroundText.text = string.Empty; Entity.TryGetComponent(out _timedActivation); Entity.TryGetComponent(out _antivirus); Entity.TryGetComponent(out _capture); Entity.TryGetComponent(out _consumableActivation); UpdateColour(); _midgroundSprite.enabled = false; _midgroundSprite.type = Image.Type.Simple; //TODO: extract item specific logic to subclasses InitializeAntivirus(); InitializeCapture(); UpdateInventory(); } else { throw new EntityInitializationException($"Could not load all required components for Entity Id {Entity.Id}"); } }
internal static int GetNumber <T>(this IItemType itemType) where T : BaseAttribute { T[] attributes = (T[])itemType.GetType().GetCustomAttributes(typeof(T), true); return(attributes[0].Number); }