// Use this for initialization
    void Start()
    {
        // Initialize Central
        central.BeginScanForDice((newDie) =>
        {
            var dieUI = GameObject.Instantiate <UIDie>(diePrefab);
            dieUI.transform.SetParent(diceRootUI.transform);
            dieUI.transform.position   = Vector3.zero;
            dieUI.transform.rotation   = Quaternion.identity;
            dieUI.transform.localScale = Vector3.one;
            dieUI.die            = newDie;
            dieUI.faceNumber     = -1;
            dieUI.OnMoreOptions += () => ShowDieCommands(newDie);
            dice.Add(dieUI);

            central.ConnectToDie(newDie, null, (lostDie) =>
            {
                GameObject.Destroy(dice.FirstOrDefault(uid => uid.die == lostDie).gameObject);
            });
        });
    }
Exemple #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();
    }