質問編集履歴

2

コード全文追記

2020/05/31 16:22

投稿

MOTOMUR
MOTOMUR

スコア195

test CHANGED
File without changes
test CHANGED
@@ -1,18 +1,50 @@
1
1
  自作したクラスを配列で扱うために、
2
2
 
3
- ```C#
4
-
5
- 「master.cs
3
+ ```MasterData.cs
4
+
6
-
5
+ using System.Collections;
6
+
7
+ using System.Collections.Generic;
8
+
9
+ using UnityEngine;
10
+
11
+
12
+
7
- public class master : MonoBehaviour{
13
+ public class MasterData : MonoBehaviour
14
+
8
-
15
+ {
16
+
9
- public static member[] MemberArray;
17
+ public static AllyMemberStatus[] AllyMemberStatusArray; //冒険者パーティー。一覧。
18
+
10
-
19
+ public static AllyMemberStatus[] AllyMemberSelectedArray;//パーティ選出メンバー管理用。
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+ // Start is called before the first frame update
28
+
11
- void Start()
29
+ void Start()
12
-
30
+
13
- {
31
+ {
32
+
14
-
33
+ DontDestroyOnLoad(this);
34
+
35
+
36
+
37
+ bool InitialGame = true;
38
+
39
+
40
+
41
+ var AllyMemberStatusList = new List<AllyMemberStatus>();
42
+
43
+ if (InitialGame)
44
+
45
+ {
46
+
15
- AllyStatus a1 = Resources.Load<AllyStatus>("AllyStatus/いち/1");
47
+ AllyStatus a1 = Resources.Load<AllyStatus>("AllyStatus/いち/1");
16
48
 
17
49
  AllyMemberStatus aa1 = new AllyMemberStatus();
18
50
 
@@ -30,35 +62,403 @@
30
62
 
31
63
  aa2 = a2.GetAllyMemberStatus();
32
64
 
65
+
66
+
67
+ System.Array.Resize(ref AllyMemberStatusArray, AllyMemberStatusArray.Length + 1);
68
+
69
+ AllyMemberStatusArray[AllyMemberStatusArray.Length - 1] = aa2;
70
+
71
+ AllyMemberSelectedArray = new AllyMemberStatus[2] { aa1, aa2 };
72
+
73
+
74
+
75
+ Debug.Log(AllyMemberStatusArray[0].GetCharactorName());
76
+
77
+ Debug.Log(AllyMemberStatusArray[1].GetCharactorName());
78
+
79
+ InitialGame = false;
80
+
81
+ }
82
+
83
+ }
84
+
85
+
86
+
87
+ // Update is called once per frame
88
+
89
+ void Update()
90
+
91
+ {
92
+
93
+
94
+
33
95
  }
34
96
 
35
97
  }
36
98
 
99
+
100
+
37
- -----------------------------------------
101
+ ```
38
-
102
+
39
- AllyStatus.cs
103
+ ```AllyStatus.cs
104
+
40
-
105
+ using System;
106
+
41
-
107
+ using System.Collections;
108
+
42
-
109
+ using System.Collections.Generic;
110
+
111
+ using System.Linq;
112
+
113
+ using UnityEngine;
114
+
115
+ using UnityEngine.UI;
116
+
117
+
118
+
119
+ [Serializable]
120
+
121
+ [CreateAssetMenu(fileName = "AllyStatus" , menuName = "CreateAllyStatus")]
122
+
43
- public class AllyStatus : scriptableObject{
123
+ public class AllyStatus : CharactorsStatus
44
-
45
- public string memberName;
124
+
46
-
47
- public int HP;
48
-
49
-
50
-
51
- GetAllyMemberStatus(){
125
+ {
52
-
53
- //略 AllyStatusをmonoBehaviorのAllyMemberStatusに変換している}
126
+
127
+
128
+
129
+
54
130
 
55
131
  }
56
132
 
133
+
134
+
57
135
  ```
58
136
 
59
-
137
+ ```CharactorStatus.cs
138
+
60
-
139
+ using System;
140
+
141
+ using System.Collections;
142
+
143
+ using System.Collections.Generic;
144
+
145
+ using System.Linq;
146
+
147
+ using UnityEngine;
148
+
149
+ using UnityEngine.UI;
150
+
151
+
152
+
153
+ [Serializable]
154
+
155
+ public abstract class CharactorsStatus : ScriptableObject
156
+
157
+ {
158
+
159
+
160
+
161
+ [SerializeField]
162
+
163
+ private string charactorName = " ";
164
+
165
+ [SerializeField]
166
+
167
+ private string CharactorID = System.Guid.NewGuid().ToString("N");
168
+
169
+ [SerializeField]
170
+
171
+ private int level = 1;
172
+
173
+ [SerializeField]
174
+
175
+ private JobType.JobKind jobType =JobType.JobKind.戦士;
176
+
177
+ [SerializeField]
178
+
179
+ private JobType.JobName jobName = JobType.JobName.戦士;
180
+
181
+ [SerializeField]
182
+
183
+ private WeaponEnum.AllWeapon equipWeapon;
184
+
185
+
186
+
187
+ [SerializeField]
188
+
189
+ private int earnedExperience = 0;
190
+
191
+ [SerializeField]
192
+
193
+ private int nextLvUpExperience = 0;
194
+
195
+
196
+
197
+ [SerializeField]
198
+
199
+ private int maxHP = 100;
200
+
201
+ [SerializeField]
202
+
203
+ private int nowHP = 100;
204
+
205
+ [SerializeField]
206
+
207
+ private int maxMP = 30;
208
+
209
+ [SerializeField]
210
+
211
+ private int nowMP = 30;
212
+
213
+ [SerializeField]
214
+
215
+ private int ATK = 20;
216
+
217
+ [SerializeField]
218
+
219
+ private int DEF = 10;
220
+
221
+ [SerializeField]
222
+
223
+ private int INT = 15;
224
+
225
+ [SerializeField]
226
+
227
+ private int MND = 10;
228
+
229
+ [SerializeField]
230
+
231
+ private int DEX = 10;
232
+
233
+ [SerializeField]
234
+
235
+ private int AGI = 10;
236
+
237
+ [SerializeField]
238
+
239
+ private int CRI = 5;
240
+
241
+
242
+
243
+ [SerializeField]
244
+
245
+ private bool isPoisonState = false;
246
+
247
+ [SerializeField]
248
+
249
+ private bool isNumbnessState = false;
250
+
251
+ [SerializeField]
252
+
253
+ private bool isSelected = false;
254
+
255
+
256
+
257
+ /*上記の要素すべてのget setは省略。*/
258
+
259
+
260
+
261
+ public AllyMemberStatus GetAllyMemberStatus()
262
+
263
+ {
264
+
265
+ AllyMemberStatus allyMemberStatus = new AllyMemberStatus();
266
+
267
+ allyMemberStatus.SetCharactorName(charactorName);
268
+
269
+ allyMemberStatus.SetCharactorID(CharactorID);
270
+
271
+ allyMemberStatus.SetLevel(level);
272
+
273
+ allyMemberStatus.SetJobType(jobType);
274
+
275
+ allyMemberStatus.SetJobName(jobName);
276
+
277
+ allyMemberStatus.SetEquipWeapon(equipWeapon);
278
+
279
+ allyMemberStatus.SetEarnedExperience(earnedExperience);
280
+
281
+ allyMemberStatus.SetNextLvUpExperience(nextLvUpExperience);
282
+
283
+ allyMemberStatus.SetMaxHP(maxHP);
284
+
285
+ allyMemberStatus.SetNowHP(nowHP);
286
+
287
+ allyMemberStatus.SetMaxMP(maxMP);
288
+
289
+ allyMemberStatus.SetNowMP(nowMP);
290
+
291
+ allyMemberStatus.SetATK(ATK);
292
+
293
+ allyMemberStatus.SetDEF(DEF);
294
+
295
+ allyMemberStatus.SetINT(INT);
296
+
297
+ allyMemberStatus.SetMND(MND);
298
+
299
+ allyMemberStatus.SetDEX(DEX);
300
+
301
+ allyMemberStatus.SetAGI(AGI);
302
+
303
+ allyMemberStatus.SetCRI(CRI);
304
+
305
+ return allyMemberStatus;
306
+
307
+ }
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+ // Start is called before the first frame update
316
+
317
+ void Start()
318
+
319
+ {
320
+
321
+ DontDestroyOnLoad(this);
322
+
323
+ }
324
+
325
+
326
+
327
+
328
+
329
+ }
330
+
331
+
332
+
333
+
334
+
335
+ ```
336
+
337
+
338
+
339
+
340
+
341
+ ```AllyMemberStatus
342
+
343
+ using System.Collections;
344
+
345
+ using System.Collections.Generic;
346
+
347
+ using UnityEngine;
348
+
349
+
350
+
351
+ public class AllyMemberStatus : MonoBehaviour
352
+
353
+ {
354
+
355
+ public static string charactorName = " ";
356
+
357
+ public static string CharactorID;
358
+
359
+ public static int level = 1;
360
+
361
+ public static JobType.JobKind jobType = JobType.JobKind.戦士;
362
+
363
+ public static JobType.JobName jobName = JobType.JobName.戦士;
364
+
365
+ public static WeaponEnum.AllWeapon equipWeapon;
366
+
367
+
368
+
369
+
370
+
371
+ public static int earnedExperience = 0;
372
+
373
+ public static int nextLvUpExperience = 0;
374
+
375
+
376
+
377
+ public static int maxHP = 100;
378
+
379
+ public static int nowHP = 100;
380
+
381
+ public static int maxMP = 30;
382
+
383
+ public static int nowMP = 30;
384
+
385
+ public static int ATK = 20;
386
+
387
+ public static int DEF = 10;
388
+
389
+ public static int INT = 15;
390
+
391
+ public static int MND = 10;
392
+
393
+ public static int DEX = 10;
394
+
395
+ public static int AGI = 10;
396
+
397
+ public static int CRI = 5;
398
+
399
+
400
+
401
+
402
+
403
+ public static bool isPoisonState = false;
404
+
405
+ public static bool isNumbnessState = false;
406
+
407
+ public static bool isSelected = false;
408
+
409
+
410
+
411
+ public void SetCharactorName(string CharactorName)
412
+
413
+ {
414
+
415
+ charactorName = CharactorName;
416
+
417
+ }
418
+
419
+
420
+
421
+ public string GetCharactorName()
422
+
423
+ {
424
+
425
+ return charactorName;
426
+
427
+ }
428
+
429
+ public void SetCharactorID(string CharactorId)
430
+
431
+ {
432
+
433
+ CharactorID = CharactorId;
434
+
435
+ }
436
+
437
+ /*上記以外のすべての要素のget setは省略。*/
438
+
439
+
440
+
441
+ // Start is called before the first frame update
442
+
443
+ void Start()
444
+
445
+ {
446
+
447
+ DontDestroyOnLoad(this);
448
+
449
+ }
450
+
451
+
452
+
453
+ }
454
+
455
+
456
+
457
+ ```
458
+
459
+
460
+
61
- 上記のコードを作成しました。AllyStatus.csは実際の問題のあったコードだと長ので略。原因不明の場合は修正で追記します。)
461
+ 上記のコードを作成しました。AllyMemberStatus.csは実際に使用してるget,set以外略。原因不明の場合は修正で追記します。)
62
462
 
63
463
 
64
464
 

1

かきなおし

2020/05/31 16:22

投稿

MOTOMUR
MOTOMUR

スコア195

test CHANGED
File without changes
test CHANGED
@@ -58,7 +58,7 @@
58
58
 
59
59
 
60
60
 
61
- というもがあっとするAllyStatus.csは実際の問題のあったコードだと長いので略。原因不明の場合は修正で追記します。)
61
+ 上記コードを作成しました。AllyStatus.csは実際の問題のあったコードだと長いので略。原因不明の場合は修正で追記します。)
62
62
 
63
63
 
64
64