A small UI Razor component that renders an Edit button for a CharacterAvatar when the avatar is valid and the current StudioSession view is not "editor". The button calls Avatar.OpenEditor and shows the avatar's preset name. It also overrides BuildHash to combine the avatar preset JSON and the current StudioSession view string.
@using Sandbox
@using Sandbox.UI
@namespace CharacterEditor
@inherits PanelComponent
<root>
@if(Avatar.IsValid() && Scene.GetAllComponents<StudioSession>().All(x=>x.View!="editor"))
{<button [email protected]>Edit @Avatar.Preset.Name</button>}
</root>
@code {
public CharacterAvatar Avatar { get; set; }
protected override int BuildHash() => System.HashCode.Combine(Avatar?.PresetJson, Scene.GetAllComponents<StudioSession>().FirstOrDefault()?.View);
}