2021-01-14 00:45:25 +01:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEditor;
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation.Editor
|
|
|
|
{
|
|
|
|
public static class AssetDatabaseUtils
|
|
|
|
{
|
|
|
|
public static bool HasChildAsset(Object parent, Object child)
|
|
|
|
{
|
|
|
|
var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(parent));
|
|
|
|
|
|
|
|
foreach (var a in assets)
|
|
|
|
{
|
|
|
|
if (a == child)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-19 13:59:31 +01:00
|
|
|
public static bool TryAddChildAsset(Object parent, Object child)
|
|
|
|
{
|
|
|
|
if (!HasChildAsset(parent, child))
|
|
|
|
{
|
|
|
|
AssetDatabase.AddObjectToAsset(child, parent);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-01-14 00:45:25 +01:00
|
|
|
public static void RemoveChildAssets(Object parent, Object[] filter = null)
|
|
|
|
{
|
|
|
|
var assets = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(parent));
|
|
|
|
|
|
|
|
foreach (var a in assets)
|
|
|
|
{
|
|
|
|
bool filterSkip = false;
|
|
|
|
|
|
|
|
foreach (var f in filter)
|
|
|
|
{
|
|
|
|
if (a == f)
|
|
|
|
{
|
|
|
|
filterSkip = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filterSkip && a != parent)
|
|
|
|
{
|
|
|
|
AssetDatabase.RemoveObjectFromAsset(a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-01-18 22:59:57 +01:00
|
|
|
|
|
|
|
public static bool HasAsset(string path, System.Type type)
|
|
|
|
{
|
|
|
|
return (AssetDatabase.LoadAssetAtPath(path, type) ? true : false);
|
|
|
|
}
|
2021-01-14 00:45:25 +01:00
|
|
|
}
|
|
|
|
}
|