private void Awake() { rule = FindObjectOfType <PTTableTop_Playingcard>(); monoPlayer = GetComponentInParent <PTMono_PlayerTT>(); monoHand = monoPlayer.GetComponentInChildren <PTMono_PlayingcardHand>(); GetComponent <Button>().onClick.AddListener(OnClicked); }
protected abstract IEnumerator UpdatePlayerInfo(PTMono_PlayerTT player);
private IEnumerator InstantiatePlayerTT(PTPlayer ptPlayer) { //paramaters float awayFromCenter = 0.6f; float currY = 7.5f; //random init position Vector3 currPos = Vector3.zero; while (true) { yield return(new WaitForEndOfFrame()); float currX = UnityEngine.Random.Range(X_MIN, X_MAX); float currZ = UnityEngine.Random.Range(Z_MIN, Z_MAX); if ((currX > X_MAX * awayFromCenter || currX < X_MIN * awayFromCenter) && (currZ > Z_MAX * awayFromCenter || currZ < Z_MIN * awayFromCenter)) { currPos = new Vector3(currX, currY, currZ); break; } } //instantiate game object PTMono_PlayerTT newPlayer = Instantiate(ptMonoPlayer.gameObject, currPos, ptMonoPlayer.transform.rotation).GetComponent <PTMono_PlayerTT>(); //Assign the ptPlayer to the new player game object newPlayer.ptPlayer = ptPlayer; //Set name int countPresetName = Enum.GetNames(typeof(PresetName)).Length; newPlayer.name = newPlayer.ptPlayer == null?General.RandName() + "(Bot)" : newPlayer.ptPlayer.name; while (true) { yield return(new WaitForEndOfFrame()); bool hasSameName = false; foreach (PTMono_PlayerTT player in players) { if (!player.Equals(newPlayer) && player.name == newPlayer.name) { hasSameName = true; print("while InstantiatePlayerTT, same name detected:" + player.name); break; } } if (hasSameName) { newPlayer.name = newPlayer.ptPlayer == null?General.RandName() + "(Bot)" : newPlayer.ptPlayer.name; } else { break; } } //wait until newplayer is instantiated successfully yield return(new WaitUntil(() => newPlayer != null)); }