How to get the name of a model file(fbx) contained in a certain prefab with scripts?

Hi,

I want to output a list about all the prefabs in the project and the related .fbx files with custom editor.

But now I can only get FilterMesh.name and sharedMesh.name.

I realized that I can select the .fbx file via click here

So I think it should be possible to get the information.

Here is the related code.I don’t think it is necessary but still paste it here.

    public void GetMeshList()

    {

        for (int i = 0; i < prefab_list.Count; i++)

        {

            GameObject _prefab = AssetDatabase.LoadAssetAtPath(prefab_path[i] + "\\" + prefab_list[i], typeof(GameObject)) as GameObject;

            if (_prefab != null)

            {

                MeshFilter[] _mf = _prefab.GetComponentsInChildren<MeshFilter>();

                for (int j = 0; j < _mf.Length; j++)

                {  

                    GameObject go = _mf[j].gameObject;

                    //mesh_list.Add(prefab_list[i].ToString().Replace(".prefab","") + "=>" + _mf[j].name);

                    string str1 = _mf[j].name;

                    while (go.transform.parent!=null)

                    {

                        str1 = string.Concat(go.transform.parent.name + "=>" + str1);

                        go = go.transform.parent.gameObject;

                    }

                    mesh_list.Add(str1);

                    CalculateFinalData(_mf[j].sharedMesh, scale);

                }  

            }

        }

    }

Thx!

The ‘m_CorrespondingSourceObject’ is stored inside the prefab file on disk. It maybe possible to work it out from that. That member is not exposed in the API for C#.

Thx for ur reply!

Actually I thought about the prefab file itself and try to match the guid, but the compute is too large and I don’t know how to optimize it.

    public void MatchGUID()
    {

        EditorSettings.serializationMode = SerializationMode.ForceText;
        DirectoryInfo direction = new DirectoryInfo(Application.dataPath + "/Resources/effect");
        FileInfo[] prefab_files = direction.GetFiles("*.prefab", SearchOption.AllDirectories);

        for (int j = 0; j < mesh_list.Count; j++)
        {
            final_prefab = "";

            string guid = AssetDatabase.AssetPathToGUID((mesh_path[j] + "\\" + mesh_list[j]).ToString());
            for (int i = 0; i < prefab_files.Length; i++)
            {
                string file = prefab_files[i].OpenText().ReadToEnd();
                //if (Regex.IsMatch(File.ReadAllText(file), guid))
                if (Regex.IsMatch(file, guid))
                {
                    final_prefab = string.Concat(prefab_files[i].Name + ",", final_prefab);
                }
            }
        }
    }

About the ‘m_CorrespondingSourceObject’ you mentioned, I didn’t find too much info. Hope you can provide more advice, thx!

For those who find this when googling:

2 Likes