ScriptableWizard

作者:追风剑情 发布于:2015-5-22 12:48 分类:Unity3d

脚本向导类。

ScriptableWizard1.png


ScriptableWizard2.png


using UnityEngine;
using UnityEditor;
using System.Collections;

public class TestScriptableWizard : ScriptableWizard
{
    //公共参数将显示在窗口中
    public float range = 500;
    public Color color = Color.red;

    [MenuItem("GameObject/Create Light Wizard")]
    static void CreateWizard()
    {
        //第三个参数按钮为可选
        ScriptableWizard.DisplayWizard<TestScriptableWizard>("Create Light", "Create", "OtherButton");
    }

    //窗口中的值改变时,OnWizardUpdate被调用
    void OnWizardUpdate()
    {
        UnityEngine.Debug.Log("OnWizardUpdate()");

        helpString = "Please set the color of the light!";
        errorString = "errorString";
    }

    //当用户按下"Create"按钮,OnWizardCreate被调用
    void OnWizardCreate()
    {
        UnityEngine.Debug.Log("OnWizardCreate()");

        GameObject go = new GameObject("New Light");
        go.AddComponent("Light");
        go.light.range = range;
        go.light.color = color;
    }

    //当用户按下"OtherButton"按钮,OnWizardOtherButton被调用
    void OnWizardOtherButton()
    {
        UnityEngine.Debug.Log("OnWizardOtherButton()");

        if (Selection.activeTransform == null ||
            Selection.activeTransform.light == null) return;
        Selection.activeTransform.light.color = Color.red;//把选中的物体设为红色
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号