質問するログイン新規登録

質問編集履歴

2

コード全文追記

2020/05/31 16:22

投稿

MOTOMUR
MOTOMUR

スコア195

title CHANGED
File without changes
body CHANGED
@@ -1,11 +1,27 @@
1
1
  自作したクラスを配列で扱うために、
2
- ```C#
3
- 「master.cs
2
+ ```MasterData.cs
3
+ using System.Collections;
4
+ using System.Collections.Generic;
5
+ using UnityEngine;
6
+
4
- public class master : MonoBehaviour{
7
+ public class MasterData : MonoBehaviour
8
+ {
5
- public static member[] MemberArray;
9
+ public static AllyMemberStatus[] AllyMemberStatusArray; //冒険者パーティー。一覧。
10
+ public static AllyMemberStatus[] AllyMemberSelectedArray;//パーティ選出メンバー管理用。
11
+
12
+
13
+
14
+ // Start is called before the first frame update
6
- void Start()
15
+ void Start()
7
16
  {
17
+ DontDestroyOnLoad(this);
18
+
19
+ bool InitialGame = true;
20
+
21
+ var AllyMemberStatusList = new List<AllyMemberStatus>();
22
+ if (InitialGame)
23
+ {
8
- AllyStatus a1 = Resources.Load<AllyStatus>("AllyStatus/いち/1");
24
+ AllyStatus a1 = Resources.Load<AllyStatus>("AllyStatus/いち/1");
9
25
  AllyMemberStatus aa1 = new AllyMemberStatus();
10
26
  aa1 = a1.GetAllyMemberStatus();
11
27
  AllyMemberStatusArray = new AllyMemberStatus[1] {aa1};
@@ -14,22 +30,206 @@
14
30
  AllyStatus a2 = Resources.Load<AllyStatus>("AllyStatus/に/1");
15
31
  AllyMemberStatus aa2 = new AllyMemberStatus();
16
32
  aa2 = a2.GetAllyMemberStatus();
33
+
34
+ System.Array.Resize(ref AllyMemberStatusArray, AllyMemberStatusArray.Length + 1);
35
+ AllyMemberStatusArray[AllyMemberStatusArray.Length - 1] = aa2;
36
+ AllyMemberSelectedArray = new AllyMemberStatus[2] { aa1, aa2 };
37
+
38
+ Debug.Log(AllyMemberStatusArray[0].GetCharactorName());
39
+ Debug.Log(AllyMemberStatusArray[1].GetCharactorName());
40
+ InitialGame = false;
41
+ }
17
42
  }
43
+
44
+ // Update is called once per frame
45
+ void Update()
46
+ {
47
+
48
+ }
18
49
  }
19
- -----------------------------------------
20
- 「AllyStatus.cs」
21
50
 
51
+ ```
22
- public class AllyStatus : scriptableObject{
52
+ ```AllyStatus.cs
23
- public string memberName;
24
- public int HP;
53
+ using System;
54
+ using System.Collections;
55
+ using System.Collections.Generic;
56
+ using System.Linq;
57
+ using UnityEngine;
58
+ using UnityEngine.UI;
25
59
 
26
- GetAllyMemberStatus(){
60
+ [Serializable]
61
+ [CreateAssetMenu(fileName = "AllyStatus" , menuName = "CreateAllyStatus")]
27
- //略 AllyStatusをmonoBehaviorのAllyMemberStatusに変換している}
62
+ public class AllyStatus : CharactorsStatus
63
+ {
64
+
65
+
28
66
  }
67
+
29
68
  ```
69
+ ```CharactorStatus.cs
70
+ using System;
71
+ using System.Collections;
72
+ using System.Collections.Generic;
73
+ using System.Linq;
74
+ using UnityEngine;
75
+ using UnityEngine.UI;
30
76
 
77
+ [Serializable]
31
- 上記のコードを作成しました。AllyStatus.csは実際の問題のあったコードだと長いので略。原因不明の場合は修正で追記します。)
78
+ public abstract class CharactorsStatus : ScriptableObject
79
+ {
32
80
 
81
+ [SerializeField]
82
+ private string charactorName = " ";
83
+ [SerializeField]
84
+ private string CharactorID = System.Guid.NewGuid().ToString("N");
85
+ [SerializeField]
86
+ private int level = 1;
87
+ [SerializeField]
88
+ private JobType.JobKind jobType =JobType.JobKind.戦士;
89
+ [SerializeField]
90
+ private JobType.JobName jobName = JobType.JobName.戦士;
91
+ [SerializeField]
92
+ private WeaponEnum.AllWeapon equipWeapon;
93
+
94
+ [SerializeField]
95
+ private int earnedExperience = 0;
96
+ [SerializeField]
97
+ private int nextLvUpExperience = 0;
98
+
99
+ [SerializeField]
100
+ private int maxHP = 100;
101
+ [SerializeField]
102
+ private int nowHP = 100;
103
+ [SerializeField]
104
+ private int maxMP = 30;
105
+ [SerializeField]
106
+ private int nowMP = 30;
107
+ [SerializeField]
108
+ private int ATK = 20;
109
+ [SerializeField]
110
+ private int DEF = 10;
111
+ [SerializeField]
112
+ private int INT = 15;
113
+ [SerializeField]
114
+ private int MND = 10;
115
+ [SerializeField]
116
+ private int DEX = 10;
117
+ [SerializeField]
118
+ private int AGI = 10;
119
+ [SerializeField]
120
+ private int CRI = 5;
121
+
122
+ [SerializeField]
123
+ private bool isPoisonState = false;
124
+ [SerializeField]
125
+ private bool isNumbnessState = false;
126
+ [SerializeField]
127
+ private bool isSelected = false;
128
+
129
+ /*上記の要素すべてのget setは省略。*/
130
+
131
+ public AllyMemberStatus GetAllyMemberStatus()
132
+ {
133
+ AllyMemberStatus allyMemberStatus = new AllyMemberStatus();
134
+ allyMemberStatus.SetCharactorName(charactorName);
135
+ allyMemberStatus.SetCharactorID(CharactorID);
136
+ allyMemberStatus.SetLevel(level);
137
+ allyMemberStatus.SetJobType(jobType);
138
+ allyMemberStatus.SetJobName(jobName);
139
+ allyMemberStatus.SetEquipWeapon(equipWeapon);
140
+ allyMemberStatus.SetEarnedExperience(earnedExperience);
141
+ allyMemberStatus.SetNextLvUpExperience(nextLvUpExperience);
142
+ allyMemberStatus.SetMaxHP(maxHP);
143
+ allyMemberStatus.SetNowHP(nowHP);
144
+ allyMemberStatus.SetMaxMP(maxMP);
145
+ allyMemberStatus.SetNowMP(nowMP);
146
+ allyMemberStatus.SetATK(ATK);
147
+ allyMemberStatus.SetDEF(DEF);
148
+ allyMemberStatus.SetINT(INT);
149
+ allyMemberStatus.SetMND(MND);
150
+ allyMemberStatus.SetDEX(DEX);
151
+ allyMemberStatus.SetAGI(AGI);
152
+ allyMemberStatus.SetCRI(CRI);
153
+ return allyMemberStatus;
154
+ }
155
+
156
+
157
+
158
+ // Start is called before the first frame update
159
+ void Start()
160
+ {
161
+ DontDestroyOnLoad(this);
162
+ }
163
+
164
+
165
+ }
166
+
167
+
168
+ ```
169
+
170
+
171
+ ```AllyMemberStatus
172
+ using System.Collections;
173
+ using System.Collections.Generic;
174
+ using UnityEngine;
175
+
176
+ public class AllyMemberStatus : MonoBehaviour
177
+ {
178
+ public static string charactorName = " ";
179
+ public static string CharactorID;
180
+ public static int level = 1;
181
+ public static JobType.JobKind jobType = JobType.JobKind.戦士;
182
+ public static JobType.JobName jobName = JobType.JobName.戦士;
183
+ public static WeaponEnum.AllWeapon equipWeapon;
184
+
185
+
186
+ public static int earnedExperience = 0;
187
+ public static int nextLvUpExperience = 0;
188
+
189
+ public static int maxHP = 100;
190
+ public static int nowHP = 100;
191
+ public static int maxMP = 30;
192
+ public static int nowMP = 30;
193
+ public static int ATK = 20;
194
+ public static int DEF = 10;
195
+ public static int INT = 15;
196
+ public static int MND = 10;
197
+ public static int DEX = 10;
198
+ public static int AGI = 10;
199
+ public static int CRI = 5;
200
+
201
+
202
+ public static bool isPoisonState = false;
203
+ public static bool isNumbnessState = false;
204
+ public static bool isSelected = false;
205
+
206
+ public void SetCharactorName(string CharactorName)
207
+ {
208
+ charactorName = CharactorName;
209
+ }
210
+
211
+ public string GetCharactorName()
212
+ {
213
+ return charactorName;
214
+ }
215
+ public void SetCharactorID(string CharactorId)
216
+ {
217
+ CharactorID = CharactorId;
218
+ }
219
+ /*上記以外のすべての要素のget setは省略。*/
220
+
221
+ // Start is called before the first frame update
222
+ void Start()
223
+ {
224
+ DontDestroyOnLoad(this);
225
+ }
226
+
227
+ }
228
+
229
+ ```
230
+
231
+ 上記のコードを作成しました。AllyMemberStatus.csは実際に使用しているget,set以外略。原因不明の場合は修正で追記します。)
232
+
33
233
  scriptableObjectのallyStatus型を読み込み、GetAllyMemberStatus()して、変換して、AllyMemberStatusArrayに保存しています。
34
234
 
35
235
  出力結果

1

かきなおし

2020/05/31 16:22

投稿

MOTOMUR
MOTOMUR

スコア195

title CHANGED
File without changes
body CHANGED
@@ -28,7 +28,7 @@
28
28
  }
29
29
  ```
30
30
 
31
- というもがあっとするAllyStatus.csは実際の問題のあったコードだと長いので略。原因不明の場合は修正で追記します。)
31
+ 上記コードを作成しました。AllyStatus.csは実際の問題のあったコードだと長いので略。原因不明の場合は修正で追記します。)
32
32
 
33
33
  scriptableObjectのallyStatus型を読み込み、GetAllyMemberStatus()して、変換して、AllyMemberStatusArrayに保存しています。
34
34