@@ -101,7 +101,7 @@ private static string GeneratePropertiesCode(List<CommandProperty> commandProper
101101 properties . AppendLine ( ) ;
102102 foreach ( var property in commandProperties )
103103 {
104- var type = GetTypeCode ( property . Type , property . IsRequired ) ;
104+ var type = GetTypeCode ( property . Type ) ;
105105 properties . AppendLine ( $ "public readonly { type } { property . CodeProperty } ;") ;
106106 }
107107
@@ -114,85 +114,39 @@ private static string GenerateCreateMethodTempVariables(List<CommandProperty> co
114114 properties . AppendLine ( ) ;
115115 foreach ( var property in commandProperties )
116116 {
117- var type = GetTypeCode ( property . Type , property . IsRequired ) ;
118-
119- if ( property . IsRequired )
117+ var type = GetTypeCode ( property . Type ) ;
118+ if ( property . Type is CommandPropertyType . CommandId )
119+ {
120+ properties . AppendLine ( $ "var { property . CodeProperty } = (CommandId)((int)json[\" { property . Name } \" ]);") ;
121+ }
122+ else if ( property . Type is CommandPropertyType . Vector2 )
123+ {
124+ properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
125+ properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector2((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1]);") ;
126+ }
127+ else if ( property . Type is CommandPropertyType . Vector3 )
128+ {
129+ properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
130+ properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector3((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2]);") ;
131+ }
132+ else if ( property . Type is CommandPropertyType . Vector4 )
133+ {
134+ properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
135+ properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector4((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2], (float){ property . CodeProperty } Array[3]);") ;
136+ }
137+ else if ( property . Type is CommandPropertyType . Vector2Int )
120138 {
121- // required の場合は従来通り
122- if ( property . Type is CommandPropertyType . CommandId )
123- {
124- properties . AppendLine ( $ "var { property . CodeProperty } = (CommandId)((int)json[\" { property . Name } \" ]);") ;
125- }
126- else if ( property . Type is CommandPropertyType . Vector2 )
127- {
128- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
129- properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector2((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1]);") ;
130- }
131- else if ( property . Type is CommandPropertyType . Vector3 )
132- {
133- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
134- properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector3((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2]);") ;
135- }
136- else if ( property . Type is CommandPropertyType . Vector4 )
137- {
138- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
139- properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector4((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2], (float){ property . CodeProperty } Array[3]);") ;
140- }
141- else if ( property . Type is CommandPropertyType . Vector2Int )
142- {
143- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
144- properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector2Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1]);") ;
145- }
146- else if ( property . Type is CommandPropertyType . Vector3Int )
147- {
148- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
149- properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector3Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1], (int){ property . CodeProperty } Array[2]);") ;
150- }
151- else
152- {
153- properties . AppendLine ( $ "var { property . CodeProperty } = ({ type } )json[\" { property . Name } \" ];") ;
154- }
139+ properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
140+ properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector2Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1]);") ;
141+ }
142+ else if ( property . Type is CommandPropertyType . Vector3Int )
143+ {
144+ properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
145+ properties . AppendLine ( $ "var { property . CodeProperty } = new global::UnityEngine.Vector3Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1], (int){ property . CodeProperty } Array[2]);") ;
155146 }
156147 else
157148 {
158- // nullable の場合はnullチェックを追加
159- if ( property . Type is CommandPropertyType . String )
160- {
161- properties . AppendLine ( $ "var { property . CodeProperty } = json[\" { property . Name } \" ] == null ? null : (string)json[\" { property . Name } \" ];") ;
162- }
163- else if ( property . Type is CommandPropertyType . CommandId )
164- {
165- properties . AppendLine ( $ "var { property . CodeProperty } = json[\" { property . Name } \" ] == null ? null : (CommandId?)((int)json[\" { property . Name } \" ]);") ;
166- }
167- else if ( property . Type is CommandPropertyType . Vector2 )
168- {
169- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
170- properties . AppendLine ( $ "var { property . CodeProperty } = { property . CodeProperty } Array == null ? null : new global::UnityEngine.Vector2((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1]);") ;
171- }
172- else if ( property . Type is CommandPropertyType . Vector3 )
173- {
174- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
175- properties . AppendLine ( $ "var { property . CodeProperty } = { property . CodeProperty } Array == null ? null : new global::UnityEngine.Vector3((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2]);") ;
176- }
177- else if ( property . Type is CommandPropertyType . Vector4 )
178- {
179- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
180- properties . AppendLine ( $ "var { property . CodeProperty } = { property . CodeProperty } Array == null ? null : new global::UnityEngine.Vector4((float){ property . CodeProperty } Array[0], (float){ property . CodeProperty } Array[1], (float){ property . CodeProperty } Array[2], (float){ property . CodeProperty } Array[3]);") ;
181- }
182- else if ( property . Type is CommandPropertyType . Vector2Int )
183- {
184- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
185- properties . AppendLine ( $ "var { property . CodeProperty } = { property . CodeProperty } Array == null ? null : new global::UnityEngine.Vector2Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1]);") ;
186- }
187- else if ( property . Type is CommandPropertyType . Vector3Int )
188- {
189- properties . AppendLine ( $ "var { property . CodeProperty } Array = json[\" { property . Name } \" ];") ;
190- properties . AppendLine ( $ "var { property . CodeProperty } = { property . CodeProperty } Array == null ? null : new global::UnityEngine.Vector3Int((int){ property . CodeProperty } Array[0], (int){ property . CodeProperty } Array[1], (int){ property . CodeProperty } Array[2]);") ;
191- }
192- else
193- {
194- properties . AppendLine ( $ "var { property . CodeProperty } = json[\" { property . Name } \" ] == null ? null : ({ type } )json[\" { property . Name } \" ];") ;
195- }
149+ properties . AppendLine ( $ "var { property . CodeProperty } = ({ type } )json[\" { property . Name } \" ];") ;
196150 }
197151 }
198152
@@ -215,7 +169,7 @@ public static string GenerateConstructorPropertiesCode(List<CommandProperty> com
215169 var properties = new StringBuilder ( ) ;
216170 foreach ( var property in commandProperties )
217171 {
218- var type = GetTypeCode ( property . Type , property . IsRequired ) ;
172+ var type = GetTypeCode ( property . Type ) ;
219173 properties . Append ( $ ", { type } { property . CodeProperty } ") ;
220174
221175 }
@@ -235,9 +189,9 @@ private static string GenerateConstructSetPropertiesCode(List<CommandProperty> c
235189 return construct . ToString ( ) ;
236190 }
237191
238- private static string GetTypeCode ( CommandPropertyType type , bool isRequired )
192+ private static string GetTypeCode ( CommandPropertyType type )
239193 {
240- var baseType = type switch
194+ return type switch
241195 {
242196 CommandPropertyType . String => "string" ,
243197 CommandPropertyType . Int => "int" ,
@@ -251,20 +205,6 @@ private static string GetTypeCode(CommandPropertyType type, bool isRequired)
251205 CommandPropertyType . Vector3Int => "global::UnityEngine.Vector3Int" ,
252206 _ => throw new ArgumentOutOfRangeException ( nameof ( type ) , type , null )
253207 } ;
254-
255- // 値型でrequiredでない場合は nullable にする
256- if ( ! isRequired && type != CommandPropertyType . String )
257- {
258- return baseType + "?" ;
259- }
260-
261- // 参照型でも明示的に nullable にする(C# 8.0以降)
262- if ( ! isRequired && type == CommandPropertyType . String )
263- {
264- return baseType + "?" ;
265- }
266-
267- return baseType ;
268208 }
269209
270210 public static string GenerateLoaderCode ( CommandsSemantics commandsSemantics )
0 commit comments