Exemple #1
0
        private bool AddAsset(string assetName, LoadedAsset la)
        {
            if (IsAssetLoaded(assetName))
            {
                return(false);
            }
            else if (la.Obj == null || la.T == null)
            {
                return(false);
            }
            else
            {
                if (la.T == typeof(GameObject) && assetBundle.Contains(ImportedComponentAttribute.MakeFileName(assetName)))
                {
                    ImportedComponentAttribute.Restore(this, la.Obj as GameObject);
                }

                loadedAssets.Add(assetName, la);

                if (this.modInfo != null && string.IsNullOrEmpty(this.Title) == false)
                {
                    ModManager.OnLoadAsset(this.Title, assetName, la.T);
                }
#if DEBUG
                Debug.Log(string.Format("added asset: {0}", assetName));
#endif
                return(true);
            }
        }
        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);
        }
Exemple #3
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);
            }
        }