Код: Выделить всё
public class Rename
{
[MenuItem("Assets/Test")]
private static void renameTest()
{
//select a fbx in project window
GameObject fbx = Selection.activeGameObject;
Mesh meshAsset = fbx.GetComponentInChildren().sharedMesh;
meshAsset.name = "new name";
Debug.Log(meshAsset);
}
}
Код: Выделить всё
private static void renameTestv2()
{
GameObject fbx = Selection.activeGameObject;
Mesh meshAsset = fbx.GetComponentInChildren().sharedMesh;
Mesh meshAsset2 = Object.Instantiate(meshAsset);
meshAsset2.name = "new name";
fbx.GetComponentInChildren().sharedMesh = meshAsset2;
}
Код: Выделить всё
private static void renameTest()
{
GameObject fbx = Selection.activeGameObject;
string path = AssetDatabase.GetAssetPath(fbx);
Mesh meshAsset = AssetDatabase.LoadAllAssetRepresentationsAtPath(path)[0] as Mesh;
meshAsset.name = "new name";
fbx.GetComponentInChildren().sharedMesh = meshAsset;
Debug.Log(meshAsset);
}
[img]https://i.sstatic. net/XdeT7.png[/img]
Если я повторно экспортирую FBX из DCC, чтобы изменить имя сетки, он потеряет связь с префабом, но руководство файла fbx фактически не изменится , почему это происходит? Мои действия:
- переименовать файл aa.FBX в Unity в bb.FBX.
- Импортировать bb.FBX в 3dsmax, и измените имя с aa на bb в 3dsmax.
- Снова экспортируйте в Unity как bb.FBX.
Подробнее здесь: https://stackoverflow.com/questions/717 ... via-script
Мобильная версия