Ejemplo n.º 1
0
    public void Populate()
    {
        selectedDice  = new HashSet <Die>();
        availableDice = new List <AddDiceToPoolDice>();

        noDiceIndicator.SetActive(true);
        availableDiceListRoot.SetActive(false);

        if (availableDiceListRoot.transform.childCount > 0)
        {
            int count = availableDiceListRoot.transform.childCount;
            for (int i = 1; i < count; ++i)
            {
                GameObject.Destroy(availableDiceListRoot.transform.GetChild(i).gameObject);
            }
        }
        else
        {
            Debug.LogError("No templace available dice!");
        }

        // Setup buttons
        cancelButton.onClick.RemoveAllListeners();
        cancelButton.onClick.AddListener(() =>
        {
            central.StopScanForDice();
            Hide();
        });

        addSelectedButton.onClick.RemoveAllListeners();
        addSelectedButton.onClick.AddListener(() =>
        {
            central.StopScanForDice();
            if (selectedDice.Count > 0)
            {
                // Have central connect to selected dice
                central.ConnectToDiceList(selectedDice);
            }
            Hide();
        });

        // Kickoff a scan right away!
        central.BeginScanForDice(AddAvailableDice);
    }
Ejemplo n.º 2
0
    IEnumerator ConnectToDice()
    {
        scanButton.enabled = false;
        scanText.text      = "Connecting";
        central.StopScanForDice();
        foreach (var d in discoveredDice)
        {
            bool connected = false;
            central.ConnectToDie(d.Key, (cdie) => connected = true, OnDieDisconnected);
            yield return(new WaitUntil(() => connected));

            // Die is now tracked
            trackedDice.Add(d.Key, d.Value);

            // Register for telemetry events
            d.Key.OnTelemetry += OnDieTelemetryReceived;
        }
        discoveredDice.Clear();

        StartIdle();
    }