コード例 #1
0
    // CLEAN ME
    private void BtnOnClickCrate(Button crateBtn)
    {
        if (_status != LootCrateScreenStatus.NORMAL)
        {
            return;
        }

        SetNavButtonsEnabled(false);

        _status = LootCrateScreenStatus.OPEN_CRATE;

        _crateItems       = new List <LootCrateItem>();
        _currentLootCrate = crateBtn.GetComponentInParent <LootCrateBox>();

        Rect        parentRect = this.parentRect;
        Transform   btnParent  = crateBtn.transform.parent;
        LootCrate   lootCrate  = _currentLootCrate.lootCrate;
        List <Item> items      = lootCrate.GenerateItems();

        //NOTE-TO-SELF: DO call this API method! (Instead of one-by-one, batch-calls adds all generated items)
        API.Items.AddMany(items)
        .Then(res => trace("Added " + items.Count + " items server-side..."))
        .Catch(err => traceError("Something went wrong while adding newly generated items to server-side: " + err.Message));

        dataMan.allItemsList.AddRange(items);
    }
コード例 #2
0
    private void PrepareCrateButtons()
    {
        trace("Preparing the Crates...");

        GameObject cratePrefab = GetPrefab("SubItems/LootCrateBox");

        _crateButtons = new List <Button>();

        List <LootCrate> lootCrates = PlayerManager.Instance.GetLootCrates();

        foreach (LootCrate lootCrate in lootCrates)
        {
            GameObject crateGo = MakeFromPrefab(cratePrefab, crateContainer);
            crateGo.transform.localScale = Vector3.one;

            LootCrateBox box = crateGo.GetComponent <LootCrateBox>();
            box.lootCrate = lootCrate;

            Button crateBtn = crateGo.GetComponentInChildren <Button>();
            _crateButtons.Add(crateBtn);

            //Hook Crate buttons click-handlers:
            crateBtn.onClick.AddListener(() => BtnOnClickCrate(crateBtn));

            //Add a CG to control the overall alpha (of Image & Text simultaneously):
            crateBtn.gameObject.AddComponent <CanvasGroup>();
        }

        scroller.RecalculateLayout();
    }