diff --git a/Source/Editor/Content/Items/VisualScriptItem.cs b/Source/Editor/Content/Items/VisualScriptItem.cs index fd23887ec..22f1d75cc 100644 --- a/Source/Editor/Content/Items/VisualScriptItem.cs +++ b/Source/Editor/Content/Items/VisualScriptItem.cs @@ -75,6 +75,8 @@ namespace FlaxEditor.Content } } + public int MetadataToken => 0; + /// public bool HasAttribute(Type attributeType, bool inherit) { @@ -195,6 +197,8 @@ namespace FlaxEditor.Content /// public ScriptType ValueType => _returnType; + public int MetadataToken => 0; + /// public bool HasAttribute(Type attributeType, bool inherit) { diff --git a/Source/Editor/CustomEditors/Editors/GenericEditor.cs b/Source/Editor/CustomEditors/Editors/GenericEditor.cs index ed6d88e9e..eec715a6b 100644 --- a/Source/Editor/CustomEditors/Editors/GenericEditor.cs +++ b/Source/Editor/CustomEditors/Editors/GenericEditor.cs @@ -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); } diff --git a/Source/Editor/Options/GeneralOptions.cs b/Source/Editor/Options/GeneralOptions.cs index 85174030f..8d3948220 100644 --- a/Source/Editor/Options/GeneralOptions.cs +++ b/Source/Editor/Options/GeneralOptions.cs @@ -68,6 +68,24 @@ namespace FlaxEditor.Options CompileScripts, } + /// + /// Order of script members show in editor + /// + public enum MembersOrder + { + /// + /// Shows properties/fields in alphabetical order + /// + [Tooltip("Shows properties/fields in alphabetical order")] + Alphabetical, + + /// + /// Shows properties/fields in declaration order + /// + [Tooltip("Shows properties/fields in declaration order")] + Declaration + } + /// /// Gets or sets the scene to load on editor startup. /// @@ -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; + /// + /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor. + /// + [DefaultValue(true)] + [EditorDisplay("Scripting", "Script Members Order"), EditorOrder(503), Tooltip("Sets the order of script properties/fields")] + public MembersOrder ScriptMembersOrder { get; set; } = MembersOrder.Alphabetical; + /// /// Gets or sets a value indicating whether automatically save the Visual Script asset editors when starting the play mode in editor. /// diff --git a/Source/Editor/Scripting/ScriptType.cs b/Source/Editor/Scripting/ScriptType.cs index 53c84a1b5..480ca6a4e 100644 --- a/Source/Editor/Scripting/ScriptType.cs +++ b/Source/Editor/Scripting/ScriptType.cs @@ -40,6 +40,27 @@ namespace FlaxEditor.Scripting /// public string Name => _managed?.Name ?? _custom?.Name; + /// + /// Gets a metadata token for sorting so it may not be the actual token. + /// + 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; + } + } + /// /// Gets a value indicating whether the type is declared public. /// @@ -1444,6 +1465,11 @@ namespace FlaxEditor.Scripting /// string Name { get; } + /// + /// Gets a metadata token for sorting so it may not be the actual token. + /// + int MetadataToken { get; } + /// /// Gets a value indicating whether the type is declared public. ///