internal static void CreateCustomVectorField(Rect position, SerializedProperty property, GUIContent label, PropertyAttribute attribute) { CustomVector4StackedAttribute customVector = (CustomVector4StackedAttribute)attribute; label = CustomVectorUtils.GetLabel(label, customVector.label); if (property.propertyType == SerializedPropertyType.Vector4) { property.vector4Value = EditorGUI.Vector4Field(position, label, property.vector4Value, customVector.xLabel, customVector.yLabel, customVector.zLabel, customVector.wLabel, customVector.expandWidth, true); } else { CustomVectorUtils.ErrorMessage(position, label, customVector, "Vector4"); } }
public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.LabelField("Vector2 Examples", EditorStyles.boldLabel); // Create a Custom Vector2 or Vector2Int field. float v2Height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector2, new GUIContent()); if (!EditorGUIUtility.wideMode) { v2Height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } Rect v2Rect = EditorGUILayout.GetControlRect(true, v2Height, EditorStyles.numberField); customV2.vector2Value = EditorGUICV.Vector2Field(v2Rect, "CustomV2", customV2.vector2Value, "xLabel", "yLabel"); customV2Layout.vector2Value = EditorGUILayoutCV.Vector2Field("CustomV2Layout", customV2Layout.vector2Value, xLabel: "xLabel"); customVector2Expanded.vector2Value = EditorGUILayoutCV.Vector2Field("CustomV2Layout Expanded", customVector2Expanded.vector2Value, xLabel: "xLabel", expandWidth: true); // Can also be used with Vector2Int. //customV2.vector2IntValue = EditorGUICV.Vector2IntField(v2Rect, "CustomV2", customV2.vector2IntValue, "xLabel", "yLabel"); //customV2Layout.vector2IntValue = EditorGUILayoutCV.Vector2IntField("CustomV2Layout", customV2Layout.vector2IntValue, xLabel: "xLabel"); //customVector2Expanded.vector2IntValue = EditorGUILayoutCV.Vector2IntField("CustomV2Layout Expanded", customVector2Expanded.vector2IntValue, xLabel: "xLabel", expandWidth: true); EditorGUILayout.Space(); EditorGUILayout.LabelField("Vector3 Examples", EditorStyles.boldLabel); // Create a Custom Vector3 or Vector3Int field. float v3Height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector3, new GUIContent()); if (!EditorGUIUtility.wideMode) { v3Height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } Rect v3Rect = EditorGUILayout.GetControlRect(true, v3Height, EditorStyles.numberField); customV3.vector3Value = EditorGUICV.Vector3Field(v3Rect, "CustomV3", customV3.vector3Value, "xLabel", "yLabel", "zLabel"); customV3Layout.vector3Value = EditorGUILayoutCV.Vector3Field("CustomV3Layout", customV3Layout.vector3Value, xLabel: "xLabel", zLabel: "zLabel"); // Can also be used with Vector3Int. //customV3.vector3IntValue = EditorGUICV.Vector3IntField(v3Rect, "CustomV3", customV3.vector3IntValue, "xLabel", "yLabel", "zLabel"); //customV3Layout.vector3IntValue = EditorGUILayoutCV.Vector3IntField("CustomV3Layout", customV3Layout.vector3IntValue, xLabel: "xLabel", zLabel: "zLabel"); EditorGUILayout.Space(); EditorGUILayout.LabelField("Vector4 Examples", EditorStyles.boldLabel); // Create a Custom Vector4 field. float v4Height = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector4, new GUIContent()); if (!EditorGUIUtility.wideMode) { v4Height += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; } Rect v4Rect = EditorGUILayout.GetControlRect(true, v4Height, EditorStyles.numberField); customV4.vector4Value = EditorGUICV.Vector4Field(v4Rect, "CustomV4", customV4.vector4Value, "xLabel", "yLabel", "zLabel", "wLabel", false); customV4Layout.vector4Value = EditorGUILayoutCV.Vector4Field("CustomV4Layout", customV4Layout.vector4Value, xLabel: "xLabel", zLabel: "zLabel", expandWidth: false); customVector4Expanded.vector4Value = EditorGUILayoutCV.Vector4Field("CustomV4Layout Expanded", customVector4Expanded.vector4Value, xLabel: "xLabel", zLabel: "zLabel"); EditorGUILayout.Space(); EditorGUILayout.LabelField("Vector4Stacked Examples", EditorStyles.boldLabel); // Create a Custom Vector4 field that displays as stacked fields. float v4StackedHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector4, new GUIContent()) * 2; v4StackedHeight = EditorGUIUtility.wideMode ? v4StackedHeight + EditorGUIUtility.standardVerticalSpacing : v4StackedHeight + EditorGUIUtility.singleLineHeight + (EditorGUIUtility.standardVerticalSpacing * 2); Rect v4StackedRect = EditorGUILayout.GetControlRect(true, v4StackedHeight, EditorStyles.numberField); customV4Stacked.vector4Value = EditorGUICV.Vector4Field(v4StackedRect, "CustomV4Stacked", customV4Stacked.vector4Value, "xLabel", "yLabel", "zLabel", "wLabel", false, true); customV4StackedLayout.vector4Value = EditorGUILayoutCV.Vector4Field("CustomV4StackedLayout", customV4StackedLayout.vector4Value, xLabel: "xLabel", zLabel: "zLabel", expandWidth: false, stackFields: true); customVector4StackedExpanded.vector4Value = EditorGUILayoutCV.Vector4Field("CustomV4StackedLayout Expanded", customVector4StackedExpanded.vector4Value, xLabel: "xLabel", zLabel: "zLabel", stackFields: true); EditorGUILayout.Space(); EditorGUILayout.LabelField("Multi Examples", EditorStyles.boldLabel); // Create a Custom MultiFloat or MultiInt field. var subLabels = new string[] { "label1", "label2", "label3", "label4", "label5", "label6", "label7" }; var subLabelsLayout = new string[] { "label1", "label2", "label3", "label4", "label5", "label6", "label7" }; int columns = 5; int rows = 2; float mfHeight = EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector3, new GUIContent()) * rows; mfHeight = EditorGUIUtility.wideMode ? mfHeight + (EditorGUIUtility.standardVerticalSpacing * (rows - 1)) : mfHeight + EditorGUIUtility.singleLineHeight + (EditorGUIUtility.standardVerticalSpacing * rows); Rect mfRect = EditorGUILayout.GetControlRect(true, mfHeight, EditorStyles.numberField); var multiValues = new float[customMulti.arraySize]; for (int i = 0; i < customMulti.arraySize; i++) { multiValues[i] = customMulti.GetArrayElementAtIndex(i).floatValue; } EditorGUICV.MultiFloatField(mfRect, "CustomMultiFloat", subLabels, multiValues, columns); for (int i = 0; i < multiValues.Length; i++) { customMulti.GetArrayElementAtIndex(i).floatValue = multiValues[i]; } var multiLayoutValues = new float[customMultiLayout.arraySize]; for (int i = 0; i < customMultiLayout.arraySize; i++) { multiLayoutValues[i] = customMultiLayout.GetArrayElementAtIndex(i).floatValue; } EditorGUILayoutCV.MultiFloatField("CustomMultiFloatLayout", subLabelsLayout, multiLayoutValues, columns); for (int i = 0; i < multiLayoutValues.Length; i++) { customMultiLayout.GetArrayElementAtIndex(i).floatValue = multiLayoutValues[i]; } var multiExpandedValues = new float[customMultiExpanded.arraySize]; for (int i = 0; i < customMultiExpanded.arraySize; i++) { multiExpandedValues[i] = customMultiExpanded.GetArrayElementAtIndex(i).floatValue; } EditorGUILayoutCV.MultiFloatField("CustomMultiFloatLayout Expanded", subLabelsLayout, multiExpandedValues, columns, true); for (int i = 0; i < multiExpandedValues.Length; i++) { customMultiExpanded.GetArrayElementAtIndex(i).floatValue = multiExpandedValues[i]; } // Can also be used with ints. /*var multiValues = new int[customMulti.arraySize]; * * for (int i = 0; i < customMulti.arraySize; i++) * { * multiValues[i] = customMulti.GetArrayElementAtIndex(i).intValue; * } * * EditorGUICV.MultiIntField(mfRect, "CustomVectors MultiInt", subLabels, multiValues, columns); * * for (int i = 0; i < multiValues.Length; i++) * { * customMulti.GetArrayElementAtIndex(i).intValue = multiValues[i]; * } * * var multiLayoutValues = new int[customMultiLayout.arraySize]; * * for (int i = 0; i < customMultiLayout.arraySize; i++) * { * multiLayoutValues[i] = customMultiLayout.GetArrayElementAtIndex(i).intValue; * } * * EditorGUILayoutCV.MultiIntField("CustomVectors MultiIntLayout", subLabelsLayout, multiLayoutValues, columns); * * for (int i = 0; i < multiLayoutValues.Length; i++) * { * customMultiLayout.GetArrayElementAtIndex(i).intValue = multiLayoutValues[i]; * } * * var multiExpandedValues = new int[customMultiExpanded.arraySize]; * * for (int i = 0; i < customMultiExpanded.arraySize; i++) * { * multiExpandedValues[i] = customMultiExpanded.GetArrayElementAtIndex(i).intValue; * } * * EditorGUILayoutCV.MultiIntField("CustomVectors MultiIntLayout Expanded", subLabelsLayout, multiExpandedValues, columns, true); * * for (int i = 0; i < multiExpandedValues.Length; i++) * { * customMultiExpanded.GetArrayElementAtIndex(i).intValue = multiExpandedValues[i]; * }*/ serializedObject.ApplyModifiedProperties(); }