ScriptableWizard

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

脚本向导类。

ScriptableWizard1.png


ScriptableWizard2.png


  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4.  
  5. public class TestScriptableWizard : ScriptableWizard
  6. {
  7. //公共参数将显示在窗口中
  8. public float range = 500;
  9. public Color color = Color.red;
  10.  
  11. [MenuItem("GameObject/Create Light Wizard")]
  12. static void CreateWizard()
  13. {
  14. //第三个参数按钮为可选
  15. ScriptableWizard.DisplayWizard<TestScriptableWizard>("Create Light", "Create", "OtherButton");
  16. }
  17.  
  18. //窗口中的值改变时,OnWizardUpdate被调用
  19. void OnWizardUpdate()
  20. {
  21. UnityEngine.Debug.Log("OnWizardUpdate()");
  22.  
  23. helpString = "Please set the color of the light!";
  24. errorString = "errorString";
  25. }
  26.  
  27. //当用户按下"Create"按钮,OnWizardCreate被调用
  28. void OnWizardCreate()
  29. {
  30. UnityEngine.Debug.Log("OnWizardCreate()");
  31.  
  32. GameObject go = new GameObject("New Light");
  33. go.AddComponent("Light");
  34. go.light.range = range;
  35. go.light.color = color;
  36. }
  37.  
  38. //当用户按下"OtherButton"按钮,OnWizardOtherButton被调用
  39. void OnWizardOtherButton()
  40. {
  41. UnityEngine.Debug.Log("OnWizardOtherButton()");
  42.  
  43. if (Selection.activeTransform == null ||
  44. Selection.activeTransform.light == null) return;
  45. Selection.activeTransform.light.color = Color.red;//把选中的物体设为红色
  46. }
  47. }

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号