Unity inspector绘制按钮与Editor下生成与销毁物体的方法 反射 协程 Editor

文章介绍了如何在Unity中编写一个脚本,实现在编辑环境下实例化预制体,并通过Inspector中的自定义按钮控制。脚本包括实例化功能、数组存储、以及避免在编辑模式下永久销毁对象的解决方案。

应美术要求,实现一个在编辑环境下,不运行,可以实例化预制体的脚本
在这里插入图片描述
效果如上图所示
1.去实现一个简单的 行、列实例化物体脚本
2.在Inspector下提供按钮
3.将方法暴露出来(通过自定义标签实现

需求一
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FX_init : MonoBehaviour
{
   
   
    // Start is called before the first frame update
    public GameObject PreGameObject;
    public int numCol = 4;

    public float spaceCol = 2.0f;
    
    public int numRow = 4;

    public float spaceRow = 2.0f;

    private List<GameObject> cubeTemp;
    void Start()
    {
   
   
        SetInit();
    }
    public void SetInit()
    {
   
   
        for (int i = 0; i < numCol; i++)
        {
   
   
            for (int j = 0; j< numRow; j++)
            {
   
   
                float xPos = i * spaceRow;
                float
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值