Skip to content

Commit

Permalink
Use shorthand syntax where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
xsduan committed Apr 8, 2019
1 parent 67acbb2 commit 369b32c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Editor/FolderEditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
40 changes: 16 additions & 24 deletions Runtime/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,18 @@ namespace UnityHierarchyFolders.Runtime
/// </summary>
static class CanDestroyExtension
{
private static bool Requires(Type obj, Type req)
{
return Attribute.IsDefined(obj, typeof(RequireComponent)) &&
Attribute.GetCustomAttributes(obj, typeof(RequireComponent))
.OfType<RequireComponent>()
// 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>()
// 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));

/// <summary>Checks whether the stated component can be destroyed without violating dependencies.</summary>
/// <returns>Is component destroyable?</returns>
/// <param name="t">Component candidate for destruction.</param>
internal static bool CanDestroy(this Component t)
{
return !t.gameObject.GetComponents<Component>()
.Any(c => Requires(c.GetType(), t.GetType()));
}
internal static bool CanDestroy(this Component t) => !t.gameObject.GetComponents<Component>()
.Any(c => Requires(c.GetType(), t.GetType()));
}
#endif

Expand Down Expand Up @@ -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"
);

/// <summary>Delete all components regardless of dependency hierarchy.</summary>
/// <param name="comps">Which components to delete.</param>
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 369b32c

Please sign in to comment.