Ejemplo n.º 1
0
            public override void OnGUI(Rect windowRect)
            {
                GUILayout.Space(5);
                Event evt      = Event.current;
                bool  hitEnter = evt.type == EventType.KeyDown && (evt.keyCode == KeyCode.Return || evt.keyCode == KeyCode.KeypadEnter);

                UnityEngine.GUI.SetNextControlName("LabelName");
                name = EditorGUILayout.TextField("New Tag EventName", name);
                if (needsFocus)
                {
                    needsFocus = false;
                    EditorGUI.FocusTextInControl("LabelName");
                }

                UnityEngine.GUI.enabled = name.Length != 0;
                if (GUILayout.Button("Save") || hitEnter)
                {
                    if (string.IsNullOrEmpty(name))
                    {
                        Debug.LogError("Cannot add empty label to Addressables label list");
                    }
                    else if (name != settings.labelTable.GetUniqueLabelName(name))
                    {
                        Debug.LogError("Label name '" + name + "' is already in the labels list.");
                    }
                    else
                    {
                        settings.AddLabel(name);
                    }

                    editorWindow.Close();
                }
            }
Ejemplo n.º 2
0
    static void CreateEntry(AddressableAssetSettings setting, AddressableAssetGroup group, string guid, string key, string label = null)
    {
        var entry = group.GetAssetEntry(guid);

        if (entry == null)
        {
            entry = setting.CreateOrMoveEntry(guid, group);
            entry.SetAddress(key);
            if (label != null)
            {
                setting.AddLabel(label, true);
                entry.SetLabel(label, true);
            }

            EditorUtility.SetDirty(setting);
        }
        else
        {
            string path = AssetDatabase.GUIDToAssetPath(guid);
            if (string.IsNullOrEmpty(path))
            {
                setting.RemoveAssetEntry(guid);
            }
            else
            {
                if (key != entry.address)
                {
                    entry.SetAddress(key);
                    if (label != null)
                    {
                        setting.AddLabel(label, true);
                        entry.SetLabel(label, true);
                    }

                    EditorUtility.SetDirty(setting);
                }
            }
        }
    }
Ejemplo n.º 3
0
    internal void SetLabelValueForEntries(AddressableAssetSettings settings, List <AddressableAssetEntry> entries, string label, bool value, bool postEvent = true)
    {
        if (value)
        {
            settings.AddLabel(label);
        }

        foreach (var e in entries)
        {
            e.SetLabel(label, value, false);
        }

        settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, postEvent, true);
    }
Ejemplo n.º 4
0
    public override void FixIssues(AddressableAssetSettings settings)
    {
        // If we have no duplicate data, run the check again
        if (duplicateAssetsAndParents == null || duplicateAssetsAndParents.Count == 0)
        {
            CheckForDuplicateDependencies(settings);
        }

        // If we have found no duplicates, return
        if (duplicateAssetsAndParents.Count == 0)
        {
            return;
        }

        // Setup Addressables Group to store all our duplicate assets
        string desiredGroupName     = "Duplicate Assets Sorted By Label";
        AddressableAssetGroup group = settings.FindGroup(desiredGroupName);

        if (group == null)
        {
            group = settings.CreateGroup(desiredGroupName, false, false, false, null, typeof(BundledAssetGroupSchema), typeof(ContentUpdateGroupSchema));
            var bundleSchema = group.GetSchema <BundledAssetGroupSchema>();
            // Set to pack by label so that assets with the same label are put in the same AssetBundle
            bundleSchema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel;
        }

        EditorUtility.DisplayProgressBar("Setting up De-Duplication Group...", "", 0f / duplicateAssetsAndParents.Count);
        // Iterate through each duplicate asset
        int bundleNumber = 1;

        foreach (var entry in duplicateAssetsAndParents)
        {
            EditorUtility.DisplayProgressBar("Setting up De-Duplication Group...", "Creating Label Group", ((float)bundleNumber) / duplicateAssetsAndParents.Count);
            string desiredLabelName = "Bundle" + bundleNumber;
            List <AddressableAssetEntry> entriesToAdd = new List <AddressableAssetEntry>();
            // Put each asset in the shared Group
            foreach (string assetPath in entry.Value)
            {
                entriesToAdd.Add(settings.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(assetPath).ToString(), group, false, false));
            }

            // Set the label for this selection of assets so they get packed into the same AssetBundle
            settings.AddLabel(desiredLabelName);
            SetLabelValueForEntries(settings, entriesToAdd, desiredLabelName, true);
            bundleNumber++;
        }

        settings.SetDirty(AddressableAssetSettings.ModificationEvent.BatchModification, null, true, true);
    }
Ejemplo n.º 5
0
        private static void SetLabelToAsset(List <string> assetGuidList, string label, bool flag)
        {
            AddressableAssetSettings assetSettings = GetSettings();

            //ラベルを追加するように呼んでおく。追加されていないと設定されない。
            assetSettings.AddLabel(label);
            List <AddressableAssetEntry> assetList = new List <AddressableAssetEntry>();

            assetSettings.GetAllAssets(assetList, true);
            foreach (AddressableAssetEntry asset in assetGuidList.Select(assetGuid =>
                                                                         assetList.Find((a) => a.guid == assetGuid)))
            {
                asset?.SetLabel(label, flag);
            }
        }
Ejemplo n.º 6
0
    public static void AddFileToAddressables()
    {
        AddressablesRules rules = new AddressablesRules();
        Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds();
        AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false);
        AddressableAssetGroup    group      = null;

        //清理错误group
        for (int i = aaSettings.groups.Count - 1; i >= 0; i--)
        {
            var g = aaSettings.groups[i];
            if (g == null || g.entries.Count == 0)
            {
                aaSettings.RemoveGroup(g);
                g = null;
                continue;
            }
            //
            // if (g != null)
            // {
            //     g.Name = $"{g.Name}_delete";
            // }
        }

        foreach (string key in bundles.Keys)
        {
            group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName);
            if (group == null)
            {
                group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null);
            }

            BundledAssetGroupSchema schema = group.GetSchema <BundledAssetGroupSchema>();
            if (schema == null)
            {
                schema = group.AddSchema <BundledAssetGroupSchema>();
            }

            ContentUpdateGroupSchema contentUpdateGroupSchema = group.GetSchema <ContentUpdateGroupSchema>();
            if (contentUpdateGroupSchema == null)
            {
                contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>();
            }

            schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
            if (bundles[key].packageType == "PackSeparately")
            {
                schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;
            }
            else if (bundles[key].packageType == "PackTogether")
            {
                schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
            }
            else if (bundles[key].packageType == "PackTogetherByLabel")
            {
                schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel;
            }

            schema.IncludeInBuild      = true;
            schema.UseAssetBundleCache = true;
            schema.UseAssetBundleCrc   = false;
            schema.UseAssetBundleCrcForCachedBundles = false;

            if (bundles[key].ResType == "online")
            {
                schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteBuildPath);
                schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteLoadPath);
                schema.BundleNaming      = BundledAssetGroupSchema.BundleNamingStyle.AppendHash;
                schema.UseAssetBundleCrc = true;
                contentUpdateGroupSchema.StaticContent = false;
            }
            else
            {
                schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalBuildPath);
                schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalLoadPath);
                schema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
                contentUpdateGroupSchema.StaticContent = true;
            }
        }

        foreach (string key in bundles.Keys)
        {
            int count    = 0;
            int MaxCount = bundles[key].entitys.Count;
            group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName);
            foreach (string entitysKey in bundles[key].entitys.Keys)
            {
                count++;
                if (count % 3 == 0)
                {
                    if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(string.Format("Collecting... [{0}/{1}]", count, MaxCount), entitysKey,
                                                                               count * 1f / MaxCount))
                    {
                        break;
                    }
                }

                string guid = AssetDatabase.AssetPathToGUID(bundles[key].entitys[entitysKey].filestring);
                AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group);
                entity.SetAddress(entitysKey);
                for (int i = 0; i < bundles[key].Lable.Length; i++)
                {
                    if (bundles[key].Lable[i].Contains("#"))
                    {
                        if (!string.IsNullOrEmpty(bundles[key].entitys[entitysKey].folderlabel))
                        {
                            aaSettings.AddLabel(bundles[key].entitys[entitysKey].folderlabel);
                            entity.SetLabel(bundles[key].entitys[entitysKey].folderlabel, true);
                        }
                    }
                    else
                    {
                        aaSettings.AddLabel(bundles[key].Lable[i]);
                        entity.SetLabel(bundles[key].Lable[i], true);
                    }
                }
            }
        }
        // for (int i = aaSettings.groups.Count - 1; i >= 0; i--)
        // {
        //     var g = aaSettings.groups[i];
        //     if (g == null || g.entries.Count == 0)
        //     {
        //         aaSettings.RemoveGroup(g);
        //         g = null;
        //         continue;
        //     }
        //
        //     if (g != null)
        //     {
        //         if (g.Name.Contains("_delete"))
        //         {
        //             aaSettings.RemoveGroup(g);
        //             g = null;
        //         }
        //     }
        // }
        UnityEditor.EditorUtility.ClearProgressBar();
    }
Ejemplo n.º 7
0
 private static void AddLabelToSetting(string label)
 {
     AssetTools.labels.Add(label);
     addressableSettings.AddLabel(label);
 }
Ejemplo n.º 8
0
    static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry(
        AddressableAssetSettings settings,
        AddressableImportSettings importSettings,
        AddressableImportRule rule,
        string assetPath)
    {
        // Set group
        AddressableAssetGroup group;
        var  groupName = rule.ParseGroupReplacement(assetPath);
        bool newGroup  = false;

        if (!TryGetGroup(settings, groupName, out group))
        {
            if (importSettings.allowGroupCreation)
            {
                //TODO Specify on editor which type to create.
                group    = CreateAssetGroup <BundledAssetGroupSchema>(settings, groupName);
                newGroup = true;
            }
            else
            {
                Debug.LogErrorFormat("[AddressableImporter] Failed to find group {0} when importing {1}. Please check if the group exists, then reimport the asset.", rule.groupName, assetPath);
                return(null);
            }
        }

        // Set group settings from template if necessary
        if (rule.groupTemplate != null && (newGroup || rule.groupTemplateApplicationMode == GroupTemplateApplicationMode.AlwaysOverwriteGroupSettings))
        {
            rule.groupTemplate.ApplyToAddressableAssetGroup(group);
        }

        var guid  = AssetDatabase.AssetPathToGUID(assetPath);
        var entry = settings.CreateOrMoveEntry(guid, group);

        if (entry != null)
        {
            // Apply address replacement if address is empty or path.
            if (string.IsNullOrEmpty(entry.address) ||
                entry.address.StartsWith("Assets/") ||
                rule.simplified ||
                !string.IsNullOrWhiteSpace(rule.addressReplacement))
            {
                entry.address = rule.ParseAddressReplacement(assetPath);
            }

            // Add labels
            if (rule.LabelMode == LabelWriteMode.Replace)
            {
                entry.labels.Clear();
            }
            foreach (var label in rule.labelsRefsEnum)
            {
                entry.labels.Add(label);
            }

            foreach (var dynamicLabel in rule.dynamicLabels)
            {
                var label = rule.ParseReplacement(assetPath, dynamicLabel);
                settings.AddLabel(label);
                entry.labels.Add(label);
            }
        }
        return(entry);
    }
        public static void AddFileToAddressables()
        {
            AddressablesRules rules = new AddressablesRules();
            Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds();
            AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false);
            AddressableAssetGroup    group      = null;

            //清理重名group
            foreach (string key in bundles.Keys)
            {
                group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName);
                if (group != null)
                {
                    aaSettings.RemoveGroup(group);
                    group = null;
                }
            }

            foreach (string key in bundles.Keys)
            {
                group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName);
                if (group == null)
                {
                    if (bundles[key].ResType == "online")
                    {
                        group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null);
                        BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>();
                        schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4;
                        if (bundles[key].packageType == "PackSeparately")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;
                        }
                        else if (bundles[key].packageType == "PackTogether")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
                        }
                        else if (bundles[key].packageType == "PackTogetherByLabel")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel;
                        }
                        schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteBuildPath);
                        schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteLoadPath);
                        schema.UseAssetBundleCache = true;
                        schema.UseAssetBundleCrc   = true;
                        ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>();
                        contentUpdateGroupSchema.StaticContent = false;
                        group = null;
                    }
                    else
                    {
                        group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null);
                        BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>();
                        schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.Uncompressed;
                        if (bundles[key].packageType == "PackSeparately")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;
                        }
                        else if (bundles[key].packageType == "PackTogether")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether;
                        }
                        else if (bundles[key].packageType == "PackTogetherByLabel")
                        {
                            schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel;
                        }

                        if (bundles[key].canUpdate)
                        {
                            ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>();
                            contentUpdateGroupSchema.StaticContent = false;
                        }

                        schema.UseAssetBundleCache = true;
                        schema.UseAssetBundleCrc   = true;
                        group = null;
                    }
                }
            }


            foreach (string key in bundles.Keys)
            {
                int count    = 0;
                int MaxCount = bundles[key].entitys.Count;
                group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName);
                foreach (string entitysKey in bundles[key].entitys.Keys)
                {
                    count++;
                    if (count % 3 == 0)
                    {
                        if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(
                                string.Format("Collecting... [{0}/{1}]", count, MaxCount), entitysKey,
                                count * 1f / MaxCount))
                        {
                            break;
                        }
                    }

                    string guid = AssetDatabase.AssetPathToGUID(bundles[key].entitys[entitysKey]);
                    AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group);
                    entity.SetAddress(entitysKey);
                    for (int i = 0; i < bundles[key].Lable.Length; i++)
                    {
                        aaSettings.AddLabel(bundles[key].Lable[i]);
                        entity.SetLabel(bundles[key].Lable[i], true);
                    }
                }
            }

            UnityEditor.EditorUtility.ClearProgressBar();
        }
        public override void OnGUI(Rect fullRect)
        {
            if (m_Entries.Count == 0)
            {
                return;
            }
            int count = -1;

            if (m_Labels == null)
            {
                m_Labels = GetLabelNamesOrderedSelectedFirst();
            }

            var areaRect = new Rect(fullRect.xMin + 3, fullRect.yMin + 3, fullRect.width - 6, fullRect.height - 6);

            GUILayout.BeginArea(areaRect);

            GUILayoutUtility.GetRect(areaRect.width, 1);
            Rect barRect    = EditorGUILayout.GetControlRect();
            var  marginDown = GUILayoutUtility.GetRect(areaRect.width, 1);

            Rect plusRect = barRect;

            plusRect.width = plusRect.height;
            plusRect.x     = (barRect.width - plusRect.width) + 4;
            if (UnityEngine.GUI.Button(plusRect, m_ManageLabelsButtonContent, m_ToolbarButtonStyle))
            {
                EditorWindow.GetWindow <LabelWindow>(true).Intialize(m_Settings);
                editorWindow.Close();
            }

            Rect  searchRect = barRect;
            float plusOffset = plusRect.width + 2;

            searchRect.width = searchRect.width - plusOffset;
            m_SearchValue    = m_SearchField.OnGUI(searchRect, m_SearchValue, m_SearchStyles[0], m_SearchStyles[1], m_SearchStyles[2]);

            EditorGUI.BeginDisabledGroup(true);
            string labelText;
            int    searchLabelIndex = m_Labels.IndexOf(m_SearchValue);

            if (searchLabelIndex >= 0)
            {
                if (m_LabelCount == null)
                {
                    count = m_Entries[0].labels.Contains(m_SearchValue) ? m_Entries.Count : 0;
                }
                else
                {
                    m_LabelCount.TryGetValue(m_SearchValue, out count);
                }
                labelText = string.Format(count == m_Entries.Count ? k_HintSearchFoundIsEnabled : k_HintSearchFoundIsDisabled, m_SearchValue);
            }
            else
            {
                labelText = !string.IsNullOrEmpty(m_SearchValue) ? string.Format(k_HintCreateNewLabel, m_SearchValue) : k_HintIdle;
            }

            Rect hintRect = EditorGUILayout.GetControlRect(true, m_HintLabelStyle.CalcHeight(new GUIContent(labelText), fullRect.width), m_HintLabelStyle);

            hintRect.x     -= 3;
            hintRect.width += 6;
            hintRect.y     -= 3;
            EditorGUI.LabelField(hintRect, new GUIContent(labelText), m_HintLabelStyle);
            EditorGUI.EndDisabledGroup();

            if (Event.current.isKey && (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter) && m_SearchField.HasFocus())
            {
                if (!string.IsNullOrEmpty(m_SearchValue))
                {
                    if (searchLabelIndex >= 0)
                    {
                        if (count != m_Entries.Count)
                        {
                            SetLabelForEntries(m_SearchValue, true);
                        }
                        else
                        {
                            SetLabelForEntries(m_SearchValue, false);
                        }
                    }
                    else
                    {
                        m_Settings.AddLabel(m_SearchValue);
                        AddressableAssetUtility.OpenAssetIfUsingVCIntegration(m_Settings);
                        SetLabelForEntries(m_SearchValue, true);
                        m_Labels.Insert(0, m_SearchValue);
                    }

                    m_ControlToFocus = m_SearchValue;
                    UnityEngine.GUI.ScrollTo(new Rect(0, searchLabelIndex * 19, 0, 0));
                    m_SearchValue   = "";
                    m_LastItemCount = -1;

                    Event.current.Use();
                    GUIUtility.ExitGUI();
                    editorWindow.Repaint();
                }
            }

            var scrollViewHeight = areaRect.height - (hintRect.y + hintRect.height + 2);

            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, false, false);
            Vector2 yPositionDrawRange = new Vector2(m_ScrollPosition.y - 19, m_ScrollPosition.y + scrollViewHeight);

            for (int i = 0; i < m_Labels.Count; ++i)
            {
                var labelName = m_Labels[i];
                if (!string.IsNullOrEmpty(m_SearchValue))
                {
                    if (labelName.IndexOf(m_SearchValue, StringComparison.OrdinalIgnoreCase) < 0)
                    {
                        continue;
                    }
                }

                var toggleRect = EditorGUILayout.GetControlRect(GUILayout.Width(m_LabelToggleControlRectWidth), GUILayout.Height(m_LabelToggleControlRectHeight));
                if (toggleRect.height > 1)
                {
                    // only draw toggles if they are in view
                    if (toggleRect.y < yPositionDrawRange.x || toggleRect.y > yPositionDrawRange.y)
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }

                bool newState;
                if (m_LabelCount == null)
                {
                    count = m_Entries[0].labels.Contains(labelName) ? m_Entries.Count : 0;
                }
                else
                {
                    m_LabelCount.TryGetValue(labelName, out count);
                }

                bool oldState = count == m_Entries.Count;
                if (!(count == 0 || count == m_Entries.Count))
                {
                    EditorGUI.showMixedValue = true;
                }
                UnityEngine.GUI.SetNextControlName(labelName);
                newState = EditorGUI.ToggleLeft(toggleRect, new GUIContent(labelName), oldState);
                EditorGUI.showMixedValue = false;

                if (oldState != newState)
                {
                    SetLabelForEntries(labelName, newState);
                }
            }

            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();

            if (Event.current.type == EventType.Repaint &&
                m_Labels != null && m_ControlToFocus != null)
            {
                UnityEngine.GUI.FocusControl(m_ControlToFocus);
                m_ControlToFocus = null;
            }
        }