Unity用低版本導入高版本預制體無法打開的解決方法:
1、直接通過代碼生成預制體,就可以使用了。
代碼示例如下:
using System.Collections.Generic; using UnityEditor; using UnityEngine; namespace DFramework.Tools { public class GeneratePrefabs : EditorWindow { [MenuItem("我的工具/物體生成")] static void 顯示新窗口() { GeneratePrefabs GenerateWindow = GetWindow<GeneratePrefabs>(true, "物體生成"); GenerateWindow.Show();//顯示一個窗口 } [SerializeField] protected List<GameObject> _assetList = new List<GameObject>(); protected SerializedObject _serializedObject; protected SerializedProperty _assetLstProperty; protected void OnEnable() { _serializedObject = new SerializedObject(this); _assetLstProperty = _serializedObject.FindProperty("_assetList"); } private string mParentName; void GenerateAssets() { float progress = 0; EditorUtility.DisplayProgressBar("進度條", "生成中", progress); if (mParentName==null|| mParentName =="") { mParentName = "資源父物體"; } Transform mParent = new GameObject(mParentName).transform; float childCount = _assetList.Count; for (int i = 0; i < _assetList.Count; i++) { if (_assetList[i]!=null) { GameObject mChild=Instantiate(_assetList[i]); mChild.transform.SetParent(mParent); } progress = (i + 1) / childCount; EditorUtility.DisplayProgressBar("進度條", "生成中", progress); } EditorUtility.ClearProgressBar(); } void OnGUI() { mParentName = EditorGUILayout.TextField("資源父物體名稱:",mParentName); GUILayout.Label("將資源添加到集合中"); _serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(_assetLstProperty, true); if (EditorGUI.EndChangeCheck()) { _serializedObject.ApplyModifiedProperties(); } if (GUILayout.Button("開始生成")) { GenerateAssets(); } } } }
