diff --git a/Editor/FolderEditorUtils.cs b/Editor/FolderEditorUtils.cs index b18cf33..cda866b 100644 --- a/Editor/FolderEditorUtils.cs +++ b/Editor/FolderEditorUtils.cs @@ -26,7 +26,7 @@ public static void AddFolderPrefab(MenuCommand command) public class FolderOnBuild : IProcessSceneWithReport { - public int callbackOrder { get { return 0; } } + public int callbackOrder { get => 0; } public void OnProcessScene(Scene scene, BuildReport report) { diff --git a/Runtime/Folder.cs b/Runtime/Folder.cs index 50bcb90..404f1e7 100644 --- a/Runtime/Folder.cs +++ b/Runtime/Folder.cs @@ -20,24 +20,18 @@ namespace UnityHierarchyFolders.Runtime /// static class CanDestroyExtension { - private static bool Requires(Type obj, Type req) - { - return Attribute.IsDefined(obj, typeof(RequireComponent)) && - Attribute.GetCustomAttributes(obj, typeof(RequireComponent)) - .OfType() - // RequireComponent has up to 3 required types per requireComponent, because of course. - .SelectMany(rc => new Type[] { rc.m_Type0, rc.m_Type1, rc.m_Type2 }) - .Any(t => t != null && t.IsAssignableFrom(req)); - } + private static bool Requires(Type obj, Type req) => Attribute.IsDefined(obj, typeof(RequireComponent)) && + Attribute.GetCustomAttributes(obj, typeof(RequireComponent)) + .OfType() + // RequireComponent has up to 3 required types per requireComponent, because of course. + .SelectMany(rc => new Type[] { rc.m_Type0, rc.m_Type1, rc.m_Type2 }) + .Any(t => t != null && t.IsAssignableFrom(req)); /// Checks whether the stated component can be destroyed without violating dependencies. /// Is component destroyable? /// Component candidate for destruction. - internal static bool CanDestroy(this Component t) - { - return !t.gameObject.GetComponents() - .Any(c => Requires(c.GetType(), t.GetType())); - } + internal static bool CanDestroy(this Component t) => !t.gameObject.GetComponents() + .Any(c => Requires(c.GetType(), t.GetType())); } #endif @@ -85,15 +79,12 @@ private void HandleSelection() } } - private bool AskDelete() - { - return EditorUtility.DisplayDialog( - title: "Can't add script", - message: "Folders shouldn't be used with other components. Which component should be kept?", - ok: "Folder", - cancel: "Component" - ); - } + private bool AskDelete() => EditorUtility.DisplayDialog( + title: "Can't add script", + message: "Folders shouldn't be used with other components. Which component should be kept?", + ok: "Folder", + cancel: "Component" + ); /// Delete all components regardless of dependency hierarchy. /// Which components to delete. @@ -169,10 +160,11 @@ public void Flatten() { if (child.parent == this.transform) { - child.name = this.name + '/' + child.name; + child.name = $"{this.name}/{child.name}"; child.parent = this.transform.parent; } } + if (Application.isPlaying) { Destroy(this.gameObject);