代码放在新建文件夹Editor下,不需要挂代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class TextEditor : Editor
{
[MenuItem("NewGameObject/Create/one")]
public static void CreateGameObject()
{
//Debug.Log("创建游戏对象");
//GameObject go = new GameObject("空对象");
//GameObject.CreatePrimitive(PrimitiveType.Sphere);//创建对象
string path = Application.streamingAssetsPath;
if(!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
}
[MenuItem("NewGameObject/Create2")]
public static void CreateGameObject2()
{
Debug.Log("创建游戏对象");
GameObject go = new GameObject("空对象");
GameObject.CreatePrimitive(PrimitiveType.Sphere);
}
}
这个代码随便挂
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class Two : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "Cube"));
GameObject go = ab.LoadAsset<GameObject>("Cube");
Instantiate(go);
}
}
未写完…