/// <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); }