2019-08-01【3D-Game-Kits】(未测试)从非R

2019-08-01  本文已影响0人  持刀的要迟到了
image.png
    protected GameObject InstantiatePrefab (string folderPath, string prefabName)
    {
        GameObject instance = null;
        string[] prefabFolderPath = { folderPath };
        string[] guids = AssetDatabase.FindAssets (prefabName, prefabFolderPath);
    
        if(guids.Length == 0)
            Debug.LogError ("The " + prefabName + " prefab could not be found in " + folderPath + " and could therefore not be instantiated.  Please create one manually.");
        else if(guids.Length > 1)
            Debug.LogError ("Multiple " + prefabName + " prefabs were found in " + folderPath + " and one could therefore not be instantiated.  Please create one manually.");
        else
        {
            string path = AssetDatabase.GUIDToAssetPath (guids[0]);
            GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject> (path);
            instance = Instantiate (prefab);
        }

        return instance;
    }
上一篇 下一篇

猜你喜欢

热点阅读