低版本Unity導入高版本Unity的預制體,低版本Unity無法使用該預制體


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM