低版本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