/// <summary> /// Add an asset to in the data directory. /// </summary> /// <param name="asset">Asset to add.</param> /// <param name="type">Asset type.</param> public void AddAssetToDataDirectory(UnityEngine.Object asset, AGXUnity.IO.AssetType type) { if (asset == null) { Debug.LogWarning("Trying to add null asset to file: " + NameWithExtension); return; } // Grouping assets given known types - unknown types are written directly to the data folder. if (type == AGXUnity.IO.AssetType.Unknown) { AssetDatabase.CreateAsset(asset, GetAssetPath(asset)); return; } if (m_assetRoots[(int)type] != null) { AssetDatabase.AddObjectToAsset(asset, m_assetRoots[(int)type]); } else { m_assetRoots[(int)type] = asset; AssetDatabase.CreateAsset(asset, GetAssetPath(asset)); } }
private T AddOrReplaceAsset <T>(T asset, Node node, AGXUnity.IO.AssetType type) where T : UnityEngine.Object { var existingAsset = AssetDatabase.LoadAssetAtPath <T>(FileInfo.GetAssetPath(asset)); if (existingAsset == null) { FileInfo.AddAssetToDataDirectory(asset, type); existingAsset = asset; } else { EditorUtility.CopySerialized(asset, existingAsset); } return(existingAsset); }
/// <summary> /// Add an asset to the data directory or updates an existing asset /// of same type and name with the current values of <paramref name="asset"/>. /// Known assets types will be grouped together and AGXFileInfo.GetAssets /// has to be used to find them. /// /// Type AssetType.Unknown will always create a new asset. /// </summary> /// <param name="asset">Asset to add.</param> /// <param name="type">Asset type.</param> /// <returns><paramref name="asset"/> if previous version doesn't exist - otherwise the already existing asset.</returns> public T AddOrUpdateExistingAsset <T>(T asset, AGXUnity.IO.AssetType type) where T : UnityEngine.Object { if (asset == null) { Debug.LogWarning("Trying to add null asset to file: " + NameWithExtension); return(null); } // Grouping assets given known types - unknown types are written directly to the data folder. if (type == AGXUnity.IO.AssetType.Unknown) { AssetDatabase.CreateAsset(asset, GetAssetPath(asset)); return(asset); } T[] assets = GetAssets <T>(); foreach (var existing in assets) { if (existing.name == asset.name) { EditorUtility.CopySerialized(asset, existing); return(existing); } } if (assets.Length == 0) { AssetDatabase.CreateAsset(asset, GetAssetPath(asset)); } else { AssetDatabase.AddObjectToAsset(asset, AssetDatabase.GetAssetPath(assets[0])); } return(asset); }