diff --git a/Source/Editor/Content/Proxy/CollisionDataProxy.cs b/Source/Editor/Content/Proxy/CollisionDataProxy.cs index e865834fd..55e8c6327 100644 --- a/Source/Editor/Content/Proxy/CollisionDataProxy.cs +++ b/Source/Editor/Content/Proxy/CollisionDataProxy.cs @@ -80,7 +80,8 @@ namespace FlaxEditor.Content /// /// The associated model. /// The action to call once the collision data gets created (or reused from existing). - public void CreateCollisionDataFromModel(Model model, Action created = null) + /// True if start initial item renaming by user, or tru to skip it. + public void CreateCollisionDataFromModel(Model model, Action created = null, bool withRenaming = true) { // Check if there already is collision data for that model to reuse var modelItem = (AssetItem)Editor.Instance.ContentDatabase.Find(model.ID); @@ -140,7 +141,7 @@ namespace FlaxEditor.Content }); }; var initialName = (modelItem?.ShortName ?? Path.GetFileNameWithoutExtension(model.Path)) + " Collision"; - Editor.Instance.Windows.ContentWin.NewItem(this, null, create, initialName); + Editor.Instance.Windows.ContentWin.NewItem(this, null, create, initialName, withRenaming); } } } diff --git a/Source/Editor/Content/Proxy/ModelProxy.cs b/Source/Editor/Content/Proxy/ModelProxy.cs index ec6b3cd1b..845cbc80b 100644 --- a/Source/Editor/Content/Proxy/ModelProxy.cs +++ b/Source/Editor/Content/Proxy/ModelProxy.cs @@ -47,9 +47,23 @@ namespace FlaxEditor.Content menu.AddButton("Create collision data", () => { - var model = FlaxEngine.Content.LoadAsync(((ModelItem)item).ID); var collisionDataProxy = (CollisionDataProxy)Editor.Instance.ContentDatabase.GetProxy(); - collisionDataProxy.CreateCollisionDataFromModel(model); + var selection = Editor.Instance.Windows.ContentWin.View.Selection; + if (selection.Count > 1) + { + // Batch action + var items = selection.ToArray(); // Clone to prevent issue when iterating over and content window changes the selection + foreach (var contentItem in items) + { + if (contentItem is ModelItem modelItem) + collisionDataProxy.CreateCollisionDataFromModel(FlaxEngine.Content.LoadAsync(modelItem.ID), null, false); + } + } + else + { + var model = FlaxEngine.Content.LoadAsync(((ModelItem)item).ID); + collisionDataProxy.CreateCollisionDataFromModel(model); + } }); } diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 654eaa91d..82f700274 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -319,6 +319,7 @@ namespace FlaxEditor.Windows /// Shows popup dialog with UI to rename content item. /// /// The item to rename. + /// The created renaming popup. public void Rename(ContentItem item) { // Show element in the view @@ -336,24 +337,7 @@ namespace FlaxEditor.Windows popup.Tag = item; popup.Validate += OnRenameValidate; popup.Renamed += renamePopup => Rename((ContentItem)renamePopup.Tag, renamePopup.Text); - popup.Closed += renamePopup => - { - // Restore scrolling in content view - if (_contentViewPanel.VScrollBar != null) - _contentViewPanel.VScrollBar.ThumbEnabled = true; - if (_contentViewPanel.HScrollBar != null) - _contentViewPanel.HScrollBar.ThumbEnabled = true; - ScrollingOnContentView(true); - - // Check if was creating new element - if (_newElement != null) - { - // Destroy mock control - _newElement.ParentFolder = null; - _newElement.Dispose(); - _newElement = null; - } - }; + popup.Closed += OnRenameClosed; // For new asset we want to mock the initial value so user can press just Enter to use default name if (_newElement != null) @@ -367,6 +351,25 @@ namespace FlaxEditor.Windows return Editor.ContentEditing.IsValidAssetName((ContentItem)popup.Tag, value, out _); } + private void OnRenameClosed(RenamePopup popup) + { + // Restore scrolling in content view + if (_contentViewPanel.VScrollBar != null) + _contentViewPanel.VScrollBar.ThumbEnabled = true; + if (_contentViewPanel.HScrollBar != null) + _contentViewPanel.HScrollBar.ThumbEnabled = true; + ScrollingOnContentView(true); + + // Check if was creating new element + if (_newElement != null) + { + // Destroy mock control + _newElement.ParentFolder = null; + _newElement.Dispose(); + _newElement = null; + } + } + /// /// Renames the specified item. /// @@ -644,7 +647,8 @@ namespace FlaxEditor.Windows /// 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. /// The initial item name. - public void NewItem(ContentProxy proxy, object argument = null, Action created = null, string initialName = null) + /// True if start initial item renaming by user, or tru to skip it. + public void NewItem(ContentProxy proxy, object argument = null, Action created = null, string initialName = null, bool withRenaming = true) { Assert.IsNull(_newElement); if (proxy == null) @@ -666,14 +670,52 @@ namespace FlaxEditor.Windows } while (parentFolder.FindChild(path) != null); } - // Create new asset proxy, add to view and rename it - _newElement = new NewItem(path, proxy, argument) + if (withRenaming) { - ParentFolder = parentFolder, - Tag = created, - }; - RefreshView(); - Rename(_newElement); + // Create new asset proxy, add to view and rename it + _newElement = new NewItem(path, proxy, argument) + { + ParentFolder = parentFolder, + Tag = created, + }; + RefreshView(); + Rename(_newElement); + } + else + { + // Create new asset + try + { + Editor.Log(string.Format("Creating asset {0} in {1}", proxy.Name, path)); + proxy.Create(path, argument); + } + catch (Exception ex) + { + Editor.LogWarning(ex); + Editor.LogError("Failed to create asset."); + return; + } + + // Focus content window + Focus(); + RootWindow?.Focus(); + + // Refresh database and view now + Editor.ContentDatabase.RefreshFolder(parentFolder, false); + RefreshView(); + var newItem = parentFolder.FindChild(path); + if (newItem == null) + { + Editor.LogWarning("Failed to find the created new item."); + return; + } + + // Auto-select item + Select(newItem, true); + + // Custom post-action + created?.Invoke(newItem); + } } private void ContentDatabaseOnItemRemoved(ContentItem contentItem)