插件制作

该代码示例展示了如何在Unity中创建Editor脚本以生成GameObject,使用AssetBundle进行资源管理,包括创建AssetBundles并存储到StreamingAssets路径,以及在游戏中加载AssetBundle并实例化游戏对象。
摘要由CSDN通过智能技术生成

代码放在新建文件夹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);
    }

}

未写完…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值