From e4079f011dd335a03ca1b9b956d9934a049e9fc7 Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Fri, 22 Jul 2022 10:20:13 +0200 Subject: [PATCH] Improve initial name for static model collision data asset --- .../Content/Proxy/CollisionDataProxy.cs | 4 +++- Source/Editor/Windows/ContentWindow.cs | 20 +++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Content/Proxy/CollisionDataProxy.cs b/Source/Editor/Content/Proxy/CollisionDataProxy.cs index fbcfaad40..cca8a8192 100644 --- a/Source/Editor/Content/Proxy/CollisionDataProxy.cs +++ b/Source/Editor/Content/Proxy/CollisionDataProxy.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; +using System.IO; using System.Threading.Tasks; using FlaxEditor.Windows; using FlaxEditor.Windows.Assets; @@ -137,7 +138,8 @@ namespace FlaxEditor.Content FlaxEngine.Scripting.InvokeOnUpdate(() => created(collisionData)); }); }; - Editor.Instance.Windows.ContentWin.NewItem(this, null, create); + var initialName = (modelItem?.ShortName ?? Path.GetFileNameWithoutExtension(model.Path)) + " Collision"; + Editor.Instance.Windows.ContentWin.NewItem(this, null, create, initialName); } } } diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index bd37610ac..aa01badf5 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -598,25 +598,29 @@ namespace FlaxEditor.Windows /// The new item proxy. /// The argument passed to the proxy for the item creation. In most cases it is null. /// The event called when the item is crated by the user. The argument is the new item. - public void NewItem(ContentProxy proxy, object argument = null, Action created = null) + /// The initial item name. + public void NewItem(ContentProxy proxy, object argument = null, Action created = null, string initialName = null) { Assert.IsNull(_newElement); if (proxy == null) throw new ArgumentNullException(nameof(proxy)); - string name = proxy.NewItemName; + string name = initialName ?? proxy.NewItemName; ContentFolder parentFolder = CurrentViewFolder; string parentFolderPath = parentFolder.Path; // Create asset name - string path; string extension = '.' + proxy.FileExtension; - int i = 0; - do + string path = StringUtils.CombinePaths(parentFolderPath, name + extension); + if (parentFolder.FindChild(path) != null) { - path = StringUtils.CombinePaths(parentFolderPath, string.Format("{0} {1}", name, i++) + extension); - } while (parentFolder.FindChild(path) != null); - + int i = 0; + do + { + path = StringUtils.CombinePaths(parentFolderPath, string.Format("{0} {1}", name, i++) + extension); + } while (parentFolder.FindChild(path) != null); + } + // Create new asset proxy, add to view and rename it _newElement = new NewItem(path, proxy, argument) {