/
Unit_Change.cs
414 lines (335 loc) · 13.1 KB
/
Unit_Change.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public class Unit_Change : MonoBehaviour
{
// ユニットの基礎攻撃力・ユニットの現在合計攻撃力・武器の基礎攻撃力・武器切り替えた後の合計攻撃力
List<GameObject> selectWindowList = new List<GameObject>(), teamAWindowList = new List<GameObject>();
private bool changeUnitIsRunning = false;// コルーチンの多重起動防止用
private bool isApply = false;// 二つ目が押されたかどうか
private int numberFrom, numberTo;// 入れ替え用、OnClick時の引数を元にする
private int weaponNumFrom, weaponNumTo;
private int selectWeaponChar, selectWeaponSlot;
UnitData[] unitData, teamA, keepData;
UnitSlotData[,] teamASlot;
WeaponData[] weaponData, keepWeaponData;
GameObject _unitDataWindow, _weaponAWindow, _changeSlotWindow;
void Start ()
{
EditList();
_unitDataWindow = GameObject.Find ( "CharTeam_WIndow (0)" );
_weaponAWindow = GameObject.Find ( "ChangeWeapon_WIndow (0)" );
_changeSlotWindow = GameObject.Find ( "SelectChangeSlot_WIndow (0)" );
_unitDataWindow.transform.localPosition = new Vector2 ( -800, -15 );
_weaponAWindow.transform.localPosition = new Vector2 ( 800, -15 );
_changeSlotWindow.transform.localPosition = new Vector2 ( -1600, -15 );
}
public int GetSelectWindowCount ( string windowName )
{
// Scene内の同タグオブジェクトを全て検索。見つかったウィンドウの数を返す
GameObject[] selWindowCount = GameObject.FindGameObjectsWithTag( windowName );
Debug.Log ( "シーン内にある " + windowName + " の数は " + selWindowCount.Length + "です" );
return selWindowCount.Length;
}
public void EditList ()
{
int maxCount = GetSelectWindowCount( "UnitSelectWindow");
unitData = new UnitData[6];
teamA = new UnitData[6];
teamASlot = new UnitSlotData[6,4];
keepData = new UnitData[1];
weaponData = new WeaponData[6];
keepWeaponData = new WeaponData[1];
for ( int i = 0; i < maxCount; i++ )
{
string charName = GetCharName ( i );
string weaponName = GetWeaponName ( i );
// -----
weaponData[i] = new WeaponData ( i, weaponName, ( ( i + 1 ) * 2 ) );
GameObject _weaponNameText = GameObject.Find ( "WeaponText_List (" + i + ")" );
_weaponNameText.GetComponent<Text>().text = weaponData[i].weapon_name.ToString();
GameObject _weaponAttackText = GameObject.Find ( "WeaponAttack_Text (" + i + ")" );
_weaponAttackText.GetComponent<Text>().text = weaponData[i].attack.ToString();
for ( int j = 0; j < 4; j++ )
{
teamASlot[i,j] = new UnitSlotData ( i, GetWeaponName( j ), ( ( i + 1 ) * 2 ) );
Debug.Log ( j + ": " + teamASlot[i,j] );
}
// -----
unitData[i] = new UnitData( ( i ), charName, ( i ) );
teamA[i] = new UnitData( ( i ), charName, ( i ) );
GameObject selWindow = GameObject.Find ( "CharSelect_List (" + i.ToString() + ")" );
selectWindowList.Add( selWindow );
GameObject teamAWindow = GameObject.Find ( "UnitSlot (" + i.ToString() + ")" );
teamAWindowList.Add( teamAWindow );
GameObject teamAPowerText = GameObject.Find ( "PowerInfo_Text (" + i + ")" );
teamAPowerText.GetComponent<Text>().text = ( "合計攻撃力:" + teamA[i].attack.ToString() );
GameObject teamACharText = GameObject.Find ( "TeamACharText_List (" + i + ")" );
teamACharText.GetComponent<Text>().text = GetCharName (i);
// 部隊外分
GameObject childSprite = selectWindowList[i].gameObject.transform.FindChild("CharSprite_Panel/CharSprite_List (" + i.ToString() + ")" ).gameObject;
childSprite.GetComponent<Image>().sprite = Resources.Load<Sprite> ( "Sprites/Character/MiniChar_" + unitData[i].char_no.ToString() );
GameObject childText = GameObject.Find ( "CharText_List (" + i + ")" );
charName = GetCharName ( unitData[i].char_no );
childText.GetComponent<Text>().text = charName;
// 部隊分
GameObject teamASprite = GameObject.Find ("SpriteSlot (" + i.ToString() + ")" ).gameObject;
teamASprite.GetComponent<Image>().sprite = Resources.Load<Sprite> ( "Sprites/Character/MiniChar_" + unitData[i].char_no.ToString() );
}
}
public void RefreshListOnly ()
{
Debug.Log ( " RefreshListOnly was RUNNED " );
int maxCount = GetSelectWindowCount( "UnitSelectWindow" );
// weaponウィンドウとunitウィンドウ両方を個別に更新するべき?
for ( int i = 0; i < maxCount; i++ )
{
GameObject childSprite = GameObject.Find( "CharSprite_List (" + i.ToString() + ")" ).gameObject;
childSprite.GetComponent<Image>().sprite = Resources.Load<Sprite> ( "Sprites/Character/MiniChar_" + unitData[i].char_no.ToString() );
GameObject childText = GameObject.Find ( "CharText_List (" + i + ")" );
string charName = GetCharName ( unitData[i].char_no );
childText.GetComponent<Text>().text = charName.ToString();
GameObject teamAPowerText = GameObject.Find ( "PowerInfo_Text (" + i + ")" );
teamAPowerText.GetComponent<Text>().text = ( "合計攻撃力:" + teamA[i].attack.ToString() );
// teamAの入れ替え
GameObject teamASprite = GameObject.Find( "SpriteSlot (" + i.ToString() + ")" ).gameObject;
teamASprite.GetComponent<Image>().sprite = Resources.Load<Sprite> ( "Sprites/Character/MiniChar_" + teamA[i].char_no.ToString() );
isApply = false;
}
}
public void ChangeUnitFrom ( int slotNumber )
{
Sound_Manager.Instance.PlaySE(1);
_unitDataWindow.transform.localPosition = new Vector2 ( 0, -15 );
StopCoroutine ( "WaitForApply" );// 既にコルーチンが起動していた場合それを停止 ( 選択しなおす )
numberFrom = slotNumber;
Debug.Log ( "「" + numberFrom + "」" + " が選択されました…入れ替え先 ( 部隊外ウィンドウ ) を選択してください。" );
StartCoroutine ( "WaitForApply" );
}
public void ChangeUnitTo ( int slotNumber )
{
Sound_Manager.Instance.PlaySE(1);
_unitDataWindow.transform.localPosition = new Vector2 ( -800, -15 );
numberTo = slotNumber;
Debug.Log ( "「" + numberTo + "」" + " が選択されました…対応する配列の入れ替えを行います" );
isApply = true;
}
// この関数で数値の受け渡しを行う
public void ChangeUnitFromTo ()
{
// 変数の入れ替え。配列keepDataに一旦保存して受け渡しを行う
keepData[0] = teamA[numberFrom];// AをXに
teamA[numberFrom] = unitData[numberTo];// BをAに
unitData[numberTo] = keepData[0];// XをAに
changeUnitIsRunning = false;
RefreshListOnly();// リストを更新する
return;
}
public void ChangeWeaponFrom ( int slotNumber )
{
selectWeaponSlot = slotNumber;
Sound_Manager.Instance.PlaySE(1);
_changeSlotWindow.transform.localPosition = new Vector2 ( -1600, -15 );
_weaponAWindow.transform.localPosition = new Vector2 ( 0, -15 );
StopCoroutine ( "WaitForWeaponApply" );// 既にコルーチンが起動していた場合それを停止 ( 選択しなおす )
numberFrom = slotNumber;
Debug.Log ( "「" + numberFrom + "」" + " が選択されました…入れ替え先 ( 部隊外ウィンドウ ) を選択してください。" );
GameObject unitCurrentText = GameObject.Find ("UnitCurrentPower" );
unitCurrentText.GetComponent<Text>().text = teamA[numberFrom].attack.ToString();
StartCoroutine ( "WaitForWeaponApply" );
}
public void ChangeWeaponTo ( int slotNumber )
{
Sound_Manager.Instance.PlaySE(1);
numberTo = slotNumber;
Debug.Log ( "「" + numberTo + "」" + " が選択されました…決定で対応する配列の入れ替えを行います" );
GameObject unitAmountText = GameObject.Find ("UnitAmountPower");
unitAmountText.GetComponent<Text>().text = (weaponData[numberTo].attack + teamA[numberFrom].attack ).ToString();
}
public void ChangeWeaponFromTo ()
{
//keepWeaponData[0] = teamASlot[selectWeaponChar,selectWeaponSlot];// AをXに
//teamASlot[selectWeaponChar,selectWeaponSlot] = weaponData[numberTo];// BをAに
//weaponData[numberTo] = keepWeaponData[0];// XをAに
changeUnitIsRunning = false;
isApply = false;
RefreshListOnly();// リストを更新する
Debug.Log ( this.gameObject.name + "ユニットの装備を入れ替えました。" );
return;
}
public void SelectWeaponChar ( int selectWeaponChar )
{
this.selectWeaponChar = selectWeaponChar;
Debug.Log ( this.selectWeaponChar + " 番の装備スロットを表示します" );
_changeSlotWindow.transform.localPosition = new Vector2 ( -0, -15 );
for ( int i = 0; i < 4; i++ )
{
GameObject _weaponSlot = GameObject.Find ( "WeaponSlotName (" + i + ")" );
_weaponSlot.GetComponent<Text>().text = teamASlot[selectWeaponChar,i].weapon_name.ToString();
}
}
public void SetBeforeInfo ( int weaponNum )
{
GameObject _beforeWeaponNameText = GameObject.Find ( "BeforeWeaponName_Text" );
GameObject _beforeWeaponAttackText = GameObject.Find ( "BeforeWeaponAttack_Text" );
GameObject _beforeWeaponImage = GameObject.Find ( "BeforeWeapon_Image" );
_beforeWeaponNameText.GetComponent<Text>().text = teamASlot[selectWeaponChar,selectWeaponSlot].weapon_name.ToString();
_beforeWeaponAttackText.GetComponent<Text>().text = teamASlot[selectWeaponChar,selectWeaponSlot].attack.ToString();
}
public void SetAfterInfo ( int weaponNum )
{
GameObject _afterWeaponNameText = GameObject.Find ( "AfterWeaponName_Text" );
GameObject _afterWeaponAttackText = GameObject.Find ( "AfterWeaponAttack_Text" );
GameObject _afterWeaponImage = GameObject.Find ( "AfterWeapon_Image" );
_afterWeaponNameText.GetComponent<Text>().text = weaponData[weaponNum].weapon_name;
_afterWeaponAttackText.GetComponent<Text>().text = weaponData[weaponNum].attack.ToString();
}
// 最終決定 後で名称変える
public void WeaponApply ()
{
Sound_Manager.Instance.PlaySE(1);
_weaponAWindow.transform.localPosition = new Vector2 ( 800, -15 );
Debug.Log ( "装備の入れ替えを確定します。" );
isApply = true;
}
IEnumerator WaitForApply ()
{
if ( changeUnitIsRunning ) { yield break; }
changeUnitIsRunning = true;
while( !isApply )
{
Debug.Log ( "入力待ちです。" );
yield return 1;
}
ChangeUnitFromTo();
yield break;
}
IEnumerator WaitForWeaponApply ()
{
if ( changeUnitIsRunning ) { yield break; }
changeUnitIsRunning = true;
while( !isApply )
{
Debug.Log ( "入力待ちです。" );
yield return 1;
}
ChangeWeaponFromTo();
yield break;
}
// char_noにより名称を返す。仮データなので、データベースから排出される形式が決定次第ちゃんと引っ張るようにする。
public string GetCharName ( int num )
{
string name = "";
switch ( num )
{
case 0 :
name = "まどか";
break;
case 1 :
name = "ほむら";
break;
case 2 :
name = "さやか";
break;
case 3 :
name = "きょうこ";
break;
case 4 :
name = "マミ";
break;
case 5 :
name = "キュウべえ";
break;
default :
name = "けつばんくん";
break;
}
return name;
}
public string GetWeaponName ( int num )
{
string name = "";
switch ( num )
{
case 0 :
name = "キラー";
break;
case 1 :
name = "緑こうら";
break;
case 2 :
name = "赤こうら";
break;
case 3 :
name = "トリプル緑こうら";
break;
case 4 :
name = "トリプル赤こうら";
break;
case 5 :
name = "バナナ";
break;
default :
name = "けつばんアイテム";
break;
}
return name;
}
}
public class UnitData
{
// ----------- 各ユニット固有の値
public int char_no = 0;
public string char_name = "";
public int groups;
// ----------- コスト等として増減する値
public int useSlot, maxSlot = 1;
public int hp, maxHp;
public int fuel, maxFuel;
public int bullet, maxBullet;
// ----------- 戦闘処理に関わる値
public int attack;
public int long_power, middle_power, short_power, shield_power;
public int defense, avoidance, speed;
public int sphit, searchEnemy, luck, exp;
// -----------
public UnitData ( int char_no, string char_name, int attack )
{
this.char_no = char_no;
this.char_name = char_name;
this.attack = attack;
/*int char_no, string char_name, int groups, int useSlot, int maxSlot, int hp, int maxHp, int fuel
, int maxFuel, int bullet, int maxBullet, int long_power, int middle_power, int short_power, int shield_power
, int defense, int avoidance, int speed, int sphit, int searchEnemy, int luck, int exp // データベースによって変わってくる引数たち*/
}
}
public class WeaponData
{
// ----------- 各ユニット固有の値
public int weapon_no = 0;
public string weapon_name = "";
public int attack = 0;
// -----------
public WeaponData ( int weapon_no, string weapon_name, int attack )
{
this.weapon_no = weapon_no;
this.weapon_name = weapon_name;
this.attack = attack;
}
}
public class UnitSlotData
{
// ----------- 各ユニット固有の値
public int weapon_no = 0;
public string weapon_name = "";
public int attack = 0;
// -----------
public UnitSlotData ( int weapon_no, string weapon_name, int attack )
{
this.weapon_no = weapon_no;
this.weapon_name = weapon_name;
this.attack = attack;
}
}