低版本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;
editor版本
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]);
}
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();
}
}
}
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论