A small UI Razor component that renders an Edit button for a CharacterAvatar when the avatar is valid and no StudioSession component has View equal to "editor". The button invokes Avatar.OpenEditor and shows the avatar preset name. It also overrides BuildHash to combine Avatar.PresetJson and the first StudioSession.View for UI invalidation.
@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);
}