Skip to content

Commit 01a4c9d

Browse files
committed
Add vector types to command properties
1 parent 5790ae3 commit 01a4c9d

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

CommandForgeGenerator/CodeGenerate/CodeGenerator.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,31 @@ private static string GenerateCreateMethodTempVariables(List<CommandProperty> co
119119
{
120120
properties.AppendLine($"var {property.CodeProperty} = (CommandId)((int)json[\"{property.Name}\"]);");
121121
}
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)
138+
{
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]);");
146+
}
122147
else
123148
{
124149
properties.AppendLine($"var {property.CodeProperty} = ({type})json[\"{property.Name}\"];");
@@ -173,6 +198,11 @@ private static string GetTypeCode(CommandPropertyType type)
173198
CommandPropertyType.Float => "float",
174199
CommandPropertyType.Bool => "bool",
175200
CommandPropertyType.CommandId => "CommandId",
201+
CommandPropertyType.Vector2 => "global::UnityEngine.Vector2",
202+
CommandPropertyType.Vector3 => "global::UnityEngine.Vector3",
203+
CommandPropertyType.Vector4 => "global::UnityEngine.Vector4",
204+
CommandPropertyType.Vector2Int => "global::UnityEngine.Vector2Int",
205+
CommandPropertyType.Vector3Int => "global::UnityEngine.Vector3Int",
176206
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
177207
};
178208
}

CommandForgeGenerator/Semantic/CommandSemanticsLoader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ CommandsSemantics ParseCommandsSchema(JsonObject root)
8282
"boolean" => CommandPropertyType.Bool,
8383
"enum" => CommandPropertyType.String,
8484
"command" => CommandPropertyType.CommandId,
85+
"vector2" => CommandPropertyType.Vector2,
86+
"vector3" => CommandPropertyType.Vector3,
87+
"vector4" => CommandPropertyType.Vector4,
88+
"vector2int" => CommandPropertyType.Vector2Int,
89+
"vector3int" => CommandPropertyType.Vector3Int,
8590
_ => throw new Exception($"未知の property type \"{typeStr}\"")
8691
};
8792

CommandForgeGenerator/Semantic/CommandsSemantics.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,9 @@ public enum CommandPropertyType{
4545
Float,
4646
Bool,
4747
CommandId,
48+
Vector2,
49+
Vector3,
50+
Vector4,
51+
Vector2Int,
52+
Vector3Int,
4853
}

0 commit comments

Comments
 (0)