[Unity实战]剧情对话(二)
在上一篇文章中,我们在CommandManager中直接写入一个个的指令,实际上这样是很不好的,因为一个游戏可能会出现很多的剧情动画,那么不就是要写n个类吗?而且修改起来也不是很好的。所以一个比较好的方法就是写一个编辑器类。
以下是本人写的一个编辑器类,功能还不是很完善,例如可以加入"插入命令","从文本中读取命令"等等等的功能,不过,先将就用了。。
using UnityEngine; using UnityEditor; using System.Collections.Generic; public enum Option { CommandDestory, CommandDialogue, CommandDialogueModeEnter, CommandDialogueModeExit, CommandGenerate, CommandMove, CommandMusic, CommandPlayAnim, CommandRotate, CommandWait } public class Window : EditorWindow { List<Option> options = new List<Option>(); List<string[]> strings = new List<string[]>(); List<int[]> ints = new List<int[]>(); List<float[]> floats = new List<float[]>(); List<Vector3[]> vector3s = new List<Vector3[]>(); Vector2 v2 = new Vector2(0, 0);//滚动条参数 [MenuItem("Window/My Window")] static void Init() { EditorWindow.GetWindow(typeof(Window)); } void OnGUI() { if (GUILayout.Button("保存命令")) { } if (GUILayout.Button("添加命令")) { Option x = Option.CommandDialogueModeEnter; options.Add(x); string[] a = new string[5]; strings.Add(a); int[] b = new int[5]; ints.Add(b); float[] c = new float[5]; floats.Add(c); Vector3[] d = new Vector3[5]; vector3s.Add(d); } if (GUILayout.Button("删除命令")) { options.RemoveAt(options.Count - 1); strings.RemoveAt(options.Count - 1); ints.RemoveAt(options.Count - 1); floats.RemoveAt(options.Count - 1); vector3s.RemoveAt(options.Count - 1); } v2 = EditorGUILayout.BeginScrollView(v2,false,true,null); for (int i = 0; i < options.Count; i++) { options[i] = (Option)EditorGUILayout.EnumPopup("选项" + i, options[i]); switch (options[i]) { case Option.CommandDestory: strings[i][0] = EditorGUILayout.TextField("物体名字", strings[i][0]); break; case Option.CommandDialogue: strings[i][0] = EditorGUILayout.TextField("xml文本名字", strings[i][0]); ints[i][0] = EditorGUILayout.IntField("开始序号", ints[i][0]); ints[i][1] = EditorGUILayout.IntField("结束序号", ints[i][1]); ints[i][2] = EditorGUILayout.IntField("点击后执行的步骤数", ints[i][2]); break; case Option.CommandDialogueModeEnter: break; case Option.CommandDialogueModeExit: break; case Option.CommandGenerate: strings[i][0] = EditorGUILayout.TextField("物体名字", strings[i][0]); vector3s[i][0] = EditorGUILayout.Vector3Field("生成位置", vector3s[i][0]); vector3s[i][1] = EditorGUILayout.Vector3Field("生成角度", vector3s[i][1]); break; case Option.CommandMove: strings[i][0] = EditorGUILayout.TextField("物体名字", strings[i][0]); vector3s[i][0] = EditorGUILayout.Vector3Field("终点位置", vector3s[i][0]); floats[i][0] = EditorGUILayout.FloatField("所用时间", floats[i][0]); break; case Option.CommandMusic: strings[i][0] = EditorGUILayout.TextField("音乐名字", strings[i][0]); break; case Option.CommandPlayAnim: strings[i][0] = EditorGUILayout.TextField("物体名字", strings[i][0]); ints[i][0] = EditorGUILayout.IntField("动画状态", ints[i][0]); break; case Option.CommandRotate: strings[i][0] = EditorGUILayout.TextField("物体名字", strings[i][0]); vector3s[i][0] = EditorGUILayout.Vector3Field("终点角度", vector3s[i][0]); floats[i][0] = EditorGUILayout.FloatField("所用时间", floats[i][0]); break; case Option.CommandWait: floats[i][0] = EditorGUILayout.FloatField("等待时间", floats[i][0]); break; default: break; } } EditorGUILayout.EndScrollView(); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。