static object DrawArrayFields <T>(PropertyInfoDataWrapper prop, Func <string, T[], object> draw2Dimensional, Func <string, T[], object> draw3Dimensional, Func <string, T[], object> draw4Dimensional, Func <string, T, T> fieldDrawMethodOther) { object newValue = null; var a = prop.GetValue <T[]>(); switch (a.Length) { case 2: { newValue = draw2Dimensional(prop.name, a); break; } case 3: { newValue = draw3Dimensional(prop.name, a); break; } case 4: { newValue = draw4Dimensional(prop.name, a); break; } default: { EditorGUILayout.BeginVertical(); for (int i = 0; i < prop.arrayLength; i++) { EditorGUI.BeginChangeCheck(); T newValueInArray = fieldDrawMethodOther($"{prop.name}[{i}]", a[i]); if (EditorGUI.EndChangeCheck()) { var newValueAsArray = new T[prop.arrayLength]; for (int j = 0; j < prop.arrayLength; j++) { if (j == i) { newValueAsArray[j] = newValueInArray; } else { newValueAsArray[j] = a[j]; } } newValue = newValueAsArray; } } EditorGUILayout.EndVertical(); break; } } return(newValue); }
private static object DrawArrayFieldsInt(PropertyInfoDataWrapper prop) { return(DrawArrayFields(prop, (name, val) => EditorGUILayout.Vector2IntField(name, new Vector2Int(val[0], val[1])), (name, val) => EditorGUILayout.Vector3IntField(name, new Vector3Int(val[0], val[1], val[2])), (name, val) => EditorGUILayout.Vector4Field(name, new Vector4(val[0], val[1], val[2], val[3])), (string name, int val) => EditorGUILayout.IntField(name, val))); }
private static object DrawArrayFieldsFloat(PropertyInfoDataWrapper prop) { return(DrawArrayFields(prop, (string name, float[] val) => EditorGUILayout.Vector2Field(name, new Vector2(val[0], val[1])), (name, val) => EditorGUILayout.Vector3Field(name, new Vector3(val[0], val[1], val[2])), (name, val) => EditorGUILayout.Vector4Field(name, new Vector4(val[0], val[1], val[2], val[3])), (name, val) => EditorGUILayout.FloatField(name, val))); }