Example #1
0
    public GameObject Add(RewardGridItem item, bool isNew = false)
    {
        var go = Instantiate(rewardButton, gameObject.transform);

        var script = go.GetComponent <RewardButton>();

        script.rewardSettings = rewardSettings;
        script.reward         = item;

        var bgImage = go.GetComponent <Image>();

        bgImage.color = item.color;

        var actionIndex = item.data?["Action"].Value <int>();

        if (actionIndex == null || actionIndex == 0)
        {
            bgImage.color = new Color32(0, 0, 0, 127);
        }

        if (item.customReward)
        {
            script.managedBadge.gameObject.SetActive(true);
        }

        item.image = go.transform.GetChild(0).GetComponent <Image>();
        var rect   = new Rect(0, 0, item.imageTexture.width, item.imageTexture.height);
        var sprite = Sprite.Create(item.imageTexture, rect, new Vector2(0.5f, 0.5f));

        item.image.preserveAspect = true;
        item.image.sprite         = sprite;

        var text = go.transform.GetChild(1).GetComponent <Text>();

        text.text = item.title;

        if (text.text.Length > 25)
        {
            text.text = text.text.Substring(0, 25).TrimEnd() + ". . .";
        }

        if (isNew)
        {
            rewardSettings.SetReward(item);
        }

        return(go);
    }
Example #2
0
 public void OnPointerClick(PointerEventData eventData)
 {
     rewardSettings.SetReward(reward);
 }