Unity's higher version prefab (Prefab) to lower version

Unity's higher version prefab to lower version

Untiy2019 version prefab:

1.1

Copy the prefab made by the Unity2019 version to the lower version project, and find that it cannot be dragged to the editing panel, as shown below:
1.1.2


Write a script to regenerate the prefab:
1.1.3

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);
	}
}

Then you can drag it to the edit panel, as shown below:1.1.5



Extended update, batch generation:

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);
		}
	}
}

Guess you like

Origin blog.csdn.net/Czhenya/article/details/110385888