Exemple #1
0
 void StartScanning()
 {
     central.BeginScanForDice(OnDieDiscovered);
     scanButton.enabled = true;
     scanText.text      = "Stop";
     scanButton.onClick.RemoveAllListeners();
     scanButton.onClick.AddListener(StartConnecting);
 }
    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);
    }
    // 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);
            });
        });
    }