Search Unity

Command "Move All to Root"

Discussion in 'Addressables' started by Accky, Sep 26, 2018.

  1. Accky

    Accky

    Joined:
    Feb 9, 2016
    Posts:
    5
    When I use Addressable, I often want to place entries all at the root of the group.
    So I changed the Addressable System locally as below.

    Addressable System/Editor/GUI/AddressableAssetSettingGroupEditor.cs
    Add to line 1037

    menu.AddItem(new GUIContent("Move All to Root"), false, MoveAllToRoot, selectedNodes);

    Add to line 1216
    protected void MoveAllToRoot(object context)
    {
    if (EditorUtility.DisplayDialog("Move All Entry to Root?", "Are you sure you want to move all entyr to root?\n\nYou cannot undo this action.", "Yes", "No")) {
    List<AssetEntryTreeViewItem> selectedNodes = context as List<AssetEntryTreeViewItem>;
    var groups = new List<AddressableAssetGroup>();
    foreach (var item in selectedNodes) {
    var g = item.group;
    //Force move to Group Root
    List<AddressableAssetEntry> entries = new List<AddressableAssetEntry>();
    g.GatherAllAssets(entries, true, true);
    foreach (var e in entries) {
    e.address = e.AssetPath;
    editor.settings.CreateOrMoveEntry(e.guid, e.parentGroup);
    }

    //Address Shorten
    entries.Clear();
    g.GatherAllAssets(entries, true, true);
    foreach (var e in entries) {
    e.address = System.IO.Path.GetFileName(e.AssetPath);
    }

    //Collect entries to delete
    entries.Clear();
    foreach (var e in g.entries) {
    var isDirectory = System.IO.Directory.Exists(e.AssetPath);
    if (isDirectory) {
    entries.Add(e);
    }
    }

    //delete entries
    entries.ForEach(e => editor.settings.RemoveAssetEntry(e.guid));
    }
    }
    }



    I registered a folder to Addressable by dragging and dropping, use "Move All to Root" Command, and then move all the entries to the root.

    Could you please officially support such operation?
     
    Kichang-Kim likes this.
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    To make sure I understand, you have something like:
    /Assets/
    - Level1/
    -- Prefabs/
    --- all level 1 the prefabs...
    -- Textures/
    --- all level 1 the textures...
    - Level2/
    --....

    and you want to drag "Level1" into some group, but then do an operation so that the group just has a flat list of all level 1 prefabs and textures?

    What is the use-case here? Is it just so the addresses are simplified? Or so you can change them? or move things in/out of the group?

    I just want to make sure I understand the "why" of the feature to understand exactly how it should work.
    -Bill
     
  3. Accky

    Accky

    Joined:
    Feb 9, 2016
    Posts:
    5
    @unity_bill

    Thank you for reply.

    I'd like to easily register Assets individually into groups.
    And I'd like to easily set address to Assets, and access individually.

    Yes, I think.
    This function was necessary when I wanted to register lots of sound data contained in an audio folder to Group.

    When I did not use the function I posted, it took me a lot of time because I needed to drag and drop files one by one from project window.
    (Or once register a folder, drag and drop everything to the root.)

    Ideally, I hope that when dragging and dropping folders to Group, we can decide whether to register individually or register folder.
    The function I posted is the next-best option.

    Address simplification is not directly related to this operation.
    But, If the Asset's name do not same, it was convenient to have this function.
    For example, Audio files are almost no same name.
     
  4. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    makes sense. Thanks for the input.
     
    Accky likes this.