转载:http://blog.csdn.net/liqiangeastsun/article/details/42124469
// 利用代码创建prefab
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.IO;
public class CameraMove : MonoBehaviour {
//生成Prefab, 参数1 需要生成的对象,参数2,名字
private void CreatePrefabObj(GameObject obj, string prefabName)
{
string[] str = prefabName.Split ('(');
string path = "Assets/Resources/_Art/Role/Individual/" + str[0] + ".prefab";
//参数1 创建路径,参数2 需要创建的对象, 如果路径下已经存在该名字的prefab,则覆盖
PrefabUtility.CreatePrefab (path, obj);
}
}
网友评论