示例#1
0
        #pragma warning disable CA1801 // CA1801 Review unused parameters
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            // TODO: Handle deleted assets. We should use the asset guid to determine the asset type and what we need to do if anything.
            foreach (var assetPath in deletedAssets)
            {
                if (assetPath.EndsWith("asset"))
                {
                    LocalizationEditorSettings.Instance.TableCollectionCache.Clear();
                    break;
                }
            }

            foreach (var assetPath in importedAssets)
            {
                if (assetPath.EndsWith("asset"))
                {
                    var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                    if (typeof(LocalizationTableCollection).IsAssignableFrom(assetType))
                    {
                        var collection = AssetDatabase.LoadAssetAtPath <LocalizationTableCollection>(assetPath);
                        collection.ImportCollectionIntoProject();
                    }
                    else if (typeof(SharedTableData).IsAssignableFrom(assetType))
                    {
                        var sharedTableData = AssetDatabase.LoadAssetAtPath <SharedTableData>(assetPath);
                        if (sharedTableData != null)
                        {
                            Debug.Assert(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sharedTableData, out string sharedTableDataGuid, out long _), "Failed to extract SharedTableData Guid", sharedTableData);
                            var guid = Guid.Parse(sharedTableDataGuid);

                            if (sharedTableData.TableCollectionNameGuid != Guid.Empty)
                            {
                                Debug.Assert(sharedTableData.TableCollectionNameGuid == guid, "SharedTableData Name Guid does not match the assets Guid. This may cause issues matching the correct TableCollectionName.", sharedTableData);
                            }
                            else
                            {
                                sharedTableData.TableCollectionNameGuid = guid;
                            }
                        }
                    }
                    else if (typeof(Locale).IsAssignableFrom(assetType))
                    {
                        var locale = AssetDatabase.LoadAssetAtPath <Locale>(assetPath);
                        Debug.Assert(locale != null, "Failed to load Locale asset.");
                        LocalizationEditorSettings.AddLocale(locale, false);
                    }
                }
            }
        }
        #pragma warning disable CA1801 // CA1801 Review unused parameters
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            // TODO: Handle deleted assets. We should use the asset guid to determine the asset type and what we need to do if anything.
            foreach (var assetPath in deletedAssets)
            {
                if (assetPath.EndsWith("asset"))
                {
                    LocalizationEditorSettings.Instance.TableCollectionCache.Clear();
                    break;
                }
            }

            foreach (var assetPath in importedAssets)
            {
                if (assetPath.EndsWith("asset"))
                {
                    var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                    if (typeof(LocalizationTableCollection).IsAssignableFrom(assetType))
                    {
                        var collection = AssetDatabase.LoadAssetAtPath <LocalizationTableCollection>(assetPath);
                        collection.ImportCollectionIntoProject();
                    }
                    else if (typeof(SharedTableData).IsAssignableFrom(assetType))
                    {
                        var sharedTableData = AssetDatabase.LoadAssetAtPath <SharedTableData>(assetPath);
                        if (sharedTableData != null)
                        {
                            Debug.Assert(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sharedTableData, out string sharedTableDataGuid, out long _), "Failed to extract SharedTableData Guid", sharedTableData);
                            var guid = Guid.Parse(sharedTableDataGuid);

                            if (sharedTableData.TableCollectionNameGuid != Guid.Empty)
                            {
                                Debug.Assert(sharedTableData.TableCollectionNameGuid == guid, "SharedTableData Name Guid does not match the assets Guid. This may cause issues matching the correct TableCollectionName.", sharedTableData);
                            }
                            else
                            {
                                sharedTableData.TableCollectionNameGuid = guid;
                            }

                            // If the collection asset was deleted and then restored we may have a collection using an invalid handle (LOC-182)
                            var collection = LocalizationEditorSettings.GetCollectionForSharedTableData(sharedTableData);
                            if (collection != null)
                            {
                                bool modified = false;
                                if (collection.SharedData == null)
                                {
                                    modified = true;
                                    collection.SharedData = sharedTableData;
                                }

                                foreach (var tableReference in collection.Tables)
                                {
                                    if (tableReference.asset == null && tableReference.asset.SharedData != null)
                                    {
                                        continue;
                                    }

                                    modified = true;
                                    tableReference.asset.SharedData = sharedTableData;
                                }

                                if (modified)
                                {
                                    LocalizationEditorSettings.EditorEvents.RaiseCollectionModified(null, collection);
                                }
                            }
                        }
                    }
                    else if (typeof(Locale).IsAssignableFrom(assetType))
                    {
                        var locale = AssetDatabase.LoadAssetAtPath <Locale>(assetPath);
                        Debug.Assert(locale != null, "Failed to load Locale asset.");
                        LocalizationEditorSettings.AddLocale(locale, false);
                    }
                }
            }
        }
示例#3
0
        #pragma warning disable CA1801 // CA1801 Review unused parameters
        static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
        {
            // We need to disable Addresables settings creation here.
            // When doing a full project import, there is no guarantee of OnPostprocessAllAssets order
            // and the Addressables may be called after Localization which would cause assets to be
            // re-added to groups that become invalid and a general corruption of Addressables data.
            LocalizationEditorSettings.EnableAddressablesCreation = false;

            try
            {
                // TODO: Handle deleted assets. We should use the asset guid to determine the asset type and what we need to do if anything.
                foreach (var assetPath in deletedAssets)
                {
                    if (assetPath.EndsWith("asset"))
                    {
                        LocalizationEditorSettings.Instance.TableCollectionCache.Clear();
                        break;
                    }
                }

                foreach (var assetPath in importedAssets)
                {
                    if (assetPath.EndsWith("asset"))
                    {
                        var assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
                        if (typeof(LocalizedTableCollection).IsAssignableFrom(assetType))
                        {
                            var collection = AssetDatabase.LoadAssetAtPath <LocalizedTableCollection>(assetPath);
                            collection.ImportCollectionIntoProject();
                        }
                        else if (typeof(SharedTableData).IsAssignableFrom(assetType))
                        {
                            var sharedTableData = AssetDatabase.LoadAssetAtPath <SharedTableData>(assetPath);
                            if (sharedTableData != null)
                            {
                                Debug.Assert(AssetDatabase.TryGetGUIDAndLocalFileIdentifier(sharedTableData, out string sharedTableDataGuid, out long _), "Failed to extract SharedTableData Guid", sharedTableData);
                                var guid = Guid.Parse(sharedTableDataGuid);

                                if (sharedTableData.TableCollectionNameGuid != Guid.Empty)
                                {
                                    Debug.Assert(sharedTableData.TableCollectionNameGuid == guid, "SharedTableData Name Guid does not match the assets Guid. This may cause issues matching the correct TableCollectionName.", sharedTableData);
                                }
                                else
                                {
                                    sharedTableData.TableCollectionNameGuid = guid;
                                }
                            }
                        }
                        else if (typeof(Locale).IsAssignableFrom(assetType))
                        {
                            var locale = AssetDatabase.LoadAssetAtPath <Locale>(assetPath);
                            Debug.Assert(locale != null, "Failed to load Locale asset.");
                            LocalizationEditorSettings.AddLocale(locale, false);
                        }
                    }
                }
            }
            finally
            {
                LocalizationEditorSettings.EnableAddressablesCreation = true;
            }
        }