Ejemplo n.º 1
0
        private async void InstantiateItem()
        {
            var products       = Buy.Left.Shop.Products;
            var position       = new Vector3(RectTransform.position.x, RectTransform.position.y + (RectTransform.sizeDelta.y * 0.5f));
            var spacingPerItem = 10.0f;

            position.y -= itemPrefab.RectTransform.sizeDelta.y * 0.5f;

            items = new UI_Shop_Left_Buy_ItemChild[maxVisibleItem];
            for (int i = startIndex; i < startIndex + maxVisibleItem; i++)
            {
                if (i > products.Count - 1)
                {
                    break;
                }

                var product = Instantiate(itemPrefab, RectTransform);
                product.Initialize(products.ElementAt(i), this, position);
                items[i - startIndex] = product;

                position.y -= itemPrefab.RectTransform.sizeDelta.y + spacingPerItem;
            }

            await AsyncManager.WaitForFrame(1);

            int index = startIndex;

            foreach (var item in items)
            {
                if (index > products.Count - 1)
                {
                    break;
                }

                UI_ItemRenderer.ResetCameraPositionAndRotation(products.ElementAt(index).Product, item.ItemPreview.transform);
                UI_ItemRenderer.SetTexture(item.ItemRenderer.texture as RenderTexture);
                UI_ItemRenderer.Render();

                index++;
            }

            UI_ItemRenderer.SetTexture(null);
        }
Ejemplo n.º 2
0
        private async void Awake()
        {
            await AsyncManager.WaitForFrame(1);

            var mid = RectTransform.position;

            icon        = UI_Pool.Instance.GetImage(RectTransform, 64, 64, nameof(icon));
            icon.sprite = GlobalAssetsReference.Money_Sprite;
            icon.rectTransform.position = mid + new Vector3(32, 0);

            var iconLeft    = icon.rectTransform.position + new Vector3(32, 0);
            var leftLeft    = mid + new Vector3(RectTransform.sizeDelta.x * 0.5f, 0);
            var amountSizeX = Mathf.Abs(iconLeft.x - leftLeft.x);

            amount = UI_Pool.Instance.GetText(RectTransform, amountSizeX, 48, PlayerData.MoneyString, nameof(amount));
            amount.rectTransform.position = iconLeft + new Vector3(amountSizeX * 0.5f, 0);
            var amountPos = amount.rectTransform.position;

            amountPos.y = icon.rectTransform.position.y - 32 + 24;
            amount.rectTransform.position = amountPos;
            amount.alignment = TextAlignmentOptions.MidlineLeft;

            UI_Menu.OnBeforeOpen.AddListener(UpdateMoney);
        }