Files
BABA_YAGA/Packages/app.rive.rive-unity/Editor/Components/TexturePanelRendererEditor.cs
2026-05-19 17:39:03 +07:00

42 lines
1.6 KiB
C#

using Rive.Components;
using UnityEditor;
using UnityEngine.UIElements;
namespace Rive.EditorTools
{
[CustomEditor(typeof(RiveTextureRenderer), true)]
internal class TexturePanelRendererEditor : PanelRendererInspector
{
public override VisualElement CreateInspectorGUI()
{
var root = base.CreateInspectorGUI() ?? new VisualElement();
// For worldspace renderers, we display a button to convert materials on the current mesh renderer, if needed.
// Makes it easier for users to switch to Rive materials without having to know the right ones to pick.
var textureRenderer = (RiveTextureRenderer)target;
if (textureRenderer != null && textureRenderer.Renderer != null)
{
System.Action clickAction = () =>
{
// This will replace any non-Rive materials with Rive equivalents, even if the existing materials are not Unity defaults.
MaterialConversionUtility.ReplaceMaterialsWithRive(textureRenderer.Renderer);
};
var convertButton = new Button(() => clickAction())
{
text = "Replace Materials with Rive Materials"
};
convertButton.name = "RiveConvertMaterialsButton";
convertButton.userData = clickAction; // allow tests to invoke without event system/panel
convertButton.style.marginTop = 6;
root.Add(convertButton);
}
return root;
}
}
}