Add dedicated editor for Texture Group picking

This commit is contained in:
Wojtek Figat
2021-06-18 09:43:35 +02:00
parent 801e3c26d4
commit 2d88ed17d4
2 changed files with 52 additions and 0 deletions

View File

@@ -286,6 +286,7 @@ namespace FlaxEditor.Content.Import
/// <summary>
/// Texture group for streaming (negative if unused). See Streaming Settings.
/// </summary>
[CustomEditor(typeof(CustomEditors.Dedicated.TextureGroupEditor))]
[EditorOrder(300), Tooltip("Texture group for streaming (negative if unused). See Streaming Settings.")]
public int TextureGroup = -1;

View File

@@ -0,0 +1,51 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using FlaxEditor.Content.Settings;
using FlaxEditor.CustomEditors.Elements;
using FlaxEditor.GUI;
using FlaxEngine;
namespace FlaxEditor.CustomEditors.Dedicated
{
/// <summary>
/// Custom editor for <see cref="TextureGroup"/> index.
/// </summary>
internal class TextureGroupEditor : CustomEditor
{
private ComboBoxElement _element;
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.Inline;
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
_element = layout.ComboBox();
_element.ComboBox.SelectedIndexChanged += OnSelectedIndexChanged;
_element.ComboBox.AddItem("None");
var groups = GameSettings.Load<StreamingSettings>();
if (groups?.TextureGroups != null)
{
for (int i = 0; i < groups.TextureGroups.Length; i++)
{
_element.ComboBox.AddItem(groups.TextureGroups[i].Name);
}
}
}
private void OnSelectedIndexChanged(ComboBox comboBox)
{
var value = comboBox.HasSelection ? comboBox.SelectedIndex - 1 : -1;
SetValue(value);
}
/// <inheritdoc />
public override void Refresh()
{
base.Refresh();
var value = (int)Values[0];
_element.ComboBox.SelectedIndex = value + 1;
}
}
}