Esempio n. 1
0
    private static void SetGroupsSetting(AddressableAssetGroup group,
                                         bool UseAssetBundleCache,
                                         bool UseAssetBundleCrc,
                                         BundledAssetGroupSchema.BundleNamingStyle BundleNaming,
                                         string BuildPath,
                                         string LoadPath,
                                         bool StaticContent)
    {
        BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema <BundledAssetGroupSchema>();

        if (bundledAssetGroupSchema == null)
        {
            bundledAssetGroupSchema = group.AddSchema <BundledAssetGroupSchema>();
        }
        //bundledAssetGroupSchema.IncludeInBuild = true;
        bundledAssetGroupSchema.UseAssetBundleCache = UseAssetBundleCache;
        bundledAssetGroupSchema.UseAssetBundleCrc   = UseAssetBundleCrc;
        bundledAssetGroupSchema.BundleNaming        = BundleNaming;
        bundledAssetGroupSchema.BuildPath.SetVariableByName(group.Settings, BuildPath);
        bundledAssetGroupSchema.LoadPath.SetVariableByName(group.Settings, LoadPath);
        bundledAssetGroupSchema.SetAssetBundleProviderType(typeof(AssetBundleEncryptProvider));
        EditorUtility.SetDirty(bundledAssetGroupSchema);


        ContentUpdateGroupSchema contentUpdateGroupSchema = group.GetSchema <ContentUpdateGroupSchema>();

        if (contentUpdateGroupSchema == null)
        {
            contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>();
        }
        contentUpdateGroupSchema.StaticContent = StaticContent;
        EditorUtility.SetDirty(contentUpdateGroupSchema);
    }
Esempio n. 2
0
    AddressableAssetGroup CreateGroup(string groupName)
    {
        string guid = AssetDatabase.FindAssets("t:AddressableAssetSettings").FirstOrDefault();
        string path = AssetDatabase.GUIDToAssetPath(guid);
        AddressableAssetSettings settings = AssetDatabase.LoadAssetAtPath <AddressableAssetSettings>(path);
        BundledAssetGroupSchema  bundledAssetGroupSchema  = ScriptableObject.CreateInstance <BundledAssetGroupSchema>();
        ContentUpdateGroupSchema contentUpdateGroupSchema = ScriptableObject.CreateInstance <ContentUpdateGroupSchema>();
        var schemas = new List <AddressableAssetGroupSchema> {
            bundledAssetGroupSchema, contentUpdateGroupSchema
        };

        return(settings.CreateGroup(groupName, false, false, true, schemas));
    }
Esempio n. 3
0
        /// <summary>
        /// グループを作成する
        /// </summary>
        private static AddressableAssetGroup GetOrCreateGroup(string groupName)
        {
            var settings = Settings;

            // すでにあれば何もしない
            var group = settings.groups.Find(group => group.name == groupName);

            if (group != null)
            {
                return(group);
            }

            var schema = new List <AddressableAssetGroupSchema>()
            {
                BundledAssetGroupSchema.CreateInstance <BundledAssetGroupSchema>(),
                ContentUpdateGroupSchema.CreateInstance <ContentUpdateGroupSchema>()
            };

            return(settings.CreateGroup(groupName, setAsDefaultGroup: false, readOnly: false, postEvent: true, schema));
        }
        private AddressableAssetGroup GetGroup(AddressableAssetSettings settings, string groupName)
        {
            for (int i = 0; i < settings.groups.Count; ++i)
            {
                if (settings.groups[i].Name == groupName)
                {
                    return(settings.groups[i]);
                }
            }

            List <AddressableAssetGroupSchema> schemas = new List <AddressableAssetGroupSchema>();

            ContentUpdateGroupSchema contentUpdateGroupSchema = ScriptableObject.CreateInstance <ContentUpdateGroupSchema>();
            BundledAssetGroupSchema  bundledAssetGroupSchema  = ScriptableObject.CreateInstance <BundledAssetGroupSchema>();

            bundledAssetGroupSchema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;

            schemas.Add(contentUpdateGroupSchema);
            schemas.Add(bundledAssetGroupSchema);

            AddressableAssetGroup group = settings.CreateGroup(groupName, false, false, false, schemas);

            return(group);
        }
Esempio n. 5
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();
    }
        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();
        }