Синтаксис:
Используется csharp
for (int i = 0; i < go.renderer.sharedMaterials.Length; ++i)
{
string thePath = AssetDatabase.GetAssetPath(go.renderer.sharedMaterials[i]);
int li = thePath.LastIndexOf("/");
string assetName = thePath.Substring(li+1, thePath.Length-li-1);
string assetPath = thePath.Substring(0, li+1);
//Debug.Log(assetPath);
//string folderGUID = AssetDatabase.AssetPathToGUID(assetPath);
//string guid1 = AssetDatabase.CreateFolder("Assets", "ClonedMaterials");
//AssetDatabase.Refresh();
//assetPath = AssetDatabase.GUIDToAssetPath(guid1);
//Debug.Log(assetPath);
string newPath = assetPath + "clone" + assetName;
//AssetDatabase.CopyAsset(thePath, newPath);
//Debug.Log(newPath);
//Material myNewMat = new Material(go.renderer.sharedMaterials[i]);
AssetDatabase.CopyAsset(thePath, newPath);
//AssetDatabase
//newPath = AssetDatabase.GetAssetPath(myNewMat);
//Debug.Log(newPath);
//AssetDatabase.ImportAsset(newPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
AssetDatabase.ImportAsset(newPath);
AssetDatabase.Refresh();
Material m = (Material)AssetDatabase.LoadAssetAtPath(newPath, typeof(Material));
//m = EditorUtility.InstantiatePrefab(m) as Material;
//m = (Material)Instantiate(m);
go.renderer.sharedMaterials[i] = m;
//Debug.Log(AssetDatabase.GetAssetPath(m));
}
{
string thePath = AssetDatabase.GetAssetPath(go.renderer.sharedMaterials[i]);
int li = thePath.LastIndexOf("/");
string assetName = thePath.Substring(li+1, thePath.Length-li-1);
string assetPath = thePath.Substring(0, li+1);
//Debug.Log(assetPath);
//string folderGUID = AssetDatabase.AssetPathToGUID(assetPath);
//string guid1 = AssetDatabase.CreateFolder("Assets", "ClonedMaterials");
//AssetDatabase.Refresh();
//assetPath = AssetDatabase.GUIDToAssetPath(guid1);
//Debug.Log(assetPath);
string newPath = assetPath + "clone" + assetName;
//AssetDatabase.CopyAsset(thePath, newPath);
//Debug.Log(newPath);
//Material myNewMat = new Material(go.renderer.sharedMaterials[i]);
AssetDatabase.CopyAsset(thePath, newPath);
//AssetDatabase
//newPath = AssetDatabase.GetAssetPath(myNewMat);
//Debug.Log(newPath);
//AssetDatabase.ImportAsset(newPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
AssetDatabase.ImportAsset(newPath);
AssetDatabase.Refresh();
Material m = (Material)AssetDatabase.LoadAssetAtPath(newPath, typeof(Material));
//m = EditorUtility.InstantiatePrefab(m) as Material;
//m = (Material)Instantiate(m);
go.renderer.sharedMaterials[i] = m;
//Debug.Log(AssetDatabase.GetAssetPath(m));
}