Skip to content

apply button #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Core/AvatarChooseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ void ShowChooseMaterialControl(IList<string> children, string child, Material[]
EditorGUILayout.BeginHorizontal();
var newValue = EditorGUILayout.ObjectField(ChooseName(j), value, typeof(Material), false) as Material;
MaterialPickerButton(child, i, ref newValue);
MaterialApplyButton(child, i, newValue);
EditorGUILayout.EndHorizontal();
if (value != newValue)
{
Expand Down Expand Up @@ -904,6 +905,7 @@ void ShowChooseBlendShapeControl(
EditorGUILayout.BeginHorizontal();
var newValue = EditorGUILayout.FloatField(ChooseName(i), value);
BlendShapeLikePickerButton(isBlendShape, child, name.Name, ref newValue);
BlendShapeLikeApplyButton(isBlendShape, child, name.Name, newValue);
EditorGUILayout.EndHorizontal();

if (value != newValue)
Expand Down Expand Up @@ -1012,6 +1014,7 @@ IEnumerable<INameAndDescription> names
EditorGUILayout.BeginHorizontal();
var newValue = EditorGUILayout.Vector4Field(ChooseName(i), value);
ShaderVectorParameterPickerButton(child, name.Name, ref newValue);
ShaderVectorParameterApplyButton(child, name.Name, newValue);
EditorGUILayout.EndHorizontal();

if (value != newValue)
Expand Down Expand Up @@ -1115,23 +1118,27 @@ IEnumerable<TypeMember> members
{
newValue = EditorGUILayout.FloatField(ChooseName(i), (float)value);
ValuePickerButton(child, member, p => newValue = p.floatValue);
ValueApplyButton(child, member, p => p.floatValue = (float)newValue);
}
else if (member.MemberType == typeof(int))
{
newValue = EditorGUILayout.IntField(ChooseName(i), (int)value);
ValuePickerButton(child, member, p => newValue = p.intValue);
ValueApplyButton(child, member, p => p.intValue = (int)newValue);
}
else if (member.MemberType == typeof(bool))
{
newValue = EditorGUILayout.Toggle(ChooseName(i), (bool)value);
ValuePickerButton(child, member, p => newValue = p.boolValue);
ValueApplyButton(child, member, p => p.boolValue = (bool)newValue);
}
else if (member.MemberType.IsSubclassOf(typeof(Enum)))
{
var enumNames = member.MemberType.GetEnumNamesCached();
var enumValues = member.MemberType.GetEnumValuesCached();
newValue = EditorGUILayout.IntPopup(ChooseName(i), (int)value, enumNames, enumValues);
ValuePickerButton(child, member, p => newValue = enumValues[p.enumValueIndex]);
ValueApplyButton(child, member, p => p.enumValueIndex = Array.IndexOf(enumValues, (int)newValue));
}
else if (member.MemberType == typeof(VRCPhysBoneBase.PermissionFilter))
{
Expand All @@ -1151,6 +1158,7 @@ IEnumerable<TypeMember> members
EditorGUIUtility.wideMode = true;
newValue = EditorGUILayout.Vector3Field(ChooseName(i), (Vector3)value);
ValuePickerButton(child, member, p => newValue = p.vector3Value);
ValueApplyButton(child, member, p => p.vector3Value = (Vector3)newValue);
EditorGUIUtility.wideMode = widemode;
}
else if (member.MemberType == typeof(Quaternion))
Expand All @@ -1159,6 +1167,7 @@ IEnumerable<TypeMember> members
EditorGUIUtility.wideMode = true;
newValue = EditorGUILayout.Vector4Field(ChooseName(i), ((Quaternion)value).ToVector4()).ToQuaternion();
ValuePickerButton(child, member, p => newValue = p.quaternionValue);
ValueApplyButton(child, member, p => p.quaternionValue = (Quaternion)newValue);
EditorGUIUtility.wideMode = widemode;
}
else if (member.MemberType == typeof(Color))
Expand All @@ -1167,6 +1176,7 @@ IEnumerable<TypeMember> members
EditorGUIUtility.wideMode = true;
newValue = EditorGUILayout.ColorField(ChooseName(i), (Color)value);
ValuePickerButton(child, member, p => newValue = p.colorValue);
ValueApplyButton(child, member, p => p.colorValue = (Color)newValue);
EditorGUIUtility.wideMode = widemode;
}
EditorGUILayout.EndHorizontal();
Expand Down Expand Up @@ -1263,6 +1273,7 @@ void ShowTransformComponentControl(IList<string> children, string child, ChooseV
EditorGUILayout.BeginHorizontal();
var newValue = EditorGUILayout.Vector3Field(ChooseName(i), value);
TransformPickerButton(child, title, ref newValue);
TransformApplyButton(child, title, newValue);
EditorGUILayout.EndHorizontal();

if (value != newValue)
Expand Down Expand Up @@ -1384,6 +1395,15 @@ protected override Material[] GetMaterialSlots(string child)
if (slots == null) slots = ChooseMaterials.MaterialSlots(child);
return slots;
}

protected override void SetMaterialSlot(string child, int index, Material mat)
{
var go = GetGameObject(child);
if (go != null)
{
go.SetMaterialSlot(index, mat);
}
}
#endif
}
}
87 changes: 87 additions & 0 deletions Core/AvatarMenuBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,8 @@ protected Texture2D TextureField(Rect rect, Texture2D texture2D)

// for MaterialPickerButton
protected virtual Material[] GetMaterialSlots(string child) { throw new NotImplementedException(); }
// for MaterualApplyButton
protected virtual void SetMaterialSlot(string child, int index, Material mat) { throw new NotImplementedException(); }

protected bool PickerButton()
{
Expand Down Expand Up @@ -651,6 +653,91 @@ protected void ValuePickerButton(string child, TypeMember member, Action<Seriali
setValue(new SerializedObject(go.GetComponent(member.Type)).FindProperty(member.AnimationMemberName));
}

protected bool ApplyButton()
{
return GUILayout.Button(EditorGUIUtility.IconContent("PlayButton"), GUILayout.Width(20), GUILayout.Height(18));
}

protected void MaterialApplyButton(string child, int index, Material value)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
SetMaterialSlot(child, index, value);
}

protected void BlendShapeLikeApplyButton(bool isBlendShape, string child, string name, float value)
{
if (isBlendShape)
{
BlendShapeApplyButton(child, name, value);
}
else
{
ShaderParameterApplyButton(child, name, value);
}
}

void BlendShapeApplyButton(string child, string name, float value)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
var mesh = go.GetComponent<SkinnedMeshRenderer>();
Undo.RecordObject(mesh, "AvatarMenuCreator Apply");
mesh.SetBlendShapeWeight(mesh.sharedMesh.GetBlendShapeIndex(name), value);
}

void ShaderParameterApplyButton(string child, string name, float value)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
var mesh = go.GetComponent<Renderer>();
foreach (var mat in mesh.sharedMaterials)
{
if (mat.shader.FindPropertyIndex(name) != -1)
{
Undo.RecordObject(mat, "AvatarMenuCreator Apply");
mat.SetFloat(name, value);
return;
}
}
}

protected void ShaderVectorParameterApplyButton(string child, string name, Vector4 value)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
var mesh = go.GetComponent<Renderer>();
foreach (var mat in mesh.sharedMaterials)
{
if (mat.shader.FindPropertyIndex(name) != -1)
{
Undo.RecordObject(mat, "AvatarMenuCreator Apply");
mat.SetColor(name, value);
return;
}
}
}

protected void TransformApplyButton(string child, string transformComponentName, Vector3 value)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
var component = go.GetComponent<Transform>();
var memberInfo = typeof(Transform).GetProperty(TransformPropertyName(transformComponentName), System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
if (memberInfo is System.Reflection.PropertyInfo propertyInfo)
{
Undo.RecordObject(component, "AvatarMenuCreator Apply");
propertyInfo.SetValue(component, value);
}
}

protected void ValueApplyButton(string child, TypeMember member, Action<SerializedProperty> setProperty)
{
var go = GetGameObject(child);
if (go == null || !ApplyButton()) return;
setProperty(new SerializedObject(go.GetComponent(member.Type)).FindProperty(member.AnimationMemberName));
}

protected Rect HorizontalLine()
{
var c = GUI.color;
Expand Down
Loading
Loading