public Node(NodeID id, RectInt rect)
 {
     ID         = id;
     Type       = NodeType.中间节点;
     IsPassed   = false;
     IsMainNode = true;
     Content    = null;
     NextNodes  = new List <NextNode>();
     Rect       = rect;
     IsFold     = false;
 }
        /// <summary>
        /// 创建节点内容
        /// </summary>
        /// <param name="type"></param>
        private static void CreateContent()
        {
            if (CurrentStory.Nodes.Contains(CurrentNode))
            {
                ScriptableContent storyContent = AssetCreator <ScriptableContent> .CreateAsset(Config.StoryResourcesFolder, "Content");

                if (storyContent != null)
                {
                    CurrentNode.Content    = storyContent;
                    Selection.activeObject = storyContent;
                    RefreshNodeHeight(CurrentNode);
                }
            }
            else
            {
                Debug.LogWarning("未指定节点");
            }
        }
示例#3
0
 private void OnEnable()
 {
     Target = (ScriptableContent)target;
 }
        /// <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);
                        }
                    }
                }
            }
        }