Skip to content

Commit

Permalink
installParent
Browse files Browse the repository at this point in the history
  • Loading branch information
Narazaka committed Feb 20, 2024
1 parent 57e49c4 commit 8af6802
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
27 changes: 17 additions & 10 deletions Editor/AvatarParametersPresetPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ string ParameterName(AvatarParametersSaverPresetGroup presets, GameObject go)

void StoreAssets(AvatarParametersSaverPresetGroup presets, GameObject go, string parameterName, AnimatorController animator)
{
var parentMenu = go.GetOrAddComponent<ModularAvatarMenuItem>();
parentMenu.Control = new VRCExpressionsMenu.Control
{
name = go.name,
type = VRCExpressionsMenu.Control.ControlType.SubMenu,
icon = presets.icon,
};
parentMenu.MenuSource = SubmenuSource.Children;
var mergeAnimator = go.GetOrAddComponent<ModularAvatarMergeAnimator>();
mergeAnimator.animator = animator;
mergeAnimator.matchAvatarWriteDefaults = true;
Expand Down Expand Up @@ -99,9 +91,24 @@ void StoreAssets(AvatarParametersSaverPresetGroup presets, GameObject go, string
{
Object.DestroyImmediate(redirect);
}
if (redirectCount == presets.presets.Count)
else if (redirectCount == presets.presets.Count)
{
return;
}
if (presets.installParent)
{
var parentMenu = go.GetOrAddComponent<ModularAvatarMenuItem>();
parentMenu.Control = new VRCExpressionsMenu.Control
{
name = go.name,
type = VRCExpressionsMenu.Control.ControlType.SubMenu,
icon = presets.icon,
};
parentMenu.MenuSource = SubmenuSource.Children;
}
else
{
Object.DestroyImmediate(parentMenu);
go.GetOrAddComponent<ModularAvatarMenuGroup>();
}
}

Expand Down
5 changes: 3 additions & 2 deletions Editor/AvatarParametersPresetsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ void OnEnable()

public override void OnInspectorGUI()
{
var cname = (target as AvatarParametersPresets).AvatarParametersSaverPresetGroup.installParent ? "MA Menu Item" : "MA Menu Group";
if ((target as AvatarParametersPresets).GetComponent<ModularAvatarMenuInstaller>() == null)
{
EditorGUILayout.HelpBox("このコンポーネントはMA Menu Itemのように振る舞います\nMA Menu Installerを同時に付けるとインストール先を指定できます。", MessageType.Info);
EditorGUILayout.HelpBox($"このコンポーネントは{cname}のように振る舞います\nMA Menu Installerを同時に付けるとインストール先を指定できます。", MessageType.Info);
}
else
{
EditorGUILayout.HelpBox("このコンポーネントはMA Menu Itemのように振る舞います\nMA Menu Installerのインストール先にメニューが生成されます。", MessageType.Info);
EditorGUILayout.HelpBox($"このコンポーネントは{cname}のように振る舞います\nMA Menu Installerのインストール先にメニューが生成されます。", MessageType.Info);
}
serializedObject.Update();
EditorGUILayout.PropertyField(AvatarParametersSaverPresetGroup);
Expand Down
6 changes: 5 additions & 1 deletion Editor/AvatarParametersSaverPresetGroupDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class AvatarParametersSaverPresetGroupDrawer : PropertyDrawer
SerializedProperty NetworkSynced;
SerializedProperty Presets;
SerializedProperty IndexOffset;
SerializedProperty InstallParent;
ReorderableList PresetsList;
bool ShowAdvanced;
bool ShowCustomize;
Expand All @@ -37,6 +38,8 @@ public Rect OnBaseGUI(Rect position, SerializedProperty property, GUIContent lab
position.yMin += EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(SingleLineRect(position), Icon);
position.yMin += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
EditorGUI.PropertyField(SingleLineRect(position), InstallParent, new GUIContent("親メニューを作る"));
position.yMin += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
ShowAdvanced = EditorGUI.Foldout(SingleLineRect(position), ShowAdvanced, new GUIContent("Advanced"));
position.yMin += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
if (ShowAdvanced)
Expand Down Expand Up @@ -126,7 +129,7 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent
public float GetBasePropertyHeight(SerializedProperty property, GUIContent label = null)
{
UpdatePropertiesIfNeeded(property);
var lines = ShowAdvanced ? 9 : 2;
var lines = ShowAdvanced ? 10 : 3;
return EditorGUIUtility.singleLineHeight * lines + EditorGUIUtility.standardVerticalSpacing * (lines + 2) + PresetsList.GetHeight();
}

Expand Down Expand Up @@ -193,6 +196,7 @@ void UpdateProperties()
NetworkSynced = Current.FindPropertyRelative(nameof(AvatarParametersSaverPresetGroup.networkSynced));
Presets = Current.FindPropertyRelative(nameof(AvatarParametersSaverPresetGroup.presets));
IndexOffset = Current.FindPropertyRelative(nameof(AvatarParametersSaverPresetGroup.IndexOffset));
InstallParent = Current.FindPropertyRelative(nameof(AvatarParametersSaverPresetGroup.installParent));
PresetsList = new ReorderableList(Current.serializedObject, Presets);
PresetsList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "Presets");
PresetsList.drawElementCallback = (rect, index, isActive, isFocused) =>
Expand Down
1 change: 1 addition & 0 deletions Scripts/AvatarParametersSaverPresetGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class AvatarParametersSaverPresetGroup
public bool networkSynced;
public List<AvatarParametersSaverPreset> presets = new List<AvatarParametersSaverPreset>();
public int IndexOffset;
public bool installParent = true;

public int GetPresetParameterValue(int index)
{
Expand Down

0 comments on commit 8af6802

Please sign in to comment.