Untiy2019版本预制体:
将Unity2019版本做的预制体复制到低版本工程中,发现是不能拖到编辑面板的,如下图:
编写脚本重新生成预制体:
public class PrefabsToLow : MonoBehaviour
{
void Start()
{
GameObject prefab = Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Prop particle01.prefab", typeof(GameObject)) as GameObject);
UnityEditor.PrefabUtility.CreatePrefab("Assets/Prefabs/CubeClone.prefab", prefab);
}
}
然后就可以拖到编辑面板了,如下图:
拓展更新,批量生成:
public class PrefabsToLow : MonoBehaviour
{
void Start()
{
for (int n = 0; n < 10; n++)
{
GameObject prefab = Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Prefabs/Cube"+ n +".prefab", typeof(GameObject)) as GameObject);
UnityEditor.PrefabUtility.CreatePrefab("Assets/Prefabs/CubeClone.prefab", prefab);
MonoBehaviour.DestroyImmediate(prefab);
}
}
}