Menu Icon Replacer
This commit is contained in:
parent
b774208e32
commit
2f770cf724
13 changed files with 301 additions and 0 deletions
8
MenuIconReplacer.meta
Normal file
8
MenuIconReplacer.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4a654954dc6cec1489d07ed6e2948696
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
MenuIconReplacer/Editor.meta
Normal file
8
MenuIconReplacer/Editor.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 242e6d8788815f146a868fa94fce66ea
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
20
MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef
Normal file
20
MenuIconReplacer/Editor/MenuIconReplacerEditor.asmdef
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"name": "MenuIconReplacerEditor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:108c6ed81f83e074fa168f7087c2a246",
|
||||
"GUID:62ced99b048af7f4d8dfe4bed8373d76",
|
||||
"GUID:5718fb738711cd34ea54e9553040911d"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 80b77092c9bbd5b48b726b52e8b9c308
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
111
MenuIconReplacer/Editor/MenuIconReplacerInspector.cs
Normal file
111
MenuIconReplacer/Editor/MenuIconReplacerInspector.cs
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using gay.lilyy.MenuIconReplacer;
|
||||
|
||||
namespace gay.lilyy.MenuIconReplacer.Editor
|
||||
{
|
||||
[CustomEditor(typeof(MenuIconReplacerConfig))]
|
||||
public class MenuIconReplacerInspector : UnityEditor.Editor
|
||||
{
|
||||
private SerializedProperty replacementsProperty;
|
||||
private bool showReplacements = true;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
replacementsProperty = serializedObject.FindProperty("replacements");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
EditorGUILayout.LabelField("Menu Icon Replacer", EditorStyles.boldLabel);
|
||||
EditorGUILayout.HelpBox("Configure texture replacements for menu icons. The left texture will be replaced with the right texture in the expressions menu.", MessageType.Info);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
showReplacements = EditorGUILayout.Foldout(showReplacements, $"Replacements ({replacementsProperty.arraySize})", true);
|
||||
|
||||
if (showReplacements)
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
|
||||
// Add new replacement button
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Button("Add Replacement"))
|
||||
{
|
||||
replacementsProperty.InsertArrayElementAtIndex(replacementsProperty.arraySize);
|
||||
}
|
||||
|
||||
if (GUILayout.Button("Clear All") && replacementsProperty.arraySize > 0)
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Clear All Replacements",
|
||||
"Are you sure you want to clear all replacements?", "Yes", "Cancel"))
|
||||
{
|
||||
replacementsProperty.ClearArray();
|
||||
}
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
// Display replacements
|
||||
for (int i = 0; i < replacementsProperty.arraySize; i++)
|
||||
{
|
||||
var element = replacementsProperty.GetArrayElementAtIndex(i);
|
||||
var fromProperty = element.FindPropertyRelative("from");
|
||||
var toProperty = element.FindPropertyRelative("to");
|
||||
|
||||
EditorGUILayout.BeginVertical("box");
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField($"Replacement {i + 1}", EditorStyles.boldLabel, GUILayout.Width(100));
|
||||
|
||||
if (GUILayout.Button("Remove", GUILayout.Width(60)))
|
||||
{
|
||||
replacementsProperty.DeleteArrayElementAtIndex(i);
|
||||
break;
|
||||
}
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("From:", GUILayout.Width(40));
|
||||
EditorGUILayout.PropertyField(fromProperty, GUIContent.none);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField("To:", GUILayout.Width(40));
|
||||
EditorGUILayout.PropertyField(toProperty, GUIContent.none);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
// Validation
|
||||
var fromTexture = fromProperty.objectReferenceValue as Texture2D;
|
||||
var toTexture = toProperty.objectReferenceValue as Texture2D;
|
||||
|
||||
if (fromTexture != null && toTexture != null && fromTexture == toTexture)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Warning: Source and target textures are the same.", MessageType.Warning);
|
||||
}
|
||||
else if (fromTexture != null && toTexture == null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Target texture is not set.", MessageType.Warning);
|
||||
}
|
||||
else if (fromTexture == null && toTexture != null)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Source texture is not set.", MessageType.Warning);
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
EditorGUILayout.Space();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
11
MenuIconReplacer/Editor/MenuIconReplacerInspector.cs.meta
Normal file
11
MenuIconReplacer/Editor/MenuIconReplacerInspector.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 43cc613e338942941a9a549788e36afc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
66
MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs
Normal file
66
MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using System.Collections.Generic;
|
||||
using gay.lilyy.MenuIconReplacer;
|
||||
using nadena.dev.ndmf;
|
||||
using NUnit.Framework.Constraints;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using VRC.SDK3.Avatars.ScriptableObjects;
|
||||
using static VRC.SDK3.Avatars.ScriptableObjects.VRCExpressionsMenu;
|
||||
|
||||
[assembly: ExportsPlugin(typeof(MenuIconReplacerPlugin))]
|
||||
|
||||
namespace gay.lilyy.MenuIconReplacer
|
||||
{
|
||||
public class MenuIconReplacerPlugin : Plugin<MenuIconReplacerPlugin>
|
||||
{
|
||||
public override string DisplayName => "MenuIconReplacer";
|
||||
public override string QualifiedName => "gay.lilyy.MenuIconReplacer";
|
||||
|
||||
protected override void Configure()
|
||||
{
|
||||
InPhase(BuildPhase.Optimizing).BeforePlugin("gay.lilyy.MenuIconRemover").Run("ReplaceMenuIcons", ctx =>
|
||||
{
|
||||
var obj = ctx.AvatarRootObject.GetComponent<MenuIconReplacerConfig>();
|
||||
if (obj != null)
|
||||
{
|
||||
ctx.AvatarDescriptor.expressionsMenu = RecurseMenu(obj, ctx.AvatarDescriptor.expressionsMenu);
|
||||
Object.DestroyImmediate(obj);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private VRCExpressionsMenu RecurseMenu(MenuIconReplacerConfig cfg, VRCExpressionsMenu menu)
|
||||
{
|
||||
if (menu == null) return null;
|
||||
|
||||
var newMenu = ScriptableObject.CreateInstance<VRCExpressionsMenu>();
|
||||
newMenu.controls = new List<Control>();
|
||||
|
||||
foreach (var control in menu.controls)
|
||||
{
|
||||
var icon = control.icon;
|
||||
foreach (var entry in cfg.replacements)
|
||||
{
|
||||
if (entry.from == icon) {
|
||||
icon = entry.to;
|
||||
}
|
||||
}
|
||||
var newControl = new Control
|
||||
{
|
||||
name = control.name,
|
||||
type = control.type,
|
||||
icon = icon,
|
||||
parameter = control.parameter,
|
||||
subMenu = RecurseMenu(cfg, control.subMenu),
|
||||
value = control.value,
|
||||
style = control.style,
|
||||
labels = control.labels,
|
||||
subParameters = control.subParameters
|
||||
};
|
||||
newMenu.controls.Add(newControl);
|
||||
}
|
||||
|
||||
return newMenu;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs.meta
Normal file
11
MenuIconReplacer/Editor/MenuIconReplacerPlugin.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b9fdfa35ac20a541848fa1c355dda23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
MenuIconReplacer/Runtime.meta
Normal file
8
MenuIconReplacer/Runtime.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dbba2be0d4a22f24abf8cf72fcc0ae76
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
19
MenuIconReplacer/Runtime/MenuIconReplacerConfig.cs
Normal file
19
MenuIconReplacer/Runtime/MenuIconReplacerConfig.cs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace gay.lilyy.MenuIconReplacer
|
||||
{
|
||||
[System.Serializable]
|
||||
public class TextureReplacement
|
||||
{
|
||||
public Texture2D from;
|
||||
public Texture2D to;
|
||||
}
|
||||
|
||||
public class MenuIconReplacerConfig : MonoBehaviour, VRC.SDKBase.IEditorOnly
|
||||
{
|
||||
[HideInInspector]
|
||||
public List<TextureReplacement> replacements = new List<TextureReplacement>();
|
||||
}
|
||||
}
|
||||
11
MenuIconReplacer/Runtime/MenuIconReplacerConfig.cs.meta
Normal file
11
MenuIconReplacer/Runtime/MenuIconReplacerConfig.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a6d76942481598d4b8d9c823b1f809c0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
MenuIconReplacer/Runtime/MenuIconReplacerRuntime.asmdef
Normal file
14
MenuIconReplacer/Runtime/MenuIconReplacerRuntime.asmdef
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "MenuIconReplacerRuntime",
|
||||
"rootNamespace": "",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 108c6ed81f83e074fa168f7087c2a246
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue