Merge branch 'patch-declarationSort' of git://github.com/honzapatCZ/FlaxEngine into honzapatCZ-patch-declarationSort

This commit is contained in:
Wojtek Figat
2021-03-14 19:29:02 +01:00
4 changed files with 63 additions and 0 deletions

View File

@@ -75,6 +75,8 @@ namespace FlaxEditor.Content
}
}
public int MetadataToken => 0;
/// <inheritdoc />
public bool HasAttribute(Type attributeType, bool inherit)
{
@@ -195,6 +197,8 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public ScriptType ValueType => _returnType;
public int MetadataToken => 0;
/// <inheritdoc />
public bool HasAttribute(Type attributeType, bool inherit)
{

View File

@@ -173,6 +173,14 @@ namespace FlaxEditor.CustomEditors.Editors
return string.Compare(Display.Group, other.Display.Group, StringComparison.InvariantCulture);
}
if(Editor.Instance.Options.Options.General.ScriptMembersOrder == Options.GeneralOptions.MembersOrder.Declaration)
{
// By declaration order
if (Info.MetadataToken > other.Info.MetadataToken)
return 1;
else if (Info.MetadataToken < other.Info.MetadataToken)
return -1;
}
// By name
return string.Compare(Info.Name, other.Info.Name, StringComparison.InvariantCulture);
}

View File

@@ -68,6 +68,24 @@ namespace FlaxEditor.Options
CompileScripts,
}
/// <summary>
/// Order of script members show in editor
/// </summary>
public enum MembersOrder
{
/// <summary>
/// Shows properties/fields in alphabetical order
/// </summary>
[Tooltip("Shows properties/fields in alphabetical order")]
Alphabetical,
/// <summary>
/// Shows properties/fields in declaration order
/// </summary>
[Tooltip("Shows properties/fields in declaration order")]
Declaration
}
/// <summary>
/// Gets or sets the scene to load on editor startup.
/// </summary>
@@ -116,6 +134,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Scripting", "Force Script Compilation On Startup"), EditorOrder(501), Tooltip("Determines whether automatically compile game scripts before starting the editor.")]
public bool ForceScriptCompilationOnStartup { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor.
/// </summary>
[DefaultValue(true)]
[EditorDisplay("Scripting", "Script Members Order"), EditorOrder(503), Tooltip("Sets the order of script properties/fields")]
public MembersOrder ScriptMembersOrder { get; set; } = MembersOrder.Alphabetical;
/// <summary>
/// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor.
/// </summary>

View File

@@ -40,6 +40,27 @@ namespace FlaxEditor.Scripting
/// </summary>
public string Name => _managed?.Name ?? _custom?.Name;
/// <summary>
/// Gets a metadata token for sorting so it may not be the actual token.
/// </summary>
public int MetadataToken
{
get
{
int standardToken = _managed?.MetadataToken ?? _custom?.MetadataToken ?? 0;
if (_managed != null && IsProperty)
{
ScriptMemberInfo finfo = DeclaringType.GetField(string.Format("<{0}>k__BackingField", Name), BindingFlags.Instance | BindingFlags.NonPublic);
if(finfo.MetadataToken == 0)
{
return standardToken;
}
return finfo.MetadataToken;
}
return standardToken;
}
}
/// <summary>
/// Gets a value indicating whether the type is declared public.
/// </summary>
@@ -1444,6 +1465,11 @@ namespace FlaxEditor.Scripting
/// </summary>
string Name { get; }
/// <summary>
/// Gets a metadata token for sorting so it may not be the actual token.
/// </summary>
int MetadataToken { get; }
/// <summary>
/// Gets a value indicating whether the type is declared public.
/// </summary>