Skip to content

Commit 11ef080

Browse files
committed
Bugfixed duplicate entry in dictionary error. Now can manually select canvas to spawn slider.
1 parent b962acf commit 11ef080

2 files changed

Lines changed: 33 additions & 5 deletions

File tree

Assets/Scripts/CharacterCustomization.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,13 @@ private SkinnedMeshRenderer GetSkinnedMeshRenderer()
7676

7777
private void ParseBlendShapesToDictionary()
7878
{
79+
//Get all blendshape names
7980
List<string> blendshapeNames = Enumerable.Range(0, mesh.blendShapeCount).Select(x => mesh.GetBlendShapeName(x)).ToList();
8081

8182
for (int i = 0; blendshapeNames.Count > 0;)
8283
{
8384
string altSuffix, noSuffix;
85+
//Removes the max and min suffixes
8486
noSuffix = blendshapeNames[i].TrimEnd(suffixMax.ToCharArray()).TrimEnd(suffixMin.ToCharArray()).Trim();
8587

8688
string positiveName = string.Empty, negativeName = string.Empty;
@@ -119,11 +121,22 @@ private void ParseBlendShapesToDictionary()
119121
if (exists)
120122
postiveIndex = mesh.GetBlendShapeIndex(altSuffix);
121123
}
124+
125+
//Doesn't have a suffix
122126
else
127+
{
123128
postiveIndex = mesh.GetBlendShapeIndex(blendshapeNames[i]);
129+
positiveName = noSuffix; //This is here so it will remove it (for condition) so its not infinite loop
130+
//print(postiveIndex + " of " + noSuffix);
131+
}
132+
133+
134+
if (blendShapeDatabase.ContainsKey(noSuffix))
135+
Debug.LogError(noSuffix + " already exists within the Database!");
124136

125137
blendShapeDatabase.Add(noSuffix, new Blendshape(postiveIndex, negativeIndex));
126138

139+
127140
//Remove Selected Indexes From the List
128141
if (positiveName != string.Empty) blendshapeNames.Remove(positiveName);
129142
if (negativeName != string.Empty) blendshapeNames.Remove(negativeName);

Assets/Scripts/Editor/CharacterCustomizationEditor.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class CharacterCustomizationEditor : Editor
1313
private int shapeBlendSelectedIndex = 0;
1414
private bool runOnce;
1515

16+
public Canvas canvas;
17+
1618
public override void OnInspectorGUI()
1719
{
1820

@@ -64,10 +66,14 @@ public override void OnInspectorGUI()
6466

6567
shapeBlendSelectedIndex = EditorGUILayout.Popup("BlendShapeName", shapeBlendSelectedIndex, blendShapeNames);
6668

69+
//Canvas selector
70+
canvas = EditorGUILayout.ObjectField("Manual Cavas Selection:", canvas, typeof(Canvas), true) as Canvas;
6771

6872
if (GUILayout.Button("Create Slider"))
6973
{
70-
var canvas = GameObject.FindObjectOfType<Canvas>();
74+
//Auto Find one if canvas is null
75+
if (canvas == null)
76+
canvas = GameObject.FindObjectOfType<Canvas>();
7177

7278
//If canvas doesn't exist, then make one
7379
if (canvas == null)
@@ -96,12 +102,21 @@ public override void OnInspectorGUI()
96102
//Slider Component Properties
97103
var slider = BShapeSlider.GetComponent<Slider>();
98104

99-
Debug.Log(blendShape.negativeIndex);
105+
//Debug.Log(blendShape.negativeIndex);
100106

101-
if (blendShape.negativeIndex == -1)
102-
{
107+
if (blendShape.negativeIndex == -1)
103108
slider.minValue = 0f;
104-
}
109+
110+
111+
else if (blendShape.positiveIndex == -1)
112+
slider.maxValue = 0f;
113+
114+
else
115+
Debug.Log("Both Values for Blendshape are -1!?");
116+
117+
slider.value = 0f;
118+
119+
105120

106121
Debug.Log("Slider \"" + BShapeSlider.blendShapeName + "\" Created!");
107122
}

0 commit comments

Comments
 (0)