/** * Crée le panel utilisateur * @param device Le device qui contient les informations de l'arduino */ private void CreateCharacterPlayer(CommunicationDeviceBLS device) { byte index = 0; while (index < FinderDevicesBLS.NB_MAX_PLAYER && isHavePlayer[index]) { ++index; } cdb[index] = device; isHavePlayer[index] = true; Vector3 position = new Vector3(posPlayer[index], -375, 0); GameObject go = Instantiate(panelPlayer, position, Quaternion.identity); goPlayer[index] = go; go.transform.SetParent(canvas.transform, false); if (!device.isPlayerDefined) { int idColor; int idCharacter; do { idColor = UnityEngine.Random.Range(0, colorUsed.Length); } while(colorUsed[idColor]); do { idCharacter = UnityEngine.Random.Range(0, spriteUsed.Length); } while(spriteUsed[idCharacter]); colorUsed[idColor] = true; spriteUsed[idCharacter] = true; device.idColor = idColor; device.idCharacter = idCharacter; device.colorPlayer = colorsPlayer[idColor]; device.characterPlayer = Resources.Load <Sprite>(spritePlayer[idCharacter]); device.isPlayerDefined = true; } else { colorUsed[device.idColor] = true; spriteUsed[device.idCharacter] = true; } GameObject imagePlayer = go.transform.GetChild(0).gameObject; GameObject textPlayer = go.transform.GetChild(1).gameObject; go.GetComponent <Image>().color = device.colorPlayer; imagePlayer.GetComponent <Image>().sprite = device.characterPlayer; textPlayer.GetComponent <Text>().text = device.surnameDevice; nbPlayer++; }
/** * Initialise le device qui sera associé à la main * @param device Un device */ void InitDevice(CommunicationDeviceBLS device) { this.device = device; }