/// <summary> /// 绘制节点 /// </summary> private static void DrawNode(Node node) { if (node != null) { Rect rect = new Rect(node.Rect.x, node.Rect.y, node.Rect.width, node.Rect.height); //节点背景 if (CurrentNode != null) { if (CurrentNode == node) { EditorGUI.DrawRect(rect, Config.SelectNode); } else { EditorGUI.DrawRect(rect, Config.NormalNode); } } else { EditorGUI.DrawRect(rect, Config.NormalNode); } //节点类型 switch (node.Type) { case NodeType.中间节点: DrawUpButton(node); DrawDownButton(node); break; case NodeType.起始节点: DrawDownButton(node); break; case NodeType.结局节点: DrawUpButton(node); break; default: break; } //编号 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 5, 30, 16), "周目"); int round = EditorGUI.IntField(new Rect(rect.x + 5, rect.y + 25, 30, 16), node.ID.Round); EditorGUI.LabelField(new Rect(rect.x + 40, rect.y + 5, 30, 16), "章节"); int chapter = EditorGUI.IntField(new Rect(rect.x + 40, rect.y + 25, 30, 16), node.ID.Chapter); EditorGUI.LabelField(new Rect(rect.x + 75, rect.y + 5, 30, 16), "场景"); int scene = EditorGUI.IntField(new Rect(rect.x + 75, rect.y + 25, 30, 16), node.ID.Scene); EditorGUI.LabelField(new Rect(rect.x + 110, rect.y + 5, 30, 16), "片段"); int part = EditorGUI.IntField(new Rect(rect.x + 110, rect.y + 25, 30, 16), node.ID.Part); EditorGUI.LabelField(new Rect(rect.x + 145, rect.y + 5, 30, 16), "分支"); int branch = EditorGUI.IntField(new Rect(rect.x + 145, rect.y + 25, 30, 16), node.ID.Branch); NodeID id = new NodeID(round, chapter, scene, part, branch); if (!id.Equals(node.ID)) { CurrentStory.SetNodeID(node, id); } //通过 bool ispass = EditorGUI.ToggleLeft(new Rect(rect.x + rect.width - 45, rect.y + 5, 100, 16), "通过", node.IsPassed); if (ispass != node.IsPassed) { node.IsPassed = ispass; } //主线 bool ismain = EditorGUI.ToggleLeft(new Rect(rect.x + rect.width - 45, rect.y + 25, 100, 16), "主线", node.IsMainNode); if (ismain != node.IsMainNode) { node.IsMainNode = ismain; } //内容 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 45, 40, 16), "内容"); node.Content = (ScriptableContent)EditorGUI.ObjectField(new Rect(rect.x + 40, rect.y + 45, 153, 16), node.Content, typeof(ScriptableContent)); ScriptableContent sc = node.Content; if (sc != null) { //形式 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 65, 40, 16), "形式"); sc.Type = (ContentType)EditorGUI.EnumPopup(new Rect(rect.x + 40, rect.y + 65, 135, 20), GUIContent.none, sc.Type); //阅读 sc.IsReaded = EditorGUI.ToggleLeft(new Rect(rect.x + rect.width - 45, rect.y + 65, 45, 16), "阅读", sc.IsReaded); //时间 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 85, 40, 16), "时间"); int y = EditorGUI.IntField(new Rect(rect.x + 40, rect.y + 85, 35, 16), sc.Time.Year); int mo = EditorGUI.IntField(new Rect(rect.x + 78f, rect.y + 85, 30, 16), sc.Time.Month); int d = EditorGUI.IntField(new Rect(rect.x + 111, rect.y + 85, 30, 16), sc.Time.Day); int h = EditorGUI.IntField(new Rect(rect.x + 145, rect.y + 85, 30, 16), sc.Time.Hour); int mi = EditorGUI.IntField(new Rect(rect.x + 180, rect.y + 85, 30, 16), sc.Time.Minute); int s = EditorGUI.IntField(new Rect(rect.x + 215, rect.y + 85, 30, 16), sc.Time.Second); sc.Time = new DateTime(y, mo, d, h, mi, s); //地点 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 105, 40, 16), "地点"); sc.Position = EditorGUI.TextField(new Rect(rect.x + 40, rect.y + 105, rect.width - 45, 16), sc.Position); //概述 EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 125, 40, 16), "概述"); sc.Summary = EditorGUI.TextArea(new Rect(rect.x + 40, rect.y + 125, rect.width - 45, 42), sc.Summary); } else { EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 65, rect.width - 83, 16), "请创建或引用一个节点内容"); } int baseHeight = RefreshNodeHeight(node); //后续节点 if (node.NextNodes != null) { for (int i = 0; i < node.NextNodes.Count; i++) { NodeID nextNodeID = node.NextNodes[i].ID; if (CurrentStory.ContainsID(nextNodeID)) { string label = nextNodeID.Round + "-" + nextNodeID.Chapter + "-" + nextNodeID.Scene + "-" + nextNodeID.Part + "-" + nextNodeID.Branch; int addWidth = (nextNodeID.Round / 10 + nextNodeID.Chapter / 10 + nextNodeID.Scene / 10 + nextNodeID.Part / 10 + nextNodeID.Branch / 10) * 7; EditorGUI.LabelField(new Rect(rect.x + 5, rect.y + 20 * i + baseHeight, 60 + addWidth, 16), label); node.NextNodes[i].Describe = EditorGUI.TextField(new Rect(rect.x + 65 + addWidth, rect.y + 20 * i + baseHeight, rect.width - 95 - addWidth, 16), node.NextNodes[i].Describe); if (GUI.Button(new Rect(rect.x + rect.width - 25, rect.y + 20 * i + baseHeight, 20, 16), "X")) { node.NextNodes.RemoveAt(i); i--; } } else { node.NextNodes.RemoveAt(i); } } } } }
public override void OnInspectorGUI() { EditorGUILayout.LabelField("【故事描述】"); Target.Describe = EditorGUILayout.TextArea(Target.Describe); EditorGUILayout.Space(); EditorGUILayout.LabelField("【故事进度】"); Target.IsPassed = EditorGUILayout.Toggle("是否已通关", Target.IsPassed); EditorGUILayout.TextField("全节点通过百分比", (Target.GetAllNodesPassPercentage() * 100).ToString("f2") + "% (" + Target.GetAllNodesPassFraction() + ")"); EditorGUILayout.TextField("全结局解锁百分比", (Target.GetAllEndingNodesPassPercentage() * 100).ToString("f2") + "% (" + Target.GetAllEndingNodesPassFraction() + ")"); EditorGUILayout.Space(); EditorGUILayout.LabelField("【故事节点】"); if (Target.Nodes.Count > 0) { if (Target.GetStartNode() == null) { EditorGUILayout.HelpBox("请设置一个起始节点", MessageType.Warning); } if (Target.GetEndingNodes().Count == 0) { EditorGUILayout.HelpBox("请至少设置一个结局节点", MessageType.Warning); } foreach (Node item in Target.Nodes) { item.IsFold = EditorGUILayout.Foldout(item.IsFold, item.ID.Round + "-" + item.ID.Chapter + "-" + item.ID.Scene + "-" + item.ID.Part + "-" + item.ID.Branch, true); if (item.IsFold) { EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins); //节点编号 EditorGUILayout.LabelField("节点编号 {周目-章节-场景-片段-分支}"); EditorGUILayout.BeginHorizontal(); int round = EditorGUILayout.IntField(item.ID.Round); int chapter = EditorGUILayout.IntField(item.ID.Chapter); int scene = EditorGUILayout.IntField(item.ID.Scene); int part = EditorGUILayout.IntField(item.ID.Part); int branch = EditorGUILayout.IntField(item.ID.Branch); EditorGUILayout.EndHorizontal(); NodeID id = new NodeID(round, chapter, scene, part, branch); if (!id.Equals(item.ID)) { Target.SetNodeID(item, id); } //节点布局 EditorGUILayout.LabelField("节点布局 {X坐标-Y坐标-宽-高}"); EditorGUILayout.BeginHorizontal(); int x = EditorGUILayout.IntField(item.Rect.x); int y = EditorGUILayout.IntField(item.Rect.y); int w = EditorGUILayout.IntField(item.Rect.width); int h = EditorGUILayout.IntField(item.Rect.height); EditorGUILayout.EndHorizontal(); item.Rect = new RectInt(x, y, w, h); //节点类型 NodeType type = (NodeType)EditorGUILayout.EnumPopup("节点类型", item.Type); Target.SetNodeType(item, type); //节点内容 item.Content = (ScriptableContent)EditorGUILayout.ObjectField("节点内容", item.Content, typeof(ScriptableContent)); //是否已通过 item.IsPassed = EditorGUILayout.Toggle("是否已通过", item.IsPassed); //是否为主线 item.IsMainNode = EditorGUILayout.Toggle("是否为主线", item.IsMainNode); //后续节点 int i = 0; if (item.NextNodes != null) { i = item.NextNodes.Count; } EditorGUILayout.LabelField("后续节点 (" + i + ")"); EditorGUILayout.BeginVertical(EditorStyles.inspectorDefaultMargins); if (i > 0) { for (int j = 0; j < item.NextNodes.Count; j++) { NextNode nn = item.NextNodes[j]; EditorGUILayout.LabelField("选项 " + (j + 1).ToString() + " (" + nn.ID.Round + "-" + nn.ID.Chapter + "-" + nn.ID.Scene + "-" + nn.ID.Part + "-" + nn.ID.Branch + ")"); nn.Describe = EditorGUILayout.TextArea(nn.Describe); } } EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical(); } } } else { EditorGUILayout.HelpBox("请至少创建二个节点", MessageType.Warning); } }