鸟语天空
ScriptableWizard
post by:追风剑情 2015-5-22 12:48

脚本向导类。

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;//把选中的物体设为红色
    }
}

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容