private string CheckForImportedComponents(string prefabPath)
        {
            var    go = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject)) as GameObject;
            string importedComponentsPath = ImportedComponentAttribute.Save(go, GetTempModDirPath(modInfo.ModTitle));

            if (importedComponentsPath != null)
            {
                importedComponentsPath = GetAssetPathFromFilePath(importedComponentsPath);
                AddAssetToMod(importedComponentsPath);
                AssetDatabase.Refresh();
                return(importedComponentsPath);
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if a prefab has custom components that need to be deserialized by mod manager.
        /// Custom components are removed and edited prefab is saved to a temp location.
        /// </summary>
        /// <param name="prefabPath">Asset path of original prefab.</param>
        /// <returns>Paths of prefab copy and json data; null if not copied./returns>
        private (string prefabPath, string dataPath)? CheckForImportedComponents(string prefabPath)
        {
            var go = PrefabUtility.LoadPrefabContents(prefabPath);

            try
            {
                string tempModPath            = GetTempModDirPath(modInfo.ModTitle);
                string importedComponentsPath = ImportedComponentAttribute.Save(go, tempModPath);
                if (importedComponentsPath != null)
                {
                    string tempPrefabPath = GetAssetPathFromFilePath($"{tempModPath}/{go.name}.prefab");
                    PrefabUtility.SaveAsPrefabAsset(go, tempPrefabPath);
                    string tempDataPath = GetAssetPathFromFilePath(importedComponentsPath);
                    return(tempPrefabPath, tempDataPath);
                }

                return(null);
            }
            finally
            {
                PrefabUtility.UnloadPrefabContents(go);
            }
        }