-
Notifications
You must be signed in to change notification settings - Fork 0
/
textUpdate.cs
147 lines (138 loc) · 4.4 KB
/
textUpdate.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Photon.Pun;
using Photon.Realtime;
using Photon.Chat;
public class textUpdate : MonoBehaviourPun
{
public string diceNum;
public bool isSelected = false;
public bool alreadyChoosed = false;
public bool isTrexDie = true;
public bool canBePut = true;
public bool mustPutTrexDieThisTurn = false; //下一个trexDie必须放在Area11;
public bool canNotPutExceptArea11;
public bool onlyForTrexDie = false;
public GameObject Area;
public GameObject PreNum;
public GameObject PreNumIn11;
public GameObject card;
public int endNum;
public int size;
public GameObject remind2DiceText;
// Update is called once per frame
private void Start()
{
diceNum = "?";
canBePut = true;
GameObject[] cardList = GameObject.FindGameObjectsWithTag("card");
foreach(GameObject a in cardList){
if(a.GetComponent<PhotonView>().OwnerActorNr == gameObject.GetComponent<PhotonView>().OwnerActorNr){
card = a;
}
}
}
void Update()
{
checkCanBePut();
CheckMustPutTrexDie();
checkBottom3fieldsInArea11();
if(card){
canNotPutExceptArea11 = card.GetComponent<Card>().nextTrexDieMustPutInArea11;
}
}
public void OnClickDiceButton()
{
diceNum = Random.Range(1, 6).ToString();
GetComponent<Text>().text = diceNum;
//remind2DiceText.SetActive(true);
}
public void OnClickOverButton()
{
if (isSelected)
{
GetComponent<PhotonView>().RPC("UpdateDice", RpcTarget.All, diceNum);
GetComponent<PhotonView>().RPC("UpdateBoolTrexDie",RpcTarget.Others);
}
else
{
GetComponent<PhotonView>().RPC("UpdateDice", RpcTarget.Others, "?");
}
}
public void OnClickSelectButton()
{
if(!alreadyChoosed){
if (!isSelected)
{
if(GetComponent<Text>().text == "?") return;
GetComponent<Text>().color = Color.green;
isSelected = true;
isTrexDie = false;
}
else
{
GetComponent<Text>().color = Color.white;
isSelected = false;
isTrexDie = true;
}
}
}
public void OnClickYesButton(){
if(!alreadyChoosed){
alreadyChoosed = true;
}
}
private void checkCanBePut(){
if(Area){
size = Area.transform.childCount;
for(int i =0;i<endNum;i++){
if(Area.transform.GetChild(i).GetComponentInChildren<Text>().text==""){
canBePut = false;
return;
}
if(PreNumIn11&&PreNumIn11.GetComponentInChildren<Text>().text == ""){
canBePut = false;
return;
}
canBePut = true;
}
}
}
private void CheckMustPutTrexDie(){
if(PreNum){
if(PreNum.transform.GetComponentInChildren<Text>().text!=""&&gameObject.GetComponentInChildren<Text>().text==""){
mustPutTrexDieThisTurn = true;
return;
}
mustPutTrexDieThisTurn = false;
}
}
private void checkBottom3fieldsInArea11(){
if(PreNumIn11&&PreNumIn11.GetComponentInChildren<Text>().text==""){
if(gameObject.GetComponentInChildren<Text>().text=="/") PreNumIn11.GetComponentInChildren<Text>().text="/";
}
if(PreNumIn11&&PreNumIn11.GetComponentInChildren<Text>().text=="/"){
if(gameObject.GetComponentInChildren<Text>().text=="") PreNumIn11.GetComponentInChildren<Text>().text="";
}
}
[PunRPC]
void UpdateDice(string diceNum) {
Debug.Log(diceNum);
string curNum = diceNum;
GetComponent<Text>().text =curNum;
}
[PunRPC]
void ResetDice(){
GetComponent<Text>().color = Color.white;
this.alreadyChoosed = false;
this.isSelected = false;
this.isTrexDie = true;
}
[PunRPC]
void UpdateBoolTrexDie(){
this.isTrexDie = false;
}
}