Improve initial name for static model collision data asset
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -598,25 +598,29 @@ namespace FlaxEditor.Windows
|
||||
/// <param name="proxy">The new item proxy.</param>
|
||||
/// <param name="argument">The argument passed to the proxy for the item creation. In most cases it is null.</param>
|
||||
/// <param name="created">The event called when the item is crated by the user. The argument is the new item.</param>
|
||||
public void NewItem(ContentProxy proxy, object argument = null, Action<ContentItem> created = null)
|
||||
/// <param name="initialName">The initial item name.</param>
|
||||
public void NewItem(ContentProxy proxy, object argument = null, Action<ContentItem> 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user