Ejemplo n.º 1
0
    public void ShowResultPanel(Dictionary <string, int> rewardList)
    {
        GameObject container = transform.Find("ItemPanel/Container").gameObject;

        foreach (Transform item in container.transform)
        {
            Destroy(item.gameObject);
        }

        foreach (KeyValuePair <string, int> resource in rewardList)
        {
            GameObject itemGO = new GameObject();
            itemGO.transform.SetParent(container.transform);

            if (LoadManager.Instance.allResourceData.ContainsKey(resource.Key))
            {
                itemGO.AddComponent <Image>().sprite = Resources.Load <Sprite>(LoadManager.Instance.allResourceData[resource.Key].spritePath);
            }
            else if (LoadManager.Instance.allEquipmentData.ContainsKey(resource.Key))
            {
                itemGO.AddComponent <Image>().sprite = Resources.Load <Sprite>(LoadManager.Instance.allEquipmentData[resource.Key].spritePath);
            }

            GameObject textGO = new GameObject();
            textGO.name = "Amount";
            textGO.transform.SetParent(itemGO.transform);
            Text text = textGO.AddComponent <Text>();
            text.text = resource.Value.ToString();
            text.GetComponent <Text>().font     = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            text.GetComponent <Text>().fontSize = 20;
            RectTransformExtensions.SetAnchor(text.GetComponent <RectTransform>(), AnchorPresets.BottonCenter);
            text.transform.position = text.transform.position + new Vector3(0, -10, 0);
        }
    }
Ejemplo n.º 2
0
    public GameObject addSprite(string name, Sprite sprite, Vector2 scale,
                                AnchorPresets anchorPreset = AnchorPresets.MiddleCenter,
                                Vector2Int pos             = new Vector2Int(),
                                PivotPresets pivotPreset   = PivotPresets.MiddleCenter)
    {
        GameObject gameObject = new GameObject();

        gameObject.transform.parent = canvas.transform;
        gameObject.name             = name;

        Image image = gameObject.AddComponent <Image>();

        image.sprite = sprite;

        RectTransform rectTransform = image.GetComponent <RectTransform>();

        RectTransformExtensions.SetAnchor(rectTransform, anchorPreset, pos.x, pos.y);
        RectTransformExtensions.SetPivot(rectTransform, pivotPreset);
        rectTransform.localScale = scale;

        return(gameObject);
    }
        public void Change(Sprite sprite)
        {
            AspectRatioFitter.enabled = false;

            Image.sprite = sprite;
            RectTransformExtensions.SetAnchor(transform, AnchorPresets.MiddleCenter);
            transform.sizeDelta = new Vector2(sprite.rect.width, sprite.rect.height);
            bool bWidth = transform.rect.width > transform.rect.height;

            AspectRatioFitter.AspectMode aspectMode = bWidth ?
                                                      AspectRatioFitter.AspectMode.WidthControlsHeight : AspectRatioFitter.AspectMode.HeightControlsWidth;

            float aspectRatio = bWidth ?
                                transform.rect.height / transform.rect.width : transform.rect.width / transform.rect.height;

            AspectRatioFitter.aspectMode  = aspectMode;
            AspectRatioFitter.aspectRatio = aspectRatio;
            AspectRatioFitter.enabled     = true;

            RectTransformExtensions.SetAnchor(transform, AnchorPresets.StretchAll);
            transform.sizeDelta        = Vector2.zero;
            transform.anchoredPosition = Vector2.zero;
        }
Ejemplo n.º 4
0
    public GameObject addText(string name, string text, int fontSize, Vector2 scale,
                              AnchorPresets anchorPreset = AnchorPresets.MiddleCenter,
                              Vector2Int pos             = new Vector2Int(),
                              PivotPresets pivotPreset   = PivotPresets.MiddleCenter)
    {
        GameObject gameObject = new GameObject();

        gameObject.transform.parent = canvas.transform;
        gameObject.name             = name;

        Text textObject = gameObject.AddComponent <Text>();

        textObject.text     = text;
        textObject.font     = font;
        textObject.fontSize = fontSize;

        RectTransform rectTransform = textObject.GetComponent <RectTransform>();

        RectTransformExtensions.SetAnchor(rectTransform, anchorPreset, pos.x, pos.y);
        RectTransformExtensions.SetPivot(rectTransform, pivotPreset);
        rectTransform.localScale = scale;

        return(gameObject);
    }