public void Initialize(Canvas canvas, int itemId, bool isEquiped = false, Action onClicked = null) { this.transform.parent = canvas.transform; this.indicator = this.transform.Find("SelectionIndicator"); SetSelected(false); // canvas.worldCamera = camera; // this.canvas = canvas; this.item = DefinitionStore.Instance.GetItemDefinition(itemId); if (this.item == null) { throw new ArgumentException("Cannot find item definition with ID=" + itemId); } this.isEquiped = isEquiped; if (onClicked != null) { Clickable clickable = indicator.GetComponent <Clickable>(); clickable.Initialize(onClicked); } // Icon Transform iconObject = this.transform.Find("Icon"); Image iconImage = iconObject.GetComponent <Image>(); string iconKey = string.Empty; if (this.item is AttackItemDefinition) { iconKey = "Attack"; } else if (this.item is DefendItemDefinition) { iconKey = "Defend"; } else { iconKey = "Usable"; } int equiped = isEquiped ? 1 : 0; string iconName = string.Format(@"OthersLegacy/Item{0}Icon_{1}", iconKey, equiped); iconImage.sprite = LoadSprite(iconName, 24, 20); // Name string name = LocalizedStrings.GetItemName(itemId); TextMeshPro text = RenderText(name, "Name", FontAssets.FontSizeType.Normal); text.transform.localScale = new Vector3(7, 7, 7); // Description string description = GetItemDescription(this.item); TextMeshPro descriptionText = RenderText(description, "Description", FontAssets.FontSizeType.Normal); descriptionText.transform.localScale = new Vector3(5, 5, 5); }
void AddItemsToContainer(GameObject container) { float zOrder = 2f; float intervalX = -12f; float intervalY = 1.7f; float startX = 14.0f; float startY = -2.55f; float xOffsetIcon = -3.2f; float xOffsetName = -8.5f; float xOffsetAttr = -12.5f; float xOffsetValue = -15.2f; Vector3 scale = new Vector3(0.35f, 0.35f, 1); for (int i = 0; i < creature.Data.Items.Count; i++) { int itemId = creature.Data.Items[i]; ItemDefinition item = DefinitionStore.Instance.GetItemDefinition(itemId); if (item == null) { continue; } int x = i / 4; int y = i % 4; float baseX = startX + intervalX * x; float baseY = startY + intervalY * y; // Icon int val = i; AddControl("Others/IconAttack_1", container.transform, new Vector3(baseX + xOffsetIcon, zOrder, baseY), new Vector3(1f, 1f, 1f), () => { this.OnSelectClicked(val); }); string name = LocalizedStrings.GetItemName(itemId); // Name AddText(name, container.transform, new Vector3(baseX + xOffsetName, zOrder, baseY), scale); // Attr AddText("+AP", container.transform, new Vector3(baseX + xOffsetAttr, zOrder, baseY), scale); // Value int value = 15; AddText(StringUtils.Digit3(value), container.transform, new Vector3(baseX + xOffsetValue, zOrder, baseY), scale); } }