回答編集履歴

3

続き②のタイトルを追記

2018/04/30 12:29

投稿

imohori708
imohori708

スコア10

test CHANGED
@@ -1,3 +1,7 @@
1
+ 続き②です。
2
+
3
+
4
+
1
5
  CardViewクラスは以下に記載します。
2
6
 
3
7
  ```C#

2

コードを見やすいように修正

2018/04/30 12:28

投稿

imohori708
imohori708

スコア10

test CHANGED
@@ -1 +1,295 @@
1
+ CardViewクラスは以下に記載します。
2
+
3
+ ```C#
4
+
5
+ using UnityEngine;
6
+
7
+ using UnityEngine.Assertions;
8
+
9
+
10
+
1
- 内容重複のため削除済み
11
+ using TMPro;
12
+
13
+
14
+
15
+ using CCGKit;
16
+
17
+
18
+
19
+ /// <summary>
20
+
21
+ /// カードの描画情報
22
+
23
+ /// RuntimeCardクラスも持ってる。各スタッツ、使用可能の光とか
24
+
25
+ /// </summary>
26
+
27
+ public class CardView : MonoBehaviour
28
+
29
+ {
30
+
31
+ public RuntimeCard card { get; private set; }
32
+
33
+
34
+
35
+ //使用可能の青い光
36
+
37
+ [SerializeField]
38
+
39
+ protected SpriteRenderer glowSprite;
40
+
41
+
42
+
43
+ //イラスト
44
+
45
+ [SerializeField]
46
+
47
+ protected SpriteRenderer pictureSprite;
48
+
49
+
50
+
51
+ [SerializeField]
52
+
53
+ protected TextMeshPro costText;
54
+
55
+
56
+
57
+ [SerializeField]
58
+
59
+ protected TextMeshPro nameText;
60
+
61
+
62
+
63
+ [SerializeField]
64
+
65
+ protected TextMeshPro bodyText;
66
+
67
+
68
+
69
+ protected GameObject previewCard;
70
+
71
+
72
+
73
+ public int manaCost { get; protected set; }
74
+
75
+
76
+
77
+ [HideInInspector]
78
+
79
+ public bool isPreview;
80
+
81
+
82
+
83
+ protected virtual void Awake()
84
+
85
+ {
86
+
87
+ Assert.IsNotNull(glowSprite);
88
+
89
+ Assert.IsNotNull(pictureSprite);
90
+
91
+ Assert.IsNotNull(costText);
92
+
93
+ Assert.IsNotNull(nameText);
94
+
95
+ Assert.IsNotNull(bodyText);
96
+
97
+ }
98
+
99
+
100
+
101
+ /// <summary>
102
+
103
+ /// カードの情報を取り込む
104
+
105
+ /// </summary>
106
+
107
+ /// <param name="card"></param>
108
+
109
+ public virtual void PopulateWithInfo(RuntimeCard card)
110
+
111
+ {
112
+
113
+ this.card = card;
114
+
115
+
116
+
117
+ var gameConfig = GameManager.Instance.config;
118
+
119
+ /*
120
+
121
+
122
+
123
+ var cardType = gameConfig.cardTypes.Find(x => x.id == card.cardId);
124
+
125
+ Assert.IsNotNull(cardType);
126
+
127
+ pictureSprite.sprite = Resources.Load<Sprite>(cardType.GetStringProperty("Picture"));
128
+
129
+
130
+
131
+ */
132
+
133
+
134
+
135
+ var libraryCard = gameConfig.GetCard(card.cardId);
136
+
137
+ Assert.IsNotNull(libraryCard);
138
+
139
+ nameText.text = libraryCard.name;
140
+
141
+ bodyText.text = libraryCard.GetStringProperty("Text");
142
+
143
+
144
+
145
+ var cost = libraryCard.costs.Find(x => x is PayResourceCost);
146
+
147
+ if (cost != null)
148
+
149
+ {
150
+
151
+ var payResourceCost = cost as PayResourceCost;
152
+
153
+ manaCost = payResourceCost.value;
154
+
155
+ costText.text = manaCost.ToString();
156
+
157
+ }
158
+
159
+
160
+
161
+ pictureSprite.sprite = Resources.Load<Sprite>(string.Format("Images/{0}", libraryCard.GetStringProperty("Picture")));
162
+
163
+ var material = libraryCard.GetStringProperty("Material");
164
+
165
+ if (!string.IsNullOrEmpty(material))
166
+
167
+ {
168
+
169
+ pictureSprite.material = Resources.Load<Material>(string.Format("Materials/{0}", material));
170
+
171
+ }
172
+
173
+ }
174
+
175
+
176
+
177
+ /// <summary>
178
+
179
+ /// ライブラリーの情報を移行
180
+
181
+ /// </summary>
182
+
183
+ /// <param name="card"></param>
184
+
185
+ public virtual void PopulateWithLibraryInfo(Card card)
186
+
187
+ {
188
+
189
+ nameText.text = card.name;
190
+
191
+ bodyText.text = card.GetStringProperty("Text");
192
+
193
+
194
+
195
+ var cost = card.costs.Find(x => x is PayResourceCost);
196
+
197
+ if (cost != null)
198
+
199
+ {
200
+
201
+ var payResourceCost = cost as PayResourceCost;
202
+
203
+ manaCost = payResourceCost.value;
204
+
205
+ costText.text = manaCost.ToString();
206
+
207
+ }
208
+
209
+
210
+
211
+ pictureSprite.sprite = Resources.Load<Sprite>(string.Format("Images/{0}", card.GetStringProperty("Picture")));
212
+
213
+ var material = card.GetStringProperty("Material");
214
+
215
+ if (!string.IsNullOrEmpty(material))
216
+
217
+ {
218
+
219
+ pictureSprite.material = Resources.Load<Material>(string.Format("Materials/{0}", material));
220
+
221
+ }
222
+
223
+ }
224
+
225
+
226
+
227
+ /// <summary>
228
+
229
+ /// プレイできるか
230
+
231
+ /// </summary>
232
+
233
+ /// <param name="owner"></param>
234
+
235
+ /// <returns></returns>
236
+
237
+ public virtual bool CanBePlayed(DemoHumanPlayer owner)
238
+
239
+ {
240
+
241
+ return owner.isActivePlayer && owner.manaStat.effectiveValue >= manaCost;
242
+
243
+ }
244
+
245
+
246
+
247
+ /// <summary>
248
+
249
+ /// ハイライト付いてるか判定
250
+
251
+ /// </summary>
252
+
253
+ /// <returns></returns>
254
+
255
+ public bool IsHighlighted()
256
+
257
+ {
258
+
259
+ return glowSprite.enabled;
260
+
261
+ }
262
+
263
+
264
+
265
+ /// <summary>
266
+
267
+ /// ハイライトをセット
268
+
269
+ /// </summary>
270
+
271
+ /// <param name="enabled"></param>
272
+
273
+ public void SetHighlightingEnabled(bool enabled)
274
+
275
+ {
276
+
277
+ glowSprite.enabled = enabled;
278
+
279
+ }
280
+
281
+ }
282
+
283
+
284
+
285
+ ```
286
+
287
+
288
+
289
+ ### 聞きたいこと
290
+
291
+ RuntimeCard、あるいはCardViewクラスに、上記JSONファイルから値を持ってきてPlayCardクラスに渡しトークンBを召喚するにはどのようなコードを組めば良いでしょうか。
292
+
293
+ 慣れない質問で要領を得ない書き方になっているかもしれませんが、何卒よろしくお願い致します。
294
+
295
+ 不足している情報があればコメントお願いします。

1

重複のため削除しました

2018/04/30 12:16

投稿

imohori708
imohori708

スコア10

test CHANGED
@@ -1,285 +1 @@
1
- 以下、手札からボードにカードを召喚する箇所と思しきソースコード
2
-
3
- ```C#
4
-
5
- public void PlayCard(CardView card)
6
-
7
- {
8
-
9
- if (card.CanBePlayed(this))
10
-
11
- {
12
-
13
- gameUI.endTurnButton.SetEnabled(false);
14
-
15
-
16
-
17
- var gameConfig = GameManager.Instance.config;
18
-
19
- var libraryCard = gameConfig.GetCard(card.card.cardId);
20
-
21
- //スペルかミニオンか
22
-
23
- var cardType = gameConfig.cardTypes.Find(x => x.id == libraryCard.cardTypeId);
24
-
25
- if (cardType.name == "Creature")
26
-
27
- {
28
-
29
- //ミニオンをボード上にプレハブ化
30
-
31
- var boardCreature = Instantiate(boardCreaturePrefab);
32
-
33
-
34
-
35
- var board = GameObject.Find("PlayerBoard");
36
-
37
- boardCreature.tag = "PlayerOwned";
38
-
39
- boardCreature.transform.parent = board.transform;
40
-
41
- boardCreature.transform.position = new Vector2(1.9f * playerBoardCards.Count, 0);
42
-
43
- boardCreature.GetComponent<BoardCreature>().ownerPlayer = this;
44
-
45
- boardCreature.GetComponent<BoardCreature>().PopulateWithInfo(card.card);
46
-
47
-
48
-
49
- //手札からプレイしたカードを消す
50
-
51
- playerHandCards.Remove(card);
52
-
53
- RearrangeHand();
1
+ 内容重複のため削除済み
54
-
55
- playerBoardCards.Add(boardCreature.GetComponent<BoardCreature>());
56
-
57
-
58
-
59
- //手札のカードのオブジェクトを削除
60
-
61
- Destroy(card.gameObject);
62
-
63
-
64
-
65
- currentCreature = boardCreature.GetComponent<BoardCreature>();
66
-
67
-
68
-
69
- //ボードの描画処理
70
-
71
- RearrangeBottomBoard(() =>{var triggeredAbilities = libraryCard.abilities.FindAll(x => x is TriggeredAbility);
72
-
73
- TriggeredAbility targetableAbility = null;
74
-
75
- foreach (var ability in triggeredAbilities)
76
-
77
- {
78
-
79
- var triggeredAbility = ability as TriggeredAbility;
80
-
81
- var trigger = triggeredAbility.trigger as OnCardEnteredZoneTrigger;
82
-
83
- if (trigger != null && trigger.zoneId == boardZone.zoneId && triggeredAbility.target is IUserTarget)
84
-
85
- {
86
-
87
- targetableAbility = triggeredAbility;
88
-
89
- break;
90
-
91
- }
92
-
93
- }
94
-
95
-
96
-
97
- // Preemptively move the card so that the effect solver can properly check the availability of targets
98
-
99
- // by also taking into account this card (that is trying to be played).
100
-
101
- //プレイしようとしているカードも考慮して、エフェクトソルバーがターゲットの使用可能性を適切にチェックできるように、先制してカードを移動します。
102
-
103
- playerInfo.namedZones["Hand"].RemoveCard(card.card);
104
-
105
- playerInfo.namedZones["Board"].AddCard(card.card);
106
-
107
-
108
-
109
- //ターゲットを取るアビリティがあり、且つターゲットがいる場合
110
-
111
- if (targetableAbility != null && effectSolver.AreTargetsAvailable(targetableAbility.effect, card.card, targetableAbility.target))
112
-
113
- {
114
-
115
- var targetingArrow = Instantiate(spellTargetingArrowPrefab).GetComponent<SpellTargetingArrow>();
116
-
117
- boardCreature.GetComponent<BoardCreature>().abilitiesTargetingArrow = targetingArrow;
118
-
119
- targetingArrow.effectTarget = targetableAbility.target;
120
-
121
- targetingArrow.targetType = targetableAbility.target.GetTarget();
122
-
123
- targetingArrow.onTargetSelected += () =>
124
-
125
- {
126
-
127
- PlayCreatureCard(card.card, targetingArrow.targetInfo);
128
-
129
- effectSolver.MoveCard(netId, card.card, "Hand", "Board", targetingArrow.targetInfo);
130
-
131
- currentCreature = null;
132
-
133
- gameUI.endTurnButton.SetEnabled(true);
134
-
135
- };
136
-
137
- targetingArrow.Begin(boardCreature.transform.localPosition);
138
-
139
- }
140
-
141
- else
142
-
143
- {
144
-
145
- PlayCreatureCard(card.card);
146
-
147
- effectSolver.MoveCard(netId, card.card, "Hand", "Board");
148
-
149
- currentCreature = null;
150
-
151
- gameUI.endTurnButton.SetEnabled(true);
152
-
153
- }
154
-
155
- boardCreature.GetComponent<BoardCreature>().fightTargetingArrowPrefab = fightTargetingArrowPrefab;
156
-
157
- });
158
-
159
- }
160
-
161
- //スペルの場合
162
-
163
- else if (cardType.name == "Spell")
164
-
165
- {
166
-
167
- var spellsPivot = GameObject.Find("PlayerSpellsPivot");
168
-
169
- var sequence = DOTween.Sequence();
170
-
171
- sequence.Append(card.transform.DOMove(spellsPivot.transform.position, 0.5f));
172
-
173
- sequence.Insert(0, card.transform.DORotate(Vector3.zero, 0.2f));
174
-
175
- sequence.Play().OnComplete(() =>
176
-
177
- {
178
-
179
- card.GetComponent<SortingGroup>().sortingLayerName = "BoardCards";
180
-
181
- card.GetComponent<SortingGroup>().sortingOrder = 1000;
182
-
183
-
184
-
185
- var boardSpell = card.gameObject.AddComponent<BoardSpell>();
186
-
187
-
188
-
189
- var triggeredAbilities = libraryCard.abilities.FindAll(x => x is TriggeredAbility);
190
-
191
- TriggeredAbility targetableAbility = null;
192
-
193
- foreach (var ability in triggeredAbilities)
194
-
195
- {
196
-
197
- var triggeredAbility = ability as TriggeredAbility;
198
-
199
- var trigger = triggeredAbility.trigger as OnCardEnteredZoneTrigger;
200
-
201
- //トリガーがあり、ボードに入ることがトリガーで、且つユーザーがターゲットを指定している場合
202
-
203
- if (trigger != null && trigger.zoneId == boardZone.zoneId && triggeredAbility.target is IUserTarget)
204
-
205
- {
206
-
207
- targetableAbility = triggeredAbility;
208
-
209
- break;
210
-
211
- }
212
-
213
- }
214
-
215
-
216
-
217
- currentSpellCard = card;
218
-
219
- //ターゲットを取るアビリティがあり、且つターゲットがいる場合、ターゲットを指定してスペルの処理をする
220
-
221
- if (targetableAbility != null && effectSolver.AreTargetsAvailable(targetableAbility.effect, card.card, targetableAbility.target))
222
-
223
- {
224
-
225
- var targetingArrow = Instantiate(spellTargetingArrowPrefab).GetComponent<SpellTargetingArrow>();
226
-
227
- boardSpell.targetingArrow = targetingArrow;
228
-
229
- targetingArrow.effectTarget = targetableAbility.target;
230
-
231
- targetingArrow.targetType = targetableAbility.target.GetTarget();
232
-
233
- targetingArrow.onTargetSelected += () =>
234
-
235
- {
236
-
237
- PlaySpellCard(card.card, targetingArrow.targetInfo);
238
-
239
- effectSolver.MoveCard(netId, card.card, "Hand", "Board", targetingArrow.targetInfo);
240
-
241
- currentSpellCard = null;
242
-
243
- gameUI.endTurnButton.SetEnabled(true);
244
-
245
- };
246
-
247
- targetingArrow.Begin(boardSpell.transform.localPosition);
248
-
249
- }
250
-
251
- else
252
-
253
- //そうでなければそのまま処理
254
-
255
- {
256
-
257
- PlaySpellCard(card.card);
258
-
259
- effectSolver.MoveCard(netId, card.card, "Hand", "Board");
260
-
261
- currentSpellCard = null;
262
-
263
- gameUI.endTurnButton.SetEnabled(true);
264
-
265
- }
266
-
267
- });
268
-
269
- }
270
-
271
- }
272
-
273
- else
274
-
275
- {
276
-
277
- card.GetComponent<HandCard>().ResetToInitialPosition();
278
-
279
- }
280
-
281
- }
282
-
283
- ```
284
-
285
- 上記メソッドの引数となっているCarViewクラスは、GUIでマウス左クリック時にぶつかったobjectを判定することによって値を取得してきているため、GUI描画のない、デッキやハンドの外からトークンBを選択することは出来ません。