コード例 #1
0
 //Attempts to load each catalog in order, stopping at first success.
 void LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap)
 {
     Addressables.LogFormat("Addressables - loading content catalog from {0}.", catalogs[index].InternalId);
     LoadContentCatalog(catalogs[index], m_ProviderSuffix).Completed += op =>
     {
         if (op.Result != null)
         {
             m_Addressables.RemoveResourceLocator(locMap);
             Result = op.Result;
             Complete(Result, true, string.Empty);
             m_Addressables.Release(op);
             Addressables.Log("Addressables - initialization complete.");
         }
         else
         {
             Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
             if (index + 1 >= catalogs.Count)
             {
                 Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                 m_Addressables.RemoveResourceLocator(locMap);
                 Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
                 m_Addressables.Release(op);
             }
             else
             {
                 LoadContentCatalogInternal(catalogs, index + 1, locMap);
                 m_Addressables.Release(op);
             }
         }
     };
 }
        internal bool LogRuntimeWarnings(string pathToBuildLogs)
        {
            if (!File.Exists(pathToBuildLogs))
            {
                return(false);
            }

            PackedPlayModeBuildLogs runtimeBuildLogs = JsonUtility.FromJson <PackedPlayModeBuildLogs>(File.ReadAllText(pathToBuildLogs));
            bool messageLogged = false;

            foreach (var log in runtimeBuildLogs.RuntimeBuildLogs)
            {
                messageLogged = true;
                switch (log.Type)
                {
                case LogType.Warning:
                    Addressables.LogWarning(log.Message);
                    break;

                case LogType.Error:
                    Addressables.LogError(log.Message);
                    break;

                case LogType.Log:
                    Addressables.Log(log.Message);
                    break;
                }
            }

            return(messageLogged);
        }
コード例 #3
0
 void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index)
 {
     if (op.Result != null)
     {
         m_Addressables.RemoveResourceLocator(locMap);
         Result = op.Result;
         Complete(Result, true, string.Empty);
         m_Addressables.Release(op);
         Addressables.Log("Addressables - initialization complete.");
     }
     else
     {
         Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
         if (index + 1 >= catalogs.Count)
         {
             Addressables.LogWarningFormat("Addressables - initialization failed.", op);
             m_Addressables.RemoveResourceLocator(locMap);
             Complete(Result, false, op.OperationException != null ? op.OperationException.Message : "LoadContentCatalogInternal");
             m_Addressables.Release(op);
         }
         else
         {
             m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap);
             m_Addressables.Release(op);
         }
     }
 }
        void CreateOrEditGradleFile(string androidPackDir, string assetPackName, DeliveryType deliveryType)
        {
            if (deliveryType == DeliveryType.None)
            {
                Addressables.Log($"Asset pack '{assetPackName}' has its delivery type set to 'None'. " +
                                 $"No gradle file will be created for this asset pack. Unity assumes that any custom asset packs with no gradle file use on-demand delivery.");
                return;
            }

            // Warn about other gradle files in the .androidpack directory
            List <string> gradleFiles = Directory.EnumerateFiles(androidPackDir, "*.gradle").Where(x => Path.GetFileName(x) != "build.gradle").ToList();

            if (gradleFiles.Count > 0)
            {
                Addressables.LogWarning($"Custom asset pack at '{androidPackDir}' contains {gradleFiles.Count} files with .gradle extension which will be ignored. " +
                                        $"Only the 'build.gradle' file will be included in the Android App Bundle.");
            }

            // Create or edit the 'build.gradle' file in the .androidpack directory
            string deliveryTypeString = CustomAssetPackUtility.DeliveryTypeToGradleString(deliveryType);
            string buildFilePath      = Path.Combine(androidPackDir, "build.gradle");
            string content            = $"apply plugin: 'com.android.asset-pack'\n\nassetPack {{\n\tpackName = \"{assetPackName}\"\n\tdynamicDelivery {{\n\t\tdeliveryType = \"{deliveryTypeString}\"\n\t}}\n}}";

            File.WriteAllText(buildFilePath, content);
        }
        bool HasRequiredSchemas(AddressableAssetSettings settings, AddressableAssetGroup group)
        {
            bool hasBundledSchema = group.HasSchema <BundledAssetGroupSchema>();
            bool hasPADSchema     = group.HasSchema <PlayAssetDeliverySchema>();

            if (!hasBundledSchema && !hasPADSchema)
            {
                return(false);
            }
            if (!hasBundledSchema && hasPADSchema)
            {
                Addressables.LogWarning($"Group '{group.name}' has a '{typeof(PlayAssetDeliverySchema).Name}' but not a '{typeof(BundledAssetGroupSchema).Name}'. " +
                                        $"It does not contain any bundled content to be assigned to an asset pack.");
                return(false);
            }
            if (hasBundledSchema && !hasPADSchema)
            {
                var    bundledSchema = group.GetSchema <BundledAssetGroupSchema>();
                string buildPath     = bundledSchema.BuildPath.GetValue(settings);
                if (BuildPathIncludedInStreamingAssets(buildPath))
                {
                    Addressables.Log($"Group '{group.name}' does not have a '{typeof(PlayAssetDeliverySchema).Name}' but its build path '{buildPath}' will be included in StreamingAssets at build time. " +
                                     $"The group will be assigned to the generated asset packs unless its build path is changed.");
                }
                return(false);
            }
            return(true);
        }
コード例 #6
0
    public static void DisabledImporterBuild()
    {
        try
        {
            string buildPath = $"DisabledImporterBuildPath/{EditorUserBuildSettings.activeBuildTarget}/";
            Directory.CreateDirectory(buildPath);

            AssetDatabase.StopAssetEditing();
            BuildPlayerOptions options = new BuildPlayerOptions()
            {
                target           = EditorUserBuildSettings.activeBuildTarget,
                scenes           = EditorBuildSettings.scenes.Select(s => s.path).ToArray(),
                options          = BuildOptions.None,
                locationPathName = $"{buildPath}/build{GetExtension()}"
            };

            BuildReport report = BuildPipeline.BuildPlayer(options);

            Addressables.Log(report.summary.ToString());
        }
        finally
        {
            AssetDatabase.StartAssetEditing();
        }
    }
コード例 #7
0
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
コード例 #8
0
        internal static void PurgeInvalidAssetEntries(AddressableAssetSettings settings)
        {
            if (settings == null)
            {
                return;
            }
            List <AddressableAssetEntry> entriesToRemove = new List <AddressableAssetEntry>();

            foreach (var group in settings.groups)
            {
                if (group == null)
                {
                    continue;
                }

                foreach (var assetEntry in group.entries)
                {
                    if (assetEntry == null ||
                        assetEntry.address == AddressableAssetEntry.EditorSceneListName ||
                        assetEntry.address == AddressableAssetEntry.ResourcesName)
                    {
                        continue;
                    }

                    if (!string.IsNullOrEmpty(assetEntry.AssetPath))
                    {
                        string path = Path.GetFullPath(assetEntry.AssetPath);
                        if (!File.Exists(path) && !Directory.Exists(path))
                        {
                            entriesToRemove.Add(assetEntry);
                        }
                    }
                    else
                    {
                        entriesToRemove.Add(assetEntry);
                    }
                }
            }

            StringBuilder builder = new StringBuilder(
                "Addressables was unable to detect the following assets in the project " +
                "but they were still part of an Addressable group.  They have been removed " +
                "from Addressables.");

            foreach (var entry in entriesToRemove)
            {
                builder.AppendLine($"\n{entry.address} at {entry.AssetPath}");
                settings.RemoveAssetEntry(entry, false);
            }

            if (entriesToRemove.Count > 0)
            {
                Addressables.Log(builder.ToString());
            }
        }
コード例 #9
0
        //Attempts to load each catalog in order, stopping at first success.
        internal AsyncOperationHandle <IResourceLocator> LoadContentCatalogInternal(IList <IResourceLocation> catalogs, int index, ResourceLocationMap locMap, IResourceLocation remoteHashLocation)
        {
            Addressables.LogFormat("Addressables - loading content catalog from {0}.", m_Addressables.ResourceManager.TransformInternalId(catalogs[index]));
            var loadOp = LoadContentCatalog(catalogs[index], m_ProviderSuffix, remoteHashLocation);

            if (loadOp.IsDone)
            {
                LoadOpComplete(loadOp, catalogs, locMap, index, remoteHashLocation);
            }
            else
            {
                loadOp.Completed += op =>
                {
                    LoadOpComplete(op, catalogs, locMap, index, remoteHashLocation);
                }
            };
            return(loadOp);
        }

        void LoadOpComplete(AsyncOperationHandle <IResourceLocator> op, IList <IResourceLocation> catalogs, ResourceLocationMap locMap, int index, IResourceLocation remoteHashLocation)
        {
            if (op.Result != null)
            {
                m_Addressables.RemoveResourceLocator(locMap);
                Result = op.Result;
                Complete(Result, true, string.Empty);
                m_Addressables.Release(op);
                Addressables.Log("Addressables - initialization complete.");
            }
            else
            {
                Addressables.LogFormat("Addressables - failed to load content catalog from {0}.", op);
                if (index + 1 >= catalogs.Count)
                {
                    Addressables.LogWarningFormat("Addressables - initialization failed.", op);
                    m_Addressables.RemoveResourceLocator(locMap);
                    if (op.OperationException != null)
                    {
                        Complete(Result, false, op.OperationException);
                    }
                    else
                    {
                        Complete(Result, false, "LoadContentCatalogInternal");
                    }
                    m_Addressables.Release(op);
                }
                else
                {
                    m_loadCatalogOp = LoadContentCatalogInternal(catalogs, index + 1, locMap, remoteHashLocation);
                    m_Addressables.Release(op);
                }
            }
        }
    }
コード例 #10
0
        public bool OnGUI(Rect pos)
        {
            GUILayout.BeginArea(pos);
            m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition, false, false, GUILayout.MaxWidth(pos.width));

            GUILayout.Space(20);
            GUILayout.Label("     NOT YET FUNCTIONAL    ");
            GUILayout.Space(10);

            m_FullBuildFoldout = EditorGUILayout.Foldout(m_FullBuildFoldout, "Full Build");
            if (m_FullBuildFoldout)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.HelpBox(new GUIContent("This section will create a rebuild of all content packs as well as the core player build.  A snapshot of this build must be saved in order to do updates to it later."));
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Build and Save Snapshot"))
                {
                    Addressables.Log("we aren't actually building yet.");
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }

            GUILayout.Space(20);

            m_UpdateFoldout = EditorGUILayout.Foldout(m_UpdateFoldout, "Update Build");
            if (m_UpdateFoldout)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.HelpBox(new GUIContent("This section will not create a core player build, and it will only create the new bundles needed when compared to a given snapshot."));
                GUILayout.BeginHorizontal();
                m_SnapshotPath = EditorGUILayout.TextField(new GUIContent("Reference Snapshot"), m_SnapshotPath);
                GUILayout.Space(10);
                if (GUILayout.Button("Browse"))
                {
                    Addressables.Log("we aren't actually browsing yet.");
                }
                GUILayout.EndHorizontal();
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Create Updated Packs"))
                {
                    Addressables.Log("we aren't actually updating yet.");
                }
                GUILayout.EndHorizontal();
                EditorGUI.indentLevel--;
            }


            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();
            return(false);
        }
コード例 #11
0
        /// <summary>
        /// Updates the CCD buckets and badges with the data source settings
        /// </summary>
        /// <param name="projectId">Project Id connected to Unity Services</param>
        /// <param name="showInfoLog">Whether or not to show debug logs or not</param>
        /// <returns>List of ProfileGroupType</returns>
        public static async Task <List <ProfileGroupType> > UpdateCCDDataSourcesAsync(string projectId, bool showInfoLog)
        {
            if (showInfoLog)
            {
                Addressables.Log("Syncing CCD Buckets and Badges.");
            }
            var settings          = GetSettings();
            var profileGroupTypes = new List <ProfileGroupType>();

            profileGroupTypes.AddRange(CreateDefaultGroupTypes());

            await CCDManagementAPIService.SetConfigurationAuthHeader(CloudProjectSettings.accessToken);

            var bucketDictionary = await GetAllBucketsAsync(projectId);

            foreach (var kvp in bucketDictionary)
            {
                var bucket = kvp.Value;
                var badges = await GetAllBadgesAsync(projectId, bucket.Id.ToString());

                if (badges.Count == 0)
                {
                    badges.Add(new CcdBadge(name: "latest"));
                }
                foreach (var badge in badges)
                {
                    var groupType = new ProfileGroupType($"CCD{ProfileGroupType.k_PrefixSeparator}{projectId}{ProfileGroupType.k_PrefixSeparator}{bucket.Id}{ProfileGroupType.k_PrefixSeparator}{badge.Name}");
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Name)}", bucket.Name));
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBucket)}{nameof(CcdBucket.Id)}", bucket.Id.ToString()));
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable($"{nameof(CcdBadge)}{nameof(CcdBadge.Name)}", badge.Name));
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(nameof(CcdBucket.Attributes.PromoteOnly), bucket.Attributes.PromoteOnly.ToString()));

                    string buildPath = $"{AddressableAssetSettings.kCCDBuildDataPath}/{bucket.Id}/{badge.Name}";
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kBuildPath, buildPath));

                    string loadPath = $"https://{projectId}.client-api.unity3dusercontent.com/client_api/v1/buckets/{bucket.Id}/release_by_badge/{badge.Name}/entry_by_path/content/?path=";
                    groupType.AddVariable(new ProfileGroupType.GroupTypeVariable(AddressableAssetSettings.kLoadPath, loadPath));

                    profileGroupTypes.Add(groupType);
                }
            }
            settings.profileGroupTypes = profileGroupTypes;
            if (showInfoLog)
            {
                Addressables.Log("Successfully synced CCD Buckets and Badges.");
            }
            EditorUtility.SetDirty(settings);
            AddressableAssetUtility.OpenAssetIfUsingVCIntegration(settings);
            return(settings.profileGroupTypes);
        }
コード例 #12
0
 internal void ResetEntryMap()
 {
     m_EntryMap.Clear();
     foreach (var e in m_SerializeEntries)
     {
         try
         {
             e.parentGroup = this;
             e.IsSubAsset  = false;
             m_EntryMap.Add(e.guid, e);
         }
         catch (Exception ex)
         {
             Addressables.Log(e.address);
             Debug.LogException(ex);
         }
     }
 }
コード例 #13
0
            public void Update(float unscaledDeltaTime)
            {
#if ENABLE_CACHING
                if (Caching.ready && m_UpdateRequired)
                {
                    m_UpdateRequired = false;

                    if (m_Callback != null)
                    {
                        Complete(m_Callback(), true, "");
                    }
                    else
                    {
                        Complete(true, true, "");
                    }

                    Addressables.Log("CacheInitialization Complete");
                }
#else
                Complete(true, true, "");
                Addressables.Log("UnityEngine.Caching not supported on this platform but a CacheInitialization object has been found in AddressableAssetSettings. No action has been taken.");
#endif
            }
コード例 #14
0
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(m_Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            var rtd = m_rtdOp.Result;

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressable Assets window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
            }

            //   DiagnosticEventCollector.ResourceManagerProfilerEventsEnabled = rtd.ProfileEvents;
            Addressables.Log("Addressables - loading initialization objects.");
            foreach (var i in rtd.InitializationObjects)
            {
                if (i.ObjectType.Value == null)
                {
                    Addressables.LogFormat("Invalid initialization object type {0}.", i.ObjectType);
                    continue;
                }
                try
                {
                    var o = i.CreateInstance <object>();
                    Addressables.LogFormat("Initialization object {0} created instance {1}.", i, o);
                }
                catch (Exception ex)
                {
                    Addressables.LogErrorFormat("Exception thrown during initialization of object {0}: {1}", i, ex.ToString());
                }
            }

            var locMap = new ResourceLocationMap(rtd.CatalogLocations);
            m_Addressables.ResourceLocators.Add(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat("Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.ResourceLocators.Remove(locMap);
                Complete(m_Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                LoadContentCatalogInternal(catalogs, 0, locMap);
            }
        }
コード例 #15
0
        protected override void Execute()
        {
            Addressables.LogFormat("Addressables - runtime data operation completed with status = {0}, result = {1}.", m_rtdOp.Status, m_rtdOp.Result);
            if (m_rtdOp.Result == null)
            {
                Addressables.LogWarningFormat("Addressables - Unable to load runtime data at location {0}.", m_rtdOp);
                Complete(Result, false, string.Format("Addressables - Unable to load runtime data at location {0}.", m_rtdOp));
                return;
            }
            Addressables.LogFormat("Initializing Addressables version {0}.", m_rtdOp.Result.AddressablesVersion);
            var rtd = m_rtdOp.Result;

            m_Addressables.ResourceManager.postProfilerEvents = rtd.ProfileEvents;
            WebRequestQueue.SetMaxConcurrentRequests(rtd.MaxConcurrentWebRequests);
            m_Addressables.CatalogRequestsTimeout = rtd.CatalogRequestsTimeout;
            foreach (var catalogLocation in rtd.CatalogLocations)
            {
                if (catalogLocation.Data != null && catalogLocation.Data is ProviderLoadRequestOptions loadData)
                {
                    loadData.WebRequestTimeout = rtd.CatalogRequestsTimeout;
                }
            }

            m_Addressables.Release(m_rtdOp);
            if (rtd.CertificateHandlerType != null)
            {
                m_Addressables.ResourceManager.CertificateHandlerInstance = Activator.CreateInstance(rtd.CertificateHandlerType) as CertificateHandler;
            }

#if UNITY_EDITOR
            if (UnityEditor.EditorUserBuildSettings.activeBuildTarget.ToString() != rtd.BuildTarget)
            {
                Addressables.LogErrorFormat("Addressables - runtime data was built with a different build target.  Expected {0}, but data was built with {1}.  Certain assets may not load correctly including shaders.  You can rebuild player content via the Addressables window.", UnityEditor.EditorUserBuildSettings.activeBuildTarget, rtd.BuildTarget);
            }
#endif
            if (!rtd.LogResourceManagerExceptions)
            {
                ResourceManager.ExceptionHandler = null;
            }

            if (!rtd.ProfileEvents)
            {
                m_Diagnostics.Dispose();
                m_Diagnostics = null;
                m_Addressables.ResourceManager.ClearDiagnosticCallbacks();
            }

            Addressables.Log("Addressables - loading initialization objects.");

            ContentCatalogProvider ccp = m_Addressables.ResourceManager.ResourceProviders
                                         .FirstOrDefault(rp => rp.GetType() == typeof(ContentCatalogProvider)) as ContentCatalogProvider;
            if (ccp != null)
            {
                ccp.DisableCatalogUpdateOnStart = rtd.DisableCatalogUpdateOnStartup;
                ccp.IsLocalCatalogInBundle      = rtd.IsLocalCatalogInBundle;
            }

            var locMap = new ResourceLocationMap("CatalogLocator", rtd.CatalogLocations);
            m_Addressables.AddResourceLocator(locMap);
            IList <IResourceLocation> catalogs;
            if (!locMap.Locate(ResourceManagerRuntimeData.kCatalogAddress, typeof(ContentCatalogData), out catalogs))
            {
                Addressables.LogWarningFormat(
                    "Addressables - Unable to find any catalog locations in the runtime data.");
                m_Addressables.RemoveResourceLocator(locMap);
                Complete(Result, false, "Addressables - Unable to find any catalog locations in the runtime data.");
            }
            else
            {
                Addressables.LogFormat("Addressables - loading content catalogs, {0} found.", catalogs.Count);
                IResourceLocation remoteHashLocation = null;
                if (catalogs[0].Dependencies.Count == 2 && rtd.DisableCatalogUpdateOnStartup)
                {
                    remoteHashLocation = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote];
                    catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = catalogs[0].Dependencies[(int)ContentCatalogProvider.DependencyHashIndex.Cache];
                }
                m_loadCatalogOp = LoadContentCatalogInternal(catalogs, 0, locMap, remoteHashLocation);
            }
        }
コード例 #16
0
        internal static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            var  aa       = AddressableAssetSettingsDefaultObject.Settings;
            bool modified = false;

            foreach (string str in importedAssets)
            {
                var assetType = AssetDatabase.GetMainAssetTypeAtPath(str);

                if (typeof(AddressableAssetGroup).IsAssignableFrom(assetType))
                {
                    AddressableAssetGroup group = aa.FindGroup(Path.GetFileNameWithoutExtension(str));
                    if (group == null)
                    {
                        var foundGroup = AssetDatabase.LoadAssetAtPath <AddressableAssetGroup>(str);
                        if (!aa.groups.Contains(foundGroup))
                        {
                            aa.groups.Add(foundGroup);
                            group    = aa.FindGroup(Path.GetFileNameWithoutExtension(str));
                            modified = true;
                        }
                    }
                    if (group != null)
                    {
                        group.DedupeEnteries();
                    }
                }

                if (typeof(AddressableAssetEntryCollection).IsAssignableFrom(assetType))
                {
                    aa.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(str), aa.DefaultGroup);
                    modified = true;
                }

                var guid = AssetDatabase.AssetPathToGUID(str);
                if (aa.FindAssetEntry(guid) != null)
                {
                    modified = true;
                }

                if (AddressableAssetUtility.IsInResources(str))
                {
                    modified = true;
                }
            }

            if (deletedAssets.Length > 0)
            {
                // if any directly referenced assets were deleted while Unity was closed, the path isn't useful, so Remove(null) is our only option
                //  this can lead to orphaned schema files.
                if (aa.groups.Remove(null) ||
                    aa.DataBuilders.Remove(null) ||
                    aa.GroupTemplateObjects.Remove(null) ||
                    aa.InitializationObjects.Remove(null))
                {
                    modified = true;
                }
            }

            foreach (string str in deletedAssets)
            {
                if (AddressableAssetUtility.IsInResources(str))
                {
                    modified = true;
                }
                else
                {
                    if (aa.CheckForGroupDataDeletion(str))
                    {
                        modified = true;
                        continue;
                    }

                    // アセットが削除された時にグループを更新しない
                    //var guidOfDeletedAsset = AssetDatabase.AssetPathToGUID(str);
                    //if (aa.RemoveAssetEntry(guidOfDeletedAsset))
                    //{
                    //    modified = true;
                    //}
                }
            }
            for (int i = 0; i < movedAssets.Length; i++)
            {
                var str       = movedAssets[i];
                var assetType = AssetDatabase.GetMainAssetTypeAtPath(str);
                if (typeof(AddressableAssetGroup).IsAssignableFrom(assetType))
                {
                    var oldGroupName = Path.GetFileNameWithoutExtension(movedFromAssetPaths[i]);
                    var group        = aa.FindGroup(oldGroupName);
                    if (group != null)
                    {
                        var newGroupName = Path.GetFileNameWithoutExtension(str);
                        group.Name = newGroupName;
                    }
                }
                else
                {
                    var guid = AssetDatabase.AssetPathToGUID(str);
                    AddressableAssetEntry entry = aa.FindAssetEntry(guid);

                    bool isAlreadyAddressable = entry != null;
                    bool startedInResources   = AddressableAssetUtility.IsInResources(movedFromAssetPaths[i]);
                    bool endedInResources     = AddressableAssetUtility.IsInResources(str);
                    bool inEditorSceneList    = BuiltinSceneCache.Contains(new GUID(guid));

                    //update entry cached path
                    entry?.SetCachedPath(str);

                    //move to Resources
                    if (isAlreadyAddressable && endedInResources)
                    {
                        var fileName = Path.GetFileNameWithoutExtension(str);
                        Addressables.Log("You have moved addressable asset " + fileName + " into a Resources directory.  It has been unmarked as addressable, but can still be loaded via the Addressables API via its Resources path.");
                        aa.RemoveAssetEntry(guid, false);
                    }
                    else if (inEditorSceneList)
                    {
                        BuiltinSceneCache.ClearState();
                    }

                    //any addressables move or resources move (even resources to within resources) needs to refresh the UI.
                    modified = isAlreadyAddressable || startedInResources || endedInResources || inEditorSceneList;
                }
            }

            if (modified)
            {
                aa.SetDirty(AddressableAssetSettings.ModificationEvent.BatchModification, null, true, true);
            }
        }