Unity ScriptableWizard窗口

官方API见:UnityEditor.ScriptableWizard - Unity 脚本 API (unity3d.com)

        使用该API可以轻松的在Unity中创建编辑器向导,以独立运行的脚本,不需要挂载在GameObject上也可以运行。 

        使用编辑器向导的脚本必须放在Editor文件夹内(没有就新建一个)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class RenderCubeMapWizard : ScriptableWizard
{
    public Transform renderFromPos;
    public Cubemap cubemap;

    [MenuItem("Tools/CreateCubemap")]

    static void CreateCubemap()
    {
        //"Create Cubemap"是打开的窗口名,"Create"是按钮名,点击时调用OnWizardCreate()方法
        ScriptableWizard.DisplayWizard("Create Cubemap", typeof(RenderCubeMapWizard), "Creat");//打开向导
    }
    private void OnWizardCreate()
    {
        GameObject obj = new GameObject("CubeMapCamera");
        obj.AddComponent<Camera>();
        obj.transform.position = renderFromPos.position;
        obj.GetComponent<Camera>().RenderToCubemap(cubemap);
        Destroy(obj);
    }
}

public static ScriptableWizard DisplayWizard (string title, Type klass, string createButtonName= "Create", string otherButtonName= "");

posted @ 2022-02-16 15:21  PAddingoi  阅读(2)  评论(0编辑  收藏  举报  来源