我尝试了很多次但是失败了,所以我想也许这就是团结4.6的错误;
Unity 4.6 Windows 7 64位
要求:当我导入fbx文件时,自动生成预制文件。
第1步: OnPostprocessModel中的1(编辑器文件夹) 2以下4方法全部返回null:
string path3 = @"C:\Users\Administrator\Documents\test\Assets\Resources\Models\Item.fbx";
object obj1 = AssetDatabase.LoadMainAssetAtPath(path3);
object obj2 = AssetDatabase.LoadAssetAtPath(path3, typeof(GameObject));
object obj3 = Resources.LoadAssetAtPath(path3, typeof(GameObject));
object obj4 = Resources.LoadAssetAtPath<GameObject>(path3);
答案 0 :(得分:1)
这不是一个错误,你永远不会找到你的对象。因为你提供了错误的道路。
您运行的所有4个函数都要求您的模型位于Resources文件夹或Assets文件夹中。所以你会想要使用路径名如下
Assets/Resources/Models/Item.fbx
Resources/Models/Item.fbx
unity wiki教我们以下
Note:
All asset names & paths in Unity use forward slashes,
paths using backslashes will not work.
除此之外,我认为您不应该使用这些功能,但您应该使用PrefabUtility代替。可以在unity answers
上找到一个很好的样本 // Create some asset folders.
AssetDatabase.CreateFolder("Assets/Meshes", "MyMeshes");
AssetDatabase.CreateFolder("Assets/Prefabs", "MyPrefabs");
// The paths to the mesh/prefab assets.
string meshPath = "Assets/Meshes/MyMeshes/MyMesh01.mesh";
string prefabPath = "Assets/Prefabs/MyPrefabs/MyPrefab01.prefab";
// Delete the assets if they already exist.
AssetDatabase.DeleteAsset(meshPath);
AssetDatabase.DeleteAsset(prefabPath);
// Create the mesh somehow.
Mesh mesh = GetMyMesh();
// Save the mesh as an asset.
AssetDatabase.CreateAsset(mesh, meshPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
// Create a transform somehow, using the mesh that was previously saved.
Transform trans = GetMyTransform(mesh);
// Save the transform's GameObject as a prefab asset.
PrefabUtility.CreatePrefab(prefabPath, trans.gameObject);