Skip to content

Commit 464b19c

Browse files
committed
picker buttons
1 parent f37e570 commit 464b19c

File tree

4 files changed

+121
-14
lines changed

4 files changed

+121
-14
lines changed

Core/AvatarChooseMenu.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ protected override void OnMainGUI(IList<string> children)
309309
))
310310
{
311311
EditorGUI.indentLevel++;
312-
ShowChooseBlendShapeControl(children, child, ChooseBlendShapes, names.ToNames());
312+
ShowChooseBlendShapeControl(true, children, child, ChooseBlendShapes, names.ToNames());
313313
EditorGUI.indentLevel--;
314314
}
315315
if (parameters.Count > 0 &&
@@ -324,7 +324,7 @@ protected override void OnMainGUI(IList<string> children)
324324
))
325325
{
326326
EditorGUI.indentLevel++;
327-
ShowChooseBlendShapeControl(children, child, ChooseShaderParameters, parameters, minValue: null, maxValue: null);
327+
ShowChooseBlendShapeControl(false, children, child, ChooseShaderParameters, parameters, minValue: null, maxValue: null);
328328
EditorGUI.indentLevel--;
329329
}
330330
if (FoldoutHeaderWithAddItemButton(
@@ -432,7 +432,10 @@ void ShowChooseMaterialControl(IList<string> children, string child, Material[]
432432
for (var j = 0; j < ChooseCount; ++j)
433433
{
434434
var value = values.ContainsKey(j) ? values[j] : null;
435+
EditorGUILayout.BeginHorizontal();
435436
var newValue = EditorGUILayout.ObjectField(ChooseName(j), value, typeof(Material), false) as Material;
437+
MaterialPickerButton(child, i, ref newValue);
438+
EditorGUILayout.EndHorizontal();
436439
if (value != newValue)
437440
{
438441
WillChange();
@@ -576,6 +579,7 @@ void ShowChooseBulkMaterialControl(Dictionary<string, Material[]> allMaterials)
576579
}
577580

578581
void ShowChooseBlendShapeControl(
582+
bool isBlendShape,
579583
IList<string> children,
580584
string child,
581585
ChooseBlendShapeDictionary choices,
@@ -596,7 +600,10 @@ void ShowChooseBlendShapeControl(
596600
for (var i = 0; i < ChooseCount; ++i)
597601
{
598602
var value = values.ContainsKey(i) ? values[i] : 0;
603+
EditorGUILayout.BeginHorizontal();
599604
var newValue = EditorGUILayout.FloatField(ChooseName(i), value);
605+
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue);
606+
EditorGUILayout.EndHorizontal();
600607

601608
if (value != newValue)
602609
{
@@ -695,7 +702,10 @@ void ShowTransformComponentControl(IList<string> children, string child, ChooseV
695702
for (var i = 0; i < ChooseCount; ++i)
696703
{
697704
var value = values.ContainsKey(i) ? values[i] : Vector3.zero;
705+
EditorGUILayout.BeginHorizontal();
698706
var newValue = EditorGUILayout.Vector3Field(ChooseName(i), value);
707+
TransformPickerButton(child, title, ref newValue);
708+
EditorGUILayout.EndHorizontal();
699709

700710
if (value != newValue)
701711
{
@@ -770,7 +780,7 @@ void RemoveTransformComponentSingle(ChooseVector3Dictionary values, string child
770780
}
771781

772782
// with prefab shim
773-
Material[] GetMaterialSlots(string child) => GetGameObject(child)?.GetMaterialSlots() ?? ChooseMaterials.MaterialSlots(child);
783+
protected override Material[] GetMaterialSlots(string child) => GetGameObject(child)?.GetMaterialSlots() ?? ChooseMaterials.MaterialSlots(child);
774784
#endif
775785
}
776786
}

Core/AvatarMenuBase.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,79 @@ protected Texture2D TextureField(Texture2D texture2D)
364364
}
365365
}
366366

367+
// for MaterialPickerButton
368+
protected virtual Material[] GetMaterialSlots(string child) { throw new NotImplementedException(); }
369+
370+
protected bool PickerButton()
371+
{
372+
return GUILayout.Button(EditorGUIUtility.IconContent("Grid.PickingTool"), GUILayout.Width(20));
373+
}
374+
375+
protected void MaterialPickerButton(string child, int index, ref Material value)
376+
{
377+
var go = GetGameObject(child);
378+
if (go == null || !PickerButton()) return;
379+
value = GetMaterialSlots(child)[index];
380+
}
381+
382+
protected void BlendShapeLikePickerButton(bool isBlendShape, string child, string name, ref float value)
383+
{
384+
if (isBlendShape)
385+
{
386+
BlendShapePickerButton(child, name, ref value);
387+
}
388+
else
389+
{
390+
ShaderParameterPickerButton(child, name, ref value);
391+
}
392+
}
393+
394+
void BlendShapePickerButton(string child, string name, ref float value)
395+
{
396+
var go = GetGameObject(child);
397+
if (go == null || !PickerButton()) return;
398+
var mesh = go.GetComponent<SkinnedMeshRenderer>();
399+
value = mesh.GetBlendShapeWeight(mesh.sharedMesh.GetBlendShapeIndex(name));
400+
}
401+
402+
void ShaderParameterPickerButton(string child, string name, ref float value)
403+
{
404+
var go = GetGameObject(child);
405+
if (go == null || !PickerButton()) return;
406+
var mesh = go.GetComponent<Renderer>();
407+
foreach (var mat in mesh.sharedMaterials)
408+
{
409+
if (mat.shader.FindPropertyIndex(name) != -1)
410+
{
411+
value = mat.GetFloat(name);
412+
return;
413+
}
414+
}
415+
}
416+
417+
protected void TransformPickerButton(string child, string transformComponentName, ref Vector3 value)
418+
{
419+
var go = GetGameObject(child);
420+
if (go == null || !PickerButton()) return;
421+
var component = go.GetComponent<Transform>();
422+
var memberInfo = TypeMemberUtil.GetMember(typeof(Transform), TransformPropertyName(transformComponentName));
423+
if (memberInfo is System.Reflection.PropertyInfo propertyInfo)
424+
{
425+
value = (Vector3)propertyInfo.GetValue(component);
426+
}
427+
}
428+
429+
string TransformPropertyName(string transformComponentName)
430+
{
431+
switch (transformComponentName)
432+
{
433+
case "Position": return "localPosition";
434+
case "Rotation": return "localEulerAngles";
435+
case "Scale": return "localScale";
436+
default: throw new ArgumentException();
437+
}
438+
}
439+
367440
protected void HorizontalLine()
368441
{
369442
var c = GUI.color;

Core/AvatarRadialMenu.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ protected override void OnMainGUI(IList<string> children)
228228
))
229229
{
230230
EditorGUI.indentLevel++;
231-
ShowRadialBlendShapeControl(children, child, RadialBlendShapes, names.ToNames());
231+
ShowRadialBlendShapeControl(true, children, child, RadialBlendShapes, names.ToNames());
232232
EditorGUI.indentLevel--;
233233
}
234234
if (parameters.Count > 0 &&
@@ -243,7 +243,7 @@ protected override void OnMainGUI(IList<string> children)
243243
))
244244
{
245245
EditorGUI.indentLevel++;
246-
ShowRadialBlendShapeControl(children, child, RadialShaderParameters, parameters, minValue: null, maxValue: null);
246+
ShowRadialBlendShapeControl(false, children, child, RadialShaderParameters, parameters, minValue: null, maxValue: null);
247247
EditorGUI.indentLevel--;
248248
}
249249
if (FoldoutHeaderWithAddItemButton(
@@ -267,6 +267,7 @@ protected override void OnMainGUI(IList<string> children)
267267
}
268268

269269
void ShowRadialBlendShapeControl(
270+
bool isBlendShape,
270271
IList<string> children,
271272
string child,
272273
RadialBlendShapeDictionary radials,
@@ -289,7 +290,9 @@ void ShowRadialBlendShapeControl(
289290
EditorGUI.indentLevel++;
290291
EditorGUIUtility.labelWidth = 75;
291292
newValue.Start = EditorGUILayout.FloatField(T., value.Start, GUILayout.Width(105));
293+
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue.Start);
292294
newValue.End = EditorGUILayout.FloatField(T., value.End, GUILayout.Width(105));
295+
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue.End);
293296
EditorGUIUtility.labelWidth = 70;
294297
using (new EditorGUI.DisabledGroupScope(true))
295298
{
@@ -420,8 +423,16 @@ void ShowTransformComponentControl(IList<string> children, string child, RadialV
420423
var widemode = EditorGUIUtility.wideMode;
421424
EditorGUIUtility.wideMode = true;
422425
EditorGUIUtility.labelWidth = 75;
423-
newValue.Start = EditorGUILayout.Vector3Field(T., value.Start);
424-
newValue.End = EditorGUILayout.Vector3Field(T., value.End);
426+
using (new EditorGUILayout.HorizontalScope())
427+
{
428+
newValue.Start = EditorGUILayout.Vector3Field(T., value.Start);
429+
TransformPickerButton(child, title, ref newValue.Start);
430+
}
431+
using (new EditorGUILayout.HorizontalScope())
432+
{
433+
newValue.End = EditorGUILayout.Vector3Field(T., value.End);
434+
TransformPickerButton(child, title, ref newValue.End);
435+
}
425436
EditorGUIUtility.labelWidth = 70;
426437
using (new EditorGUI.DisabledGroupScope(true))
427438
{

Core/AvatarToggleMenu.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected override void OnMainGUI(IList<string> children)
290290
))
291291
{
292292
EditorGUI.indentLevel++;
293-
ShowToggleBlendShapeControl(children, child, ToggleBlendShapes, names.ToNames());
293+
ShowToggleBlendShapeControl(true, children, child, ToggleBlendShapes, names.ToNames());
294294
EditorGUI.indentLevel--;
295295
}
296296
if (parameters.Count > 0 &&
@@ -305,7 +305,7 @@ protected override void OnMainGUI(IList<string> children)
305305
))
306306
{
307307
EditorGUI.indentLevel++;
308-
ShowToggleBlendShapeControl(children, child, ToggleShaderParameters, parameters, minValue: null, maxValue: null);
308+
ShowToggleBlendShapeControl(false, children, child, ToggleShaderParameters, parameters, minValue: null, maxValue: null);
309309
EditorGUI.indentLevel--;
310310
}
311311
if (properties.Count > 0 && FoldoutHeaderWithAddItemButton(
@@ -447,7 +447,9 @@ void ShowToggleMaterialControl(IList<string> children, string child, Material[]
447447
{
448448
EditorGUIUtility.labelWidth = 70;
449449
newValue.Inactive = EditorGUILayout.ObjectField("OFF", value.Inactive, typeof(Material), false) as Material;
450+
MaterialPickerButton(child, i, ref newValue.Inactive);
450451
newValue.Active = EditorGUILayout.ObjectField("ON", value.Active, typeof(Material), false) as Material;
452+
MaterialPickerButton(child, i, ref newValue.Active);
451453
EditorGUIUtility.labelWidth = 0;
452454
}
453455
if (TransitionSeconds > 0)
@@ -655,6 +657,7 @@ void ShowToggleBulkMaterialControl(Dictionary<string, Material[]> allMaterials)
655657
}
656658

657659
void ShowToggleBlendShapeControl(
660+
bool isBlendShape,
658661
IList<string> children,
659662
string child,
660663
ToggleBlendShapeDictionary toggles,
@@ -676,8 +679,10 @@ void ShowToggleBlendShapeControl(
676679
{
677680
EditorGUI.indentLevel++;
678681
EditorGUIUtility.labelWidth = 70;
679-
newValue.Inactive = EditorGUILayout.FloatField("OFF", value.Inactive, GUILayout.Width(100));
680-
newValue.Active = EditorGUILayout.FloatField("ON", value.Active, GUILayout.Width(100));
682+
newValue.Inactive = EditorGUILayout.FloatField("OFF", value.Inactive, GUILayout.Width(110));
683+
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue.Inactive);
684+
newValue.Active = EditorGUILayout.FloatField("ON", value.Active, GUILayout.Width(110));
685+
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue.Active);
681686
EditorGUIUtility.labelWidth = 0;
682687
EditorGUI.indentLevel--;
683688
}
@@ -1038,8 +1043,16 @@ void ShowTransformComponentControl(IList<string> children, string child, ToggleV
10381043
var widemode = EditorGUIUtility.wideMode;
10391044
EditorGUIUtility.wideMode = true;
10401045
EditorGUIUtility.labelWidth = 70;
1041-
newValue.Inactive = EditorGUILayout.Vector3Field("OFF", value.Inactive);
1042-
newValue.Active = EditorGUILayout.Vector3Field("ON", value.Active);
1046+
using (new EditorGUILayout.HorizontalScope())
1047+
{
1048+
newValue.Inactive = EditorGUILayout.Vector3Field("OFF", value.Inactive);
1049+
TransformPickerButton(child, title, ref newValue.Inactive);
1050+
}
1051+
using (new EditorGUILayout.HorizontalScope())
1052+
{
1053+
newValue.Active = EditorGUILayout.Vector3Field("ON", value.Active);
1054+
TransformPickerButton(child, title, ref newValue.Active);
1055+
}
10431056
EditorGUIUtility.labelWidth = 0;
10441057
EditorGUIUtility.wideMode = widemode;
10451058
EditorGUI.indentLevel--;
@@ -1144,7 +1157,7 @@ void RemoveTransformComponentSingle(ToggleVector3Dictionary values, string child
11441157
}
11451158

11461159
// with prefab shim
1147-
Material[] GetMaterialSlots(string child) => GetGameObject(child)?.GetMaterialSlots() ?? ToggleMaterials.MaterialSlots(child);
1160+
protected override Material[] GetMaterialSlots(string child) => GetGameObject(child)?.GetMaterialSlots() ?? ToggleMaterials.MaterialSlots(child);
11481161
#endif
11491162
}
11501163
}

0 commit comments

Comments
 (0)