Skip to content

Commit 56abe27

Browse files
added error helpbox if viz type is unset.
fixed spacing and hardened string extension proper case method.
1 parent 25e26e7 commit 56abe27

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Assets/MixedRealityToolkit/_Core/Extensions/StringExtensions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public static string ToProperCase(this string value)
4343
// If there are 0 or 1 characters, just return the string.
4444
if (value == null) { return value; }
4545
if (value.Length < 2) { return value.ToUpper(); }
46+
// If there's already spaces in the string, return.
47+
if (value.Contains(" ")) { return value; }
4648

4749
// Start with the first character.
4850
string result = value.Substring(0, 1).ToUpper();
@@ -52,12 +54,14 @@ public static string ToProperCase(this string value)
5254
{
5355
var wasLastCharacterUpper = false;
5456

55-
if (i < value.Length)
57+
if (i < value.Length && i != 0)
5658
{
57-
wasLastCharacterUpper = char.IsUpper(value[i - 1]);
59+
wasLastCharacterUpper = char.IsLetter(result[i - 1]) && char.IsUpper(result[i - 1]);
5860
}
5961

60-
if (char.IsUpper(value[i]) && !wasLastCharacterUpper)
62+
if (char.IsLetter(value[i]) &&
63+
char.IsUpper(value[i]) &&
64+
!wasLastCharacterUpper)
6165
{
6266
result += " ";
6367
}

Assets/MixedRealityToolkit/_Core/Inspectors/Profiles/MixedRealityControllerVisualizationProfileInspector.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,13 @@ public override void OnInspectorGUI()
102102
var rightHandModelPrefab = globalRightHandModel.objectReferenceValue as GameObject;
103103

104104
EditorGUILayout.PropertyField(controllerVisualizationType);
105+
106+
if (thisProfile.ControllerVisualizationType == null ||
107+
thisProfile.ControllerVisualizationType.Type == null)
108+
{
109+
EditorGUILayout.HelpBox("A controller visualization type must be defined!", MessageType.Error);
110+
}
111+
105112
EditorGUILayout.PropertyField(useDefaultModels);
106113

107114
if (useDefaultModels.boolValue && (leftHandModelPrefab != null || rightHandModelPrefab != null))
@@ -164,14 +171,14 @@ private void RenderControllerList(SerializedProperty controllerList)
164171
var mixedRealityControllerMappingDescription = controllerSetting.FindPropertyRelative("description");
165172
bool hasValidType = thisProfile.ControllerVisualizationSettings[i].ControllerType != null &&
166173
thisProfile.ControllerVisualizationSettings[i].ControllerType.Type != null;
167-
if (hasValidType)
168-
{
169-
mixedRealityControllerMappingDescription.stringValue = thisProfile.ControllerVisualizationSettings[i].ControllerType.Type.Name.ToProperCase();
170-
}
174+
175+
mixedRealityControllerMappingDescription.stringValue = hasValidType
176+
? thisProfile.ControllerVisualizationSettings[i].ControllerType.Type.Name.ToProperCase()
177+
: "Undefined Controller";
171178

172179
serializedObject.ApplyModifiedProperties();
173180
var mixedRealityControllerHandedness = controllerSetting.FindPropertyRelative("handedness");
174-
EditorGUILayout.LabelField($"{mixedRealityControllerMappingDescription.stringValue.ToProperCase()} {((Handedness)mixedRealityControllerHandedness.intValue).ToString().ToProperCase()} Hand");
181+
EditorGUILayout.LabelField($"{mixedRealityControllerMappingDescription.stringValue} {((Handedness)mixedRealityControllerHandedness.intValue).ToString().ToProperCase()} Hand");
175182

176183
EditorGUIUtility.fieldWidth = defaultFieldWidth;
177184
EditorGUIUtility.labelWidth = defaultLabelWidth;

0 commit comments

Comments
 (0)