public void UpdateAsset <T>(T oldAsset, T newAsset) where T : Object { #if UNITY_EDITOR if (EditorApplication.isPlaying) //Don't make any data changes while the editor is in play mode { return; } if (newAsset == null) //If you are un-assigning an asset, don't make changes to the asset list { return; } string oldPath; string newPath = AssetDatabase.GetAssetPath(newAsset); if (serializedAssets.ContainsAsset(newAsset)) //If the new asset already exists, update its path { if (!serializedAssets.ContainsPath(newPath)) //As long as the new path doesn't already exist { serializedAssets.UpdatePath(serializedAssets[oldAsset], newPath); } return; } if (oldAsset == newAsset && serializedAssets.ContainsAsset(oldAsset)) //If the assets are the same, update both the asset and path { oldPath = serializedAssets.UpdateAsset(oldAsset, newAsset); serializedAssets.UpdatePath(oldPath, newPath); return; } serializedAssets.Add(newPath, newAsset); //Add the new asset entry #endif }
public void RegenerateProjectAssets(SerializedAssetDatabaseBlacklist blacklist = null) { #if UNITY_EDITOR if (blacklist == null) { blacklist = SerializedAssetDatabaseBlacklist.Default; } serializedAssets = new SerializedAssetDictionary(); foreach (string file in GetAssetFiles(@"Assets/", blacklist)) { serializedAssets.Add(file, AssetDatabase.LoadAssetAtPath(file, typeof(Object))); } #endif }