-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateController.cs
167 lines (131 loc) · 4.9 KB
/
CreateController.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CreateController : MonoBehaviour
{
public static CreateController cc;
int x = 6;
int y = 6;
public int turn=1;
public Node[,] nodes;
public GameObject selectButtons;
public GameObject popupObject;
public Sprite sprPlayer;
public Sprite sprNode;
public Sprite sprLove;
public Sprite sprFriendship;
public Sprite sprBusiness;
public Sprite sprFamily;
public Sprite sprImage;
public Node playerNode;
public PhotonView pv;
public bool isMyTurn;
private void Awake()
{
cc = this;
}
void Start()
{
if (pv.viewID == 1)
isMyTurn = false;
popupObject = GameObject.FindWithTag("Pop");
popupObject.SetActive(false);
//GameObject popupObject = new GameObject();
//popupObject = GameObject.FindWithTag("Pop");
//popupObject.SetActive(false);
nodes = new Node[x, y];
for (int i = 1; i <=5; i++)
{
for (int j = 1; j <=5; j++)
{
Node node = new Node();
node.grid = new Vector2(i,j);
node.stone = transform.Find(i.ToString() + "-" + j.ToString()).gameObject;
node.button = transform.Find(i.ToString() + "-" + j.ToString()).GetComponent<Button>();
nodes[i, j] = node;
nodes[i, j].button.enabled = true;
var selfImg = nodes[i, j].button.GetComponent<Image>();
if (i == 5 && j == 3)
{
nodes[i, j].isPlayer = true;
playerNode = nodes[i, j];
}
//Add Component -> 컴포넌트추가
nodes[i, j].stone.AddComponent<StoneController>();
var sc = nodes[i, j].stone.GetComponent<StoneController>();
sc.selfNode = node;
nodes[i, j].button.onClick.AddListener(delegate { sc.Move(node); });
//nodes[i, j].button.onClick.AddListener(delegate { sc.ChangeTile(PawnType.Love); });
}
}
SetTileButtons();
selectButtons.SetActive(false);
}
void Update()
{
for(int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
if(i < playerNode.grid.x - 1)
{
nodes[i, j].button.interactable = false;
}
else if(i > playerNode.grid.x + 1)
{
nodes[i, j].button.interactable = false;
}
else if (j < playerNode.grid.y - 1)
{
nodes[i, j].button.interactable = false;
}
else if (j > playerNode.grid.y + 1)
{
nodes[i, j].button.interactable = false;
}
else
{
if(!selectButtons.activeSelf)
nodes[i, j].button.interactable = true;
else
nodes[i, j].button.interactable = false;
}
//첫 턴 예외
if (i == 5 && turn == 1)
nodes[i, j].button.interactable = false;
}
}
Debug.Log(PhotonNetwork.countOfPlayersInRooms);
if (Input.GetKeyDown(KeyCode.Escape))
Application.Quit();
}
void SetTileButtons()
{
var love = selectButtons.transform.Find("Love").GetComponent<Button>();
var friendship = selectButtons.transform.Find("Friendship").GetComponent<Button>();
var business = selectButtons.transform.Find("Business").GetComponent<Button>();
var family = selectButtons.transform.Find("Family").GetComponent<Button>();
love.onClick.AddListener(delegate { playerNode.button.GetComponent<StoneController>().ChangeTile(PawnType.Love, playerNode); });
friendship.onClick.AddListener(delegate { playerNode.button.GetComponent<StoneController>().ChangeTile(PawnType.Friendship, playerNode); });
business.onClick.AddListener(delegate { playerNode.button.GetComponent<StoneController>().ChangeTile(PawnType.Business, playerNode); });
family.onClick.AddListener(delegate { playerNode.button.GetComponent<StoneController>().ChangeTile(PawnType.Family, playerNode); });
selectButtons.SetActive(false);
}
}
public enum PawnType
{
Stone = 0,
Love = 1,
Friendship = 2,
Business = 3,
Family = 4
}
public class Node
{
public Vector2 grid;
public GameObject stone;
public Button button;
public PawnType pawnType;
public bool isPlayer;
}