-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButtonForVoting.cs
135 lines (101 loc) · 4.04 KB
/
ButtonForVoting.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
using TMPro;
using UnityEngine.UI;
using System;
public class ButtonForVoting : NetworkBehaviour
{
[SyncVar]
[SerializeField] public int idNum;
[SerializeField] private TMP_Text Text_On_Button_For_Voting;
[SerializeField] private GameObject Equvivalent_Fild_Card_Object;
[SerializeField] private int buttonOwner;
public void SetButtonOwner(int buttonOwnerToSet)
{
buttonOwner = buttonOwnerToSet;
}
[Client]
public override void OnStartClient()
{
GameObject parent = GameObject.Find("Voting_Layout_Group");
gameObject.transform.SetParent(parent.transform, false);
Text_On_Button_For_Voting.text = idNum.ToString();
Transform panelCardShowcase = GameObject.Find("Panel_Card_Showcase").transform;
foreach (Transform child in panelCardShowcase)
{
if (child.gameObject.GetComponent<FieldCard>().idNum == idNum)
{
Equvivalent_Fild_Card_Object = child.gameObject;
break;
}
}
}
public void turnOnIfNotHis(int chosenOwner, int WhichTurn)
{
if ((buttonOwner != chosenOwner) && (buttonOwner != WhichTurn))
{
transform.GetChild(1).gameObject.GetComponent<Button>().interactable = true;
}
}
//----------------------------------------------------TRIGER ON BUTTON FOR VOTING FOR THIS CARD----------------------------------
public void VoteForThisButtonEntered()
{
TimerVoting timerForVoting = GameObject.Find("Timer_Voting").GetComponent<TimerVoting>();
timerForVoting.CancelTimer();
timerForVoting.gameObject.SetActive(false);
int playerToVoteFor = Equvivalent_Fild_Card_Object.GetComponent<FieldCard>().owner;
CmdIncreaseNumTaps(Equvivalent_Fild_Card_Object.GetComponent<FieldCard>().idNum);
CmdVoteForThisOne(playerToVoteFor, buttonOwner);
Transform votingLayoutGroup = gameObject.transform.parent;
foreach (Transform child in votingLayoutGroup)
{
child.GetChild(1).gameObject.GetComponent<Button>().interactable = false;
}
}
public void VoteForThisButtonEnteredAutomaticWithTimer()
{
int playerToVoteFor = Equvivalent_Fild_Card_Object.GetComponent<FieldCard>().owner;
CmdIncreaseNumTaps(Equvivalent_Fild_Card_Object.GetComponent<FieldCard>().idNum);
CmdVoteForThisOne(playerToVoteFor, buttonOwner);
Transform votingLayoutGroup = gameObject.transform.parent;
foreach (Transform child in votingLayoutGroup)
{
child.GetChild(1).gameObject.GetComponent<Button>().interactable = false;
}
}
[Command(requiresAuthority =false)]
public void CmdIncreaseNumTaps(int idNum)
{
Transform panelCardShowcase = GameObject.Find("Panel_Card_Showcase").transform;
foreach (Transform child in panelCardShowcase)
{
if(child.gameObject.GetComponent<FieldCard>().idNum == idNum)
{
child.gameObject.GetComponent<FieldCard>().numTaps += 1;
break;
}
}
}
[Command(requiresAuthority = false)]
public void CmdVoteForThisOne(int playerToVoteTo, int buttonOwner)
{
NetworkManagerLobby networkManagerObject = NetworkManager.singleton.GetComponent<NetworkManagerLobby>();
for (int i = 0; i < networkManagerObject.GamePlayers.Count; i++)
{
(networkManagerObject.GamePlayers[i]).playersPoints[playerToVoteTo]+=1;
}
if (playerToVoteTo == networkManagerObject.GamePlayers[0].WhichTurn)
{
for (int i = 0; i < networkManagerObject.GamePlayers.Count; i++)
{
networkManagerObject.GamePlayers[i].successGuesses.Add(buttonOwner);
}
}
for (int i = 0; i < networkManagerObject.GamePlayers.Count; i++)
{
networkManagerObject.GamePlayers[i].numOfVotes += 1;
}
}
}