Пример #1
0
    /// <summary>
    /// 添加节点
    /// </summary>
    /// <param name="node"></param>
    public void AddNode(NodeRoot node)
    {
        int count = nodeChildList.Count;

        node.NodeIndex = count;
        nodeChildList.Add(node);
    }
Пример #2
0
        public Size CalcSize(Graphics g, Font f, TextBoxControl editor)
        {
            Size size = new Size();

            if (XmlHeader != null)
            {
                Size szTemp = XmlHeader.CalcSize(g, f, editor);
                if (szTemp.Width > size.Width)
                {
                    size.Width = szTemp.Width;
                }

                size.Height += szTemp.Height;
            }

            if (NodeRoot != null)
            {
                Size szTemp = NodeRoot.CalcSize(g, f, editor);
                if (szTemp.Width > size.Width)
                {
                    size.Width = szTemp.Width;
                }

                size.Height += szTemp.Height;
            }

            Size = size;

            NCalc = false;

            return(size);
        }
Пример #3
0
    protected virtual void AddNode()
    {
        NodeRoot nodeRoot = new NodeRoot();

        nodeRoot.WindowRect = new Rect(mousePosition.x, mousePosition.y, 300, 300);
        nodeRootList.Add(nodeRoot);
    }
Пример #4
0
        /// <summary>
        /// 选择节点依次遍历所有子节点,如果都返回 Fail,则向父节点返回 Fail
        /// 直到一个节点返回 Success 或者 Running,停止后续节点的执行,向父节点
        /// 返回 Success 或者 Running
        /// 注意:如果节点返回 Running 需要记住这个节点,下次直接从此节点开始执行
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            int index = 0;

            if (lastRunningNode != null)
            {
                index = lastRunningNode.NodeIndex;
            }
            lastRunningNode = null;

            ResultType resultType = ResultType.Fail;

            for (int i = index; i < nodeChildList.Count; ++i)
            {
                NodeRoot nodeRoot = nodeChildList[i];
                resultType = nodeRoot.Run();
                if (resultType == ResultType.Fail)
                {
                    continue;
                }

                if (resultType == ResultType.Success)
                {
                    break;
                }

                if (resultType == ResultType.Running)
                {
                    lastRunningNode = nodeRoot;
                    break;
                }
            }

            return(resultType);
        }
Пример #5
0
        /// <summary>
        /// 并行节点同时执行所有节点,直到一个节点返回 Fail 或者全部节点都返回 Success
        /// 才向父节点返回 Fail 或者 Success,并终止执行其他节点
        /// 其他情况向父节点返回 Running
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            ResultType resultType = ResultType.Fail;

            int successCount = 0;

            for (int i = 0; i < nodeChildList.Count; ++i)
            {
                NodeRoot nodeRoot = nodeChildList[i];
                resultType = nodeRoot.Run();

                if (resultType == ResultType.Fail)
                {
                    break;
                }

                if (resultType == ResultType.Success)
                {
                    ++successCount;
                    continue;
                }

                if (resultType == ResultType.Running)
                {
                    continue;
                }
            }

            if (resultType != ResultType.Fail)
            {
                resultType = (successCount >= nodeChildList.Count) ? ResultType.Success : ResultType.Running;
            }

            return(resultType);
        }
Пример #6
0
    private NodeRoot GetLeafNode(NodeValue nodeValue)
    {
        string componentName = nodeValue.componentName;

        NodeRoot nodeRoot = null;

        switch (componentName)
        {
        case "NodeActionCooking":
            nodeRoot = new NodeActionCooking();
            break;

        case "NodeActionEat":
            nodeRoot = new NodeActionEat();
            break;

        case "NodeActionMove":
            nodeRoot = new NodeActionMove();
            break;

        case "NodeConditionHasFood":
            nodeRoot = new NodeConditionHasFood();
            break;

        case "NodeConditionHungry":
            nodeRoot = new NodeConditionHungry();
            break;
        }

        return(nodeRoot);
    }
Пример #7
0
 protected static void Copy()
 {
     if (cpoyNode != null)
     {
         NodeRoot cop = ((StoryNode)cpoyNode).Clone();
         nodeRootList.Add(cop);
         cpoyNode = cop;
     }
 }
Пример #8
0
    // 删除节点
    protected void DeleteNode()
    {
        int selectIndex = 0;

        selectNode = GetMouseInNode(out selectIndex);
        if (selectNode != null)
        {
            nodeRootList[selectIndex].Release();
            nodeRootList.Remove(selectNode);
        }
    }
Пример #9
0
        /// <summary>
        /// 修饰节点只有一个子节点,执行子节点直到 执行结果 = untilResultType,将 结果返回给父节点
        /// 如果执行结果 != untilResultType 则返回 Running
        /// </summary>
        /// <returns></returns>
        public override ResultType Execute()
        {
            NodeRoot   nodeRoot   = nodeChildList[0];
            ResultType resultType = nodeRoot.Execute();

            if (resultType != untilResultType)
            {
                return(ResultType.Running);
            }

            return(resultType);
        }
Пример #10
0
    void DrawNodeWindow(int id)
    {
        if (id >= nodeRootList.Count)
        {
            return;
        }
        NodeRoot nodeRoot = nodeRootList[id];

        // 可拖拽位置的 window
        OnDrawNodeWindow(nodeRoot);
        GUI.DragWindow();
    }
Пример #11
0
 /// <summary>
 /// 每帧绘制从 节点到所有子节点的连线
 /// </summary>
 /// <param name="nodeRoot"></param>
 private void DrawToChildCurve(NodeRoot nodeRoot)
 {
     for (int i = nodeRoot.childNodeList.Count - 1; i >= 0; --i)
     {
         NodeRoot childNode = nodeRoot.childNodeList[i];
         // 删除无效节点
         if (childNode == null || childNode.isRelease)
         {
             nodeRoot.childNodeList.RemoveAt(i);
             continue;
         }
         DrawNodeCurve(nodeRoot.WindowRect, childNode.WindowRect);
     }
 }
Пример #12
0
        public override bool Update(NodeRoot rootNode)
        {
            Action <Data.NodeBase> convert = null;

            convert = (n) =>
            {
                var n_ = n as Data.Node;

                if (n_ != null && (n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ribbon || n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Track))
                {
                    var rp = n_.DrawingValues;
                    rp.TrailSmoothing.SetValueDirectly(TrailSmoothingType.Disabled);
                    rp.TrailTimeSource.SetValueDirectly(TrailTimeSourceType.FirstParticle);
                }

                if (n_ != null && n_.DrawingValues.Type.Value == RendererValues.ParamaterType.Sprite)
                {
                    StandardColor sc = new StandardColor();
                    sc.Type   = n_.DrawingValues.Sprite.ColorAll;
                    sc.Fixed  = n_.DrawingValues.Sprite.ColorAll_Fixed;
                    sc.Random = n_.DrawingValues.Sprite.ColorAll_Random;
                    sc.Easing = n_.DrawingValues.Sprite.ColorAll_Easing;
                    sc.FCurve = n_.DrawingValues.Sprite.ColorAll_FCurve;
                    var text = Core.Copy("Temp", sc);
                    Core.Paste("Temp", n_.DrawingValues.ColorAll, text);
                }

                if (n_ != null && n_.DrawingValues.Type.Value == RendererValues.ParamaterType.Model)
                {
                    StandardColor sc = new StandardColor();
                    sc.Type   = n_.DrawingValues.Model.Color;
                    sc.Fixed  = n_.DrawingValues.Model.Color_Fixed;
                    sc.Random = n_.DrawingValues.Model.Color_Random;
                    sc.Easing = n_.DrawingValues.Model.Color_Easing;
                    sc.FCurve = n_.DrawingValues.Model.Color_FCurve;

                    var text = Core.Copy("Temp", sc);
                    Core.Paste("Temp", n_.DrawingValues.ColorAll, text);
                }

                for (int i = 0; i < n.Children.Count; i++)
                {
                    convert(n.Children[i]);
                }
            };

            convert(rootNode);

            return(true);
        }
Пример #13
0
    public void IterationChild(NodeCombiner parentNode, NodeValue nodeValue)
    {
        for (int i = 0; i < nodeValue.childNodeList.Count; ++i)
        {
            NodeValue childNode = nodeValue.childNodeList[i];
            NodeRoot  node      = GetNodeRoot(childNode);
            parentNode.AddNode(node);

            if (node.GetType().IsSubclassOf(typeof(NodeCombiner)))
            {
                IterationChild((NodeCombiner)node, childNode);
            }
        }
    }
Пример #14
0
        public int LineCount()
        {
            int iCount = 0;

            if (XmlHeader != null)
            {
                iCount += 1;
            }
            if (NodeRoot != null)
            {
                iCount += NodeRoot.LineCount();
            }

            return(iCount);
        }
Пример #15
0
        /// <summary>
        /// 通过行号获取行
        /// </summary>
        public Line GetLineByLineCount(int line)
        {
            int CurrNumber = 0;

            if (XmlHeader != null)
            {
                CurrNumber += 1;
                if (line == CurrNumber)
                {
                    return(XmlHeader.FirstLine);
                }
            }
            if (NodeRoot != null)
            {
                return(NodeRoot.GetLineByLineNumber(ref CurrNumber, line));
            }
            return(null);
        }
Пример #16
0
    // 获取鼠标所在位置的节点
    private NodeRoot GetMouseInNode(out int index)
    {
        index = 0;
        NodeRoot selectRoot = null;

        for (int i = 0; i < nodeRootList.Count; i++)
        {
            NodeRoot nodeRoot = nodeRootList[i];
            // 如果鼠标位置 包含在 节点的 Rect 范围,则视为可以选择的节点
            if (nodeRoot.WindowRect.Contains(mousePosition))
            {
                selectRoot = nodeRoot;
                index      = i;
                break;
            }
        }

        return(selectRoot);
    }
Пример #17
0
    public NodeRoot GetNode(NodeAsset nodeAsset)
    {
        NodeValue nodeValue = nodeAsset.nodeValue;

        if (nodeValue == null)
        {
            Debug.LogError("RootNode is null");
            return(null);
        }

        NodeRoot rootNode = GetNodeRoot(nodeValue);

        if (rootNode.GetType().IsSubclassOf(typeof(NodeCombiner)))
        {
            IterationChild((NodeCombiner)rootNode, nodeValue);
        }

        return(rootNode);
    }
Пример #18
0
        public void SaveAs(string file)
        {
            try
            {
                if (string.IsNullOrEmpty(file))
                {
                    SaveFileDialog dlg = new SaveFileDialog();
                    dlg.Filter = "Xml File (*.xml)|*.xml";
                    if (dlg.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    file = dlg.FileName;
                }

                Encoding ed = Encoding.UTF8;
                if (XmlHeader != null && !string.IsNullOrEmpty(XmlHeader.Encoding))
                {
                    ed = Encoding.GetEncoding(XmlHeader.Encoding);
                }

                using (StreamWriter writer = new StreamWriter(file, false, ed))
                {
                    if (XmlHeader != null)
                    {
                        XmlHeader.Save(writer);
                    }

                    if (NodeRoot != null)
                    {
                        NodeRoot.Save(writer);
                    }
                }

                m_sFile = file;
            }
            catch (System.Exception ex)
            {
                //MessageBox.Show("保存XML文件失败,请确认文件是否正确。\n" + ex.Message);
                throw ex;
            }
        }
Пример #19
0
    /// <summary>
    /// 随机遍历子节点, 当遇到 Success 时, 返回父节点
    /// 当执行遇到 Fail 时, 尝试执行下一个子节点
    /// 当执行遇到 Running 时, 记录该节点, 下一次继续运行
    /// </summary>
    /// <returns></returns>
    public override ResultType Execute()
    {
        List <int> randomList = GetRandom(nodeChildList.Count);

        int index = -1;

        if (lastRunningNode != null)
        {
            index           = lastRunningNode.NodeIndex;
            lastRunningNode = null;
        }
        ResultType resultType = ResultType.Fail;

        while ((randomList.Count > 0))
        {
            if (index < 0)
            {
                // 从随机数组中最后一个开始取
                index = randomList[randomList.Count - 1];
                randomList.RemoveAt(randomList.Count - 1);
            }
            NodeRoot nodeRoot = nodeChildList[index];
            index      = -1;
            resultType = nodeRoot.Execute();
            if (resultType == ResultType.Fail)
            {
                continue;
            }
            if (resultType == ResultType.Success)
            {
                break;
            }
            if (resultType == ResultType.Running)
            {
                lastRunningNode = nodeRoot;
                break;
            }
        }

        return(resultType);
    }
Пример #20
0
    private NodeRoot GetNodeRoot(NodeValue nodeValue)
    {
        NodeRoot nodeRoot = null;

        switch (nodeValue.NodeType)
        {
        case NodeType.Select:        // 选择节点
            nodeRoot = new NodeSelect();
            break;

        case NodeType.Sequence:      // 顺序节点
            nodeRoot = new NodeSequence();
            break;

        case NodeType.Decorator:     // 修饰节点
            nodeRoot = new NodeDecorator();
            break;

        case NodeType.Random:        // 随机节点
            nodeRoot = new NodeRandom();
            break;

        case NodeType.Parallel:      // 并行节点
            nodeRoot = new NodeParallel();
            break;

        case NodeType.Condition:     // 条件节点
            nodeRoot = GetLeafNode(nodeValue);
            break;

        case NodeType.Action:        // 行为节点
            nodeRoot = GetLeafNode(nodeValue);
            break;
        }

        return(nodeRoot);
    }
Пример #21
0
    /// <summary>
    /// 并行组合节点同时执行所有节点, 直到一个节点返回 Fail 或者全部节点 Success 才返回给父节点Success
    /// 其他情况, 则向父节点返回Running
    /// </summary>
    /// <returns></returns>
    public override ResultType Execute()
    {
        ResultType resultType = ResultType.Fail;

        int successCount = 0;

        for (int i = 0; i < nodeChildList.Count; i++)
        {
            NodeRoot nodeRoot = nodeChildList[i];
            resultType = nodeRoot.Execute();
            if (resultType == ResultType.Fail)
            {
                break;
            }
            if (resultType == ResultType.Running)
            {
                break;
            }

            if (resultType == ResultType.Success)
            {
                successCount++;
                continue;
            }
        }

        if (resultType == ResultType.Fail)
        {
            return(ResultType.Fail);
        }
        if (successCount == nodeChildList.Count)
        {
            return(ResultType.Success);
        }
        return(ResultType.Running);
    }
Пример #22
0
    protected override void OnDrawNodeWindow(NodeRoot node)
    {
        StoryNode sn = node as StoryNode;

        GUILayout.BeginVertical();

        #region 剧情类型  对话、旁白、选择、冒泡

        int index = EditorGUILayout.Popup("剧情类型:", ts.GetIndex((int)sn.type), ts.alias.ToArray());
        sn.type = (Enum_Story_Type)ts.GetEnum(index);// EditorGUILayout.Popup("剧情类型:", ts.GetIndex((int)sn.type), ts.alias.ToArray()));
        switch (sn.type)
        {
        case Enum_Story_Type.None:
            sn.text          = EditorGUILayout.TextField("文本:", sn.text);
            sn.animType      = Enum_Story_RoleAnim.None;
            sn.emoji         = Enum_Story_Emoji.None;
            sn.location      = Enum_Story_Location.None;
            sn.characterName = string.Empty;
            sn.roleId        = 0;
            sn.roleType      = Enum_Story_Role.None;
            break;

        case Enum_Story_Type.Dialog:                //对话
            sn.text          = EditorGUILayout.TextField("文本:", sn.text);
            sn.location      = (Enum_Story_Location)ls.GetEnum(EditorGUILayout.Popup("位置:", ls.GetIndex((int)sn.location), ls.alias.ToArray()));
            sn.roleType      = (Enum_Story_Role)rs.GetEnum(EditorGUILayout.Popup("角色类型:", rs.GetIndex((int)sn.roleType), rs.alias.ToArray()));
            sn.animType      = (Enum_Story_RoleAnim)ras.GetEnum(EditorGUILayout.Popup("角色动画:", ras.GetIndex((int)sn.animType), ras.alias.ToArray()));
            sn.characterName = EditorGUILayout.TextField("角色名字:", sn.characterName);
            sn.soundEffect   = EditorGUILayout.TextField("音效:", sn.soundEffect);
            break;

        case Enum_Story_Type.Aside:                //旁白
            sn.text          = EditorGUILayout.TextField("文本:", sn.text);
            sn.animType      = Enum_Story_RoleAnim.None;
            sn.emoji         = Enum_Story_Emoji.None;
            sn.location      = Enum_Story_Location.None;
            sn.characterName = string.Empty;
            sn.roleId        = 0;
            sn.roleType      = Enum_Story_Role.None;
            sn.soundEffect   = EditorGUILayout.TextField("音效:", sn.soundEffect);
            break;

        case Enum_Story_Type.CutTo:                //转场
            sn.textId        = 0;
            sn.text          = string.Empty;
            sn.animType      = Enum_Story_RoleAnim.None;
            sn.emoji         = Enum_Story_Emoji.None;
            sn.location      = Enum_Story_Location.None;
            sn.roleId        = 0;
            sn.characterName = string.Empty;
            sn.roleType      = Enum_Story_Role.None;
            break;

        case Enum_Story_Type.Choice:                //选择
            sn.textId        = 0;
            sn.text          = string.Empty;
            sn.animType      = Enum_Story_RoleAnim.None;
            sn.emoji         = Enum_Story_Emoji.None;
            sn.location      = Enum_Story_Location.None;
            sn.roleId        = 0;
            sn.characterName = string.Empty;
            sn.roleType      = Enum_Story_Role.None;
            break;

        case Enum_Story_Type.Bubble:                //冒泡
            sn.text          = EditorGUILayout.TextField("文本:", sn.text);
            sn.location      = (Enum_Story_Location)ls.GetEnum(EditorGUILayout.Popup("位置:", ls.GetIndex((int)sn.location), ls.alias.ToArray()));
            sn.roleType      = (Enum_Story_Role)rs.GetEnum(EditorGUILayout.Popup("角色类型:", rs.GetIndex((int)sn.roleType), rs.alias.ToArray()));
            sn.animType      = (Enum_Story_RoleAnim)ras.GetEnum(EditorGUILayout.Popup("角色动画:", ras.GetIndex((int)sn.animType), ras.alias.ToArray()));
            sn.characterName = EditorGUILayout.TextField("角色名字:", sn.characterName);
            break;

        case Enum_Story_Type.VoiceOver:                //字幕
            sn.text          = EditorGUILayout.TextField("文本:", sn.text);
            sn.animType      = Enum_Story_RoleAnim.None;
            sn.emoji         = Enum_Story_Emoji.None;
            sn.location      = Enum_Story_Location.None;
            sn.roleId        = 0;
            sn.characterName = string.Empty;
            sn.roleType      = Enum_Story_Role.None;
            break;
        }

        #endregion

        #region   立绘、通讯窗口、雪花窗口

        switch (sn.roleType)
        {
        case Enum_Story_Role.None:
            sn.emoji = Enum_Story_Emoji.None;
            break;

        case Enum_Story_Role.Normal:                //立绘
            sn.emoji = (Enum_Story_Emoji)es.GetEnum(EditorGUILayout.Popup("立绘表情:", es.GetIndex((int)sn.emoji), es.alias.ToArray()));
            break;

        case Enum_Story_Role.Window:                //通讯窗口
            sn.emoji = Enum_Story_Emoji.None;
            break;

        case Enum_Story_Role.NoiseWindow:                //雪花窗口
            sn.emoji = Enum_Story_Emoji.None;
            break;

        default:
            break;
        }

        #endregion

        sn.autoPlay = EditorGUILayout.Toggle("自动", sn.autoPlay);
        if (sn.autoPlay)
        {
            sn.delayTime = EditorGUILayout.FloatField("延迟:", sn.delayTime);
        }
        sn.backGround1 = EditorGUILayout.TextField("背景1:", sn.backGround1);
        sn.backGround2 = EditorGUILayout.TextField("背景2:", sn.backGround2);

        #region 声音类型
        sn.bgmType = (Enum_Story_BGM)ts.GetEnum(EditorGUILayout.Popup("BGM类型:", bs.GetIndex((int)sn.bgmType), bs.alias.ToArray()));
        switch (sn.bgmType)
        {
        case Enum_Story_BGM.None:
            sn.BGM      = string.Empty;
            sn.fadeTime = 0f;
            sn.BGMLoop  = false;
            break;

        case Enum_Story_BGM.Play:
            sn.BGM      = EditorGUILayout.TextField("BGM:", sn.BGM);
            sn.fadeTime = EditorGUILayout.FloatField("淡化时间:", sn.fadeTime);
            sn.BGMLoop  = EditorGUILayout.Toggle("循环播放:", sn.BGMLoop);
            break;

        case Enum_Story_BGM.Pause:
            sn.fadeTime = EditorGUILayout.FloatField("淡化时间:", sn.fadeTime);
            break;

        case Enum_Story_BGM.Continue:
            sn.fadeTime = EditorGUILayout.FloatField("淡化时间:", sn.fadeTime);
            break;

        case Enum_Story_BGM.Stop:
            sn.fadeTime = EditorGUILayout.FloatField("淡化时间:", sn.fadeTime);
            break;

        case Enum_Story_BGM.StopAndContinueLast:
            sn.fadeTime = EditorGUILayout.FloatField("淡化时间:", sn.fadeTime);
            break;

        default:
            break;
        }

        #endregion

        GUILayout.EndVertical();
    }
Пример #23
0
        public override bool Update(NodeRoot rootNode)
        {
            {
                Action <Data.NodeBase> convert = null;
                convert = (n) =>
                {
                    var n_ = n as Data.Node;

                    if (n_ != null && n_.DrawingValues.Type.Value == Data.RendererValues.ParamaterType.Ring)
                    {
                        var rp = n_.DrawingValues.Ring;
                        if (rp.ViewingAngle.Value != Data.RendererValues.RingParamater.ViewingAngleType.Fixed ||
                            rp.ViewingAngle_Fixed.Value != 360)
                        {
                            var rc = rp.RingShape.Crescent;
                            rp.RingShape.Type.SetValue(Data.RingShapeType.Crescent);
                            rc.StartingAngle.SetValue((Data.FixedRandomEasingType)(int) rp.ViewingAngle.Value);
                            rc.EndingAngle.SetValue((Data.FixedRandomEasingType)(int) rp.ViewingAngle.Value);

                            rc.StartingAngle_Fixed.SetValue((360 - rp.ViewingAngle_Fixed.Value) / 2 + 90);
                            rc.EndingAngle_Fixed.SetValue(360 - (360 - rp.ViewingAngle_Fixed.Value) / 2 + 90);

                            rc.StartingAngle_Random.SetMax((360 - rp.ViewingAngle_Random.Min) / 2 + 90);
                            rc.StartingAngle_Random.SetMin((360 - rp.ViewingAngle_Random.Max) / 2 + 90);

                            rc.EndingAngle_Random.SetMax(360 - (360 - rp.ViewingAngle_Random.Max) / 2 + 90);
                            rc.EndingAngle_Random.SetMin(360 - (360 - rp.ViewingAngle_Random.Min) / 2 + 90);

                            rc.StartingAngle_Easing.Start.SetMax((360 - rp.ViewingAngle_Easing.Start.Min) / 2 + 90);
                            rc.StartingAngle_Easing.Start.SetMin((360 - rp.ViewingAngle_Easing.Start.Max) / 2 + 90);
                            rc.StartingAngle_Easing.End.SetMax((360 - rp.ViewingAngle_Easing.End.Min) / 2 + 90);
                            rc.StartingAngle_Easing.End.SetMin((360 - rp.ViewingAngle_Easing.End.Max) / 2 + 90);

                            rc.EndingAngle_Easing.Start.SetMax(360 - (360 - rp.ViewingAngle_Easing.Start.Max) / 2 + 90);
                            rc.EndingAngle_Easing.Start.SetMin(360 - (360 - rp.ViewingAngle_Easing.Start.Min) / 2 + 90);
                            rc.EndingAngle_Easing.End.SetMax(360 - (360 - rp.ViewingAngle_Easing.End.Max) / 2 + 90);
                            rc.EndingAngle_Easing.End.SetMin(360 - (360 - rp.ViewingAngle_Easing.End.Min) / 2 + 90);
                        }
                    }

                    for (int i = 0; i < n.Children.Count; i++)
                    {
                        convert(n.Children[i]);
                    }
                };

                convert(rootNode);
            }

            {
                // Fcurve
                var fcurves = Core.GetFCurveParameterNode(rootNode);

                Action <Utl.ParameterTreeNode> convert = null;
                convert = (n) =>
                {
                    foreach (var fcurve in n.Parameters)
                    {
                        var fcurve2     = fcurve.Item2 as Data.Value.FCurveVector2D;
                        var fcurve3     = fcurve.Item2 as Data.Value.FCurveVector3D;
                        var fcurvecolor = fcurve.Item2 as Data.Value.FCurveColorRGBA;

                        if (fcurve2 != null)
                        {
                            fcurve2.Timeline.SetValue(Data.Value.FCurveTimelineMode.Time);
                            if (!fcurve2.X.Sampling.IsValueAssigned)
                            {
                                fcurve2.X.Sampling.SetValue(5);
                            }
                            if (!fcurve2.Y.Sampling.IsValueAssigned)
                            {
                                fcurve2.Y.Sampling.SetValue(5);
                            }
                        }

                        if (fcurve3 != null)
                        {
                            fcurve3.Timeline.SetValue(Data.Value.FCurveTimelineMode.Time);
                            if (!fcurve3.X.Sampling.IsValueAssigned)
                            {
                                fcurve3.X.Sampling.SetValue(5);
                            }
                            if (!fcurve3.Y.Sampling.IsValueAssigned)
                            {
                                fcurve3.Y.Sampling.SetValue(5);
                            }
                            if (!fcurve3.Z.Sampling.IsValueAssigned)
                            {
                                fcurve3.Z.Sampling.SetValue(5);
                            }
                        }

                        if (fcurvecolor != null)
                        {
                            fcurvecolor.Timeline.SetValue(Data.Value.FCurveTimelineMode.Time);
                            if (!fcurvecolor.R.Sampling.IsValueAssigned)
                            {
                                fcurvecolor.R.Sampling.SetValue(5);
                            }
                            if (!fcurvecolor.G.Sampling.IsValueAssigned)
                            {
                                fcurvecolor.G.Sampling.SetValue(5);
                            }
                            if (!fcurvecolor.B.Sampling.IsValueAssigned)
                            {
                                fcurvecolor.B.Sampling.SetValue(5);
                            }
                            if (!fcurvecolor.A.Sampling.IsValueAssigned)
                            {
                                fcurvecolor.A.Sampling.SetValue(5);
                            }
                        }
                    }

                    foreach (var c in n.Children)
                    {
                        convert(c);
                    }
                };

                convert(fcurves);
            }

            return(true);
        }
Пример #24
0
 protected virtual void OnDrawNodeWindow(NodeRoot node)
 {
 }
Пример #25
0
        public override bool Update(NodeRoot rootNode)
        {
            Action <Data.NodeBase> convert = null;

            convert = (n) =>
            {
                var n_ = n as Data.Node;

                if (n_ != null && n_.DrawingValues.Type.Value == RendererValues.ParamaterType.Track)
                {
                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorLeft;
                        sc.Fixed  = n_.DrawingValues.Track.ColorLeft_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorLeft_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorLeft_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorLeft_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorLeft, text);
                    }

                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorLeftMiddle;
                        sc.Fixed  = n_.DrawingValues.Track.ColorLeftMiddle_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorLeftMiddle_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorLeftMiddle_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorLeftMiddle_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorLeftMiddle, text);
                    }

                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorCenter;
                        sc.Fixed  = n_.DrawingValues.Track.ColorCenter_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorCenter_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorCenter_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorCenter_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorCenter, text);
                    }

                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorCenterMiddle;
                        sc.Fixed  = n_.DrawingValues.Track.ColorCenterMiddle_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorCenterMiddle_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorCenterMiddle_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorCenterMiddle_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorCenterMiddle, text);
                    }

                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorRight;
                        sc.Fixed  = n_.DrawingValues.Track.ColorRight_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorRight_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorRight_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorRight_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorRight, text);
                    }

                    {
                        StandardColor sc = new StandardColor();
                        sc.Type   = n_.DrawingValues.Track.ColorRightMiddle;
                        sc.Fixed  = n_.DrawingValues.Track.ColorRightMiddle_Fixed;
                        sc.Random = n_.DrawingValues.Track.ColorRightMiddle_Random;
                        sc.Easing = n_.DrawingValues.Track.ColorRightMiddle_Easing;
                        sc.FCurve = n_.DrawingValues.Track.ColorRightMiddle_FCurve;
                        var text = Core.Copy("Temp", sc);
                        Core.Paste("Temp", n_.DrawingValues.TrailColorRightMiddle, text);
                    }
                }

                for (int i = 0; i < n.Children.Count; i++)
                {
                    convert(n.Children[i]);
                }
            };

            convert(rootNode);

            return(true);
        }
Пример #26
0
        private void DoImport()
        {
            var exePath  = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            var dataPath = string.Format("{0}\\Data", exePath);

            var data  = string.Format("{0}\\data.json", dataPath);
            var guide = string.Format("{0}\\guide.txt", dataPath);

            var fi = new FileInfo(guide);

            if (fi.Exists)
            {
                using (var stream = fi.OpenText())
                {
                    var text = stream.ReadToEnd();
                    stream.Close();

                    var lines = text.Split('\n');

                    var nodeRoot = new NodeRoot(eventAgg, this)
                    {
                        Name        = "ROOT",
                        Description = "just help instance..."
                    };
                    NodesExcel = new ObservableCollection <IFulltext>();
                    var masterDataNode = new NodeExcel(eventAgg, nodeRoot, this)
                    {
                        Name = "MasterData"
                    };
                    nodeRoot.Nodes = new ObservableCollection <IFulltext>();
                    nodeRoot.Nodes.Add(masterDataNode);
                    masterDataNode.Nodes = new ObservableCollection <IFulltext>();
                    NodesExcel.Add(masterDataNode);

                    NodeTab tab = null;

                    NodeDbTable dbTable = null;

                    foreach (var l in lines)
                    {
                        if (string.IsNullOrEmpty(l) || string.IsNullOrWhiteSpace(l))
                        {
                            continue;
                        }


                        if (l[0] == '#')
                        {
                            // starting... ->
                            tab = new NodeTab(eventAgg, masterDataNode, this)
                            {
                                Name = l.Substring(1, l.IndexOf('-') - 2), Description = l.Substring(l.IndexOf('-') + 2)
                            };
                            dbTable = new NodeDbTable(eventAgg, tab, this)
                            {
                                Name = l.Substring(1, l.IndexOf('-') - 2).Replace(" ", "")
                            };
                            tab.Nodes = new ObservableCollection <IFulltext>
                            {
                                dbTable
                            };
                            NodesExcel[0].Nodes.Add(tab);
                        }
                        else
                        {
                            var column = new NodeDbColumn(eventAgg, dbTable, this)
                            {
                                Name = (l.Substring(0, l.IndexOf('-') - 1)), Description = l.Substring(l.IndexOf('-') + 2)
                            };
                            if (tab.Nodes[0].Nodes == null)
                            {
                                tab.Nodes[0].Nodes = new ObservableCollection <IFulltext>();
                            }

                            tab.Nodes[0].Nodes.Add(column);
                        }
                    }
                }
            }
        }
Пример #27
0
        public bool ExtractFiles(string dirPath, FileInfo[] extractFiles = null)
        {
            if (!Directory.Exists(dirPath))
            {
                return(false);
            }

            if (extractFiles == null)
            {
                extractFiles = AllFiles.ToArray();
            }

            var backedupDelegate = Core.OnFileLoaded;

            try
            {
                // Extract effect files
                foreach (var file in EffectFiles)
                {
                    if (!extractFiles.Contains(file))
                    {
                        continue;
                    }

                    string filePath = Path.Combine(dirPath, file.RelativePath);

                    EfkEfc efkefc = new EfkEfc();
                    var    doc    = efkefc.Load(file.Data);
                    if (doc == null)
                    {
                        return(false);
                    }

                    Core.OnFileLoaded = (path) =>
                    {
                        string hashName = Path.GetFileName(path);
                        var    entry    = ResourceFiles.Find(r => r.HashName == hashName);
                        return((entry != null) ? entry.Data : null);
                    };

                    NodeRoot root = Core.LoadFromXml(doc, filePath);
                    if (root == null)
                    {
                        return(false);
                    }

                    // Resolve the path of dependent resources
                    var resourcePaths = Utils.Misc.FindResourcePaths(root, Binary.ExporterVersion.Latest);
                    foreach (var list in resourcePaths.All)
                    {
                        ApplyEffectDependencies(list);
                    }

                    // Write effect file
                    byte[] data = efkefc.Save(root, Core.SaveAsXmlDocument(root));
                    File.WriteAllBytes(filePath, data);
                    File.SetLastWriteTime(filePath, file.LastWriteTime);
                }

                // Extract resource files
                foreach (var file in ResourceFiles)
                {
                    if (!extractFiles.Contains(file))
                    {
                        continue;
                    }

                    string filePath        = Path.Combine(dirPath, file.RelativePath);
                    string resourceDirPath = Path.GetDirectoryName(filePath);
                    if (!Directory.Exists(resourceDirPath))
                    {
                        Directory.CreateDirectory(resourceDirPath);
                    }

                    byte[] data = ApplyResourceDependencies(file, dirPath, filePath);
                    if (data != null)
                    {
                        File.WriteAllBytes(filePath, data);
                        File.SetLastWriteTime(filePath, file.LastWriteTime);
                    }
                }
            }
            finally
            {
                Core.OnFileLoaded = backedupDelegate;
            }

            return(true);
        }
Пример #28
0
        private void SetSelectedItem(NodeRoot root, NodeBase node, SelectedNodePathViewModel pathItem, NodeType nodeType, NodeType nodeItemsType, Guid guid, bool isFromPath)
        {
            if (nodeType != NodeType.Column)
            {
                pathItem.Items = new ObservableCollection <PathItem>(node.GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null)
            {
                pathItem.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null && pathItem.Parent.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }

            if (pathItem.Parent != null && pathItem.Parent.Parent != null && pathItem.Parent.Parent.Parent != null && pathItem.Parent.Parent.Parent.Parent != null)
            {
                pathItem.Parent.Parent.Parent.Parent.Items = new ObservableCollection <PathItem>(node.GetParent().GetParent().GetParent().GetParent().GetNodes().Select(x => new PathItem(x)
                {
                    Guid = (x as NodeBase).Guid,
                    Name = (x as NodeBase).Name
                }));
            }


            if (nodeType == NodeType.Root)
            {
                //Root
                var excel = pathItem.Items.FirstOrDefault();
                pathItem.SelectedItem = excel;
                //var nodes = pathItem.Node.GetNodes();
                //var excelNode = nodes.First(e => e.Guid.Equals(excel.Guid));
                //countOfCycles = 0;
                //PathChangedSubscription().Invoke(excelNode);
            }

            if (nodeType == NodeType.Excel)
            {
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Sheet)
            {
                // Root ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Excel ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Table)
            {
                // Root ->
                var excelNode = node.GetParent().GetParent();
                pathItem.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(excelNode.Guid));
                // Excel ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Tab ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }

            if (nodeType == NodeType.Column)
            {
                // Root ->
                pathItem.Parent.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().GetParent().GetParent().Guid));
                // Excel ->
                pathItem.Parent.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().GetParent().Guid));
                // Tab ->
                pathItem.Parent.Parent.SelectedItem = pathItem.Parent.Parent.Items.FirstOrDefault(x => x.Guid.Equals(node.GetParent().Guid));
                // Table ->
                pathItem.Parent.SelectedItem = pathItem.Parent.Items.FirstOrDefault(x => x.Guid.Equals(guid));
            }
        }
Пример #29
0
    public virtual void OnGUI()
    {
        OnGuiDraw();
        Rect rect = new Rect(0, 0, position.width > 200 ? position.width : 200, position.height > 200 ?position.height:200);

        scrollPos = GUI.BeginScrollView(rect, scrollPos, new Rect(0, 0, 10000, 10000));
        Event _event = Event.current;

        mousePosition = _event.mousePosition;

        //遍历所有节点,移除无效节点
        for (int i = nodeRootList.Count - 1; i >= 0; --i)
        {
            if (nodeRootList[i].isRelease)
            {
                nodeRootList.RemoveAt(i);
            }
        }

        if (_event.button == 0)
        {
            if (_event.type == EventType.MouseDown)
            {
                int copyIndex = 0;
                cpoyNode = GetMouseInNode(out copyIndex);
            }
        }

        if (_event.button == 1)         // 鼠标右键
        {
            if (_event.type == EventType.MouseDown)
            {
                if (!makeTransitionMode)
                {
                    bool clickedOnNode = false;
                    int  selectIndex   = 0;
                    selectNode    = GetMouseInNode(out selectIndex);
                    clickedOnNode = (selectNode != null);

                    if (!clickedOnNode)
                    {
                        ShowMenu(0);
                    }
                    else
                    {
                        ShowMenu(1);
                    }
                }
            }
        }

        // 选择节点为空时,无法连线
        if (selectNode == null)
        {
            makeTransitionMode = false;
        }

        if (!makeTransitionMode)
        {
            if (_event.type == EventType.MouseUp)
            {
                selectNode = null;
            }
        }

        // 在连线状态,按下鼠标
        if (makeTransitionMode && _event.type == EventType.MouseDown)
        {
            int      selectIndex   = 0;
            NodeRoot newSelectNode = GetMouseInNode(out selectIndex);
            // 如果按下鼠标时,选中了一个节点,则将 新选中根节点 添加为 selectNode 的子节点
            if (selectNode != newSelectNode)
            {
                newSelectNode.parent = selectNode;
                selectNode.childNodeList.Add(newSelectNode);
            }

            // 取消连线状态
            makeTransitionMode = false;
            // 清空选择节点
            selectNode = null;
        }

        // 连线状态下 选择节点不为空
        if (makeTransitionMode && selectNode != null)
        {
            // 获取鼠标位置
            Rect mouseRect = new Rect(mousePosition.x, mousePosition.y, 10, 10);
            // 显示连线 从 选中节点到 鼠标位置的线
            DrawNodeCurve(selectNode.WindowRect, mouseRect);
        }

        // 开始绘制节点
        // 注意:必须在  BeginWindows(); 和 EndWindows(); 之间 调用 GUI.Window 才能显示
        BeginWindows();
        for (int i = 0; i < nodeRootList.Count; i++)
        {
            NodeRoot nodeRoot = nodeRootList[i];
            nodeRoot.WindowRect = GUI.Window(i, nodeRoot.WindowRect, DrawNodeWindow, "Node" + i);

            DrawToChildCurve(nodeRoot);
        }
        EndWindows();

        // 重新绘制
        Repaint();

        GUI.EndScrollView();
    }
Пример #30
0
        public LocalSearchModel Get(string problema, string algoritmo, string versao, string iteracao)
        {
            var pathRoot  = _env.ContentRootPath;
            var pathDados = Path.Combine(pathRoot, $"dados\\{problema}\\{versao}");
            var pathArquivoConfiguracoes = Path.Combine(pathRoot, $"dados\\configuracoes\\{problema}-configuracao-{versao}.cfg");

            var textoArquivoConfig = System.IO.File.ReadAllText(Path.Combine(pathRoot, pathArquivoConfiguracoes));
            var configuracao       = JsonSerializer.Deserialize <Configuracao>(textoArquivoConfig, new JsonSerializerOptions {
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            });
            var coordenadas = new List <NodeModel>();

            if (!string.IsNullOrEmpty(configuracao.ArquivoCidades))
            {
                foreach (string linha in System.IO.File.ReadAllLines(Path.Combine(pathRoot, configuracao.ArquivoCidades)))
                {
                    var coords = linha.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    coordenadas.Add(new NodeModel {
                        X = double.Parse(coords[0], System.Globalization.CultureInfo.GetCultureInfo("en-US")), Y = double.Parse(coords[1], System.Globalization.CultureInfo.GetCultureInfo("en-US"))
                    });
                }
            }

            NodeRoot        primeiroNode = null;
            NodeRoot        bestNode     = null;
            NodeRoot        ultimoNode   = null;
            List <Execucao> execucoes    = null;

            if (!string.IsNullOrEmpty(problema) && !string.IsNullOrEmpty(algoritmo) && !string.IsNullOrEmpty(iteracao))
            {
                var pathArquivo  = $"{algoritmo}-{iteracao}.dat";
                var textoArquivo = System.IO.File.ReadAllText(Path.Combine(pathDados, pathArquivo));

                execucoes = JsonSerializer.Deserialize <List <Execucao> >(textoArquivo, new JsonSerializerOptions {
                    PropertyNamingPolicy = JsonNamingPolicy.CamelCase
                });
                primeiroNode = execucoes.First().Atual.Root;
                bestNode     = execucoes.First(x => x.Atual.Root.Best == x.Atual.Root.Value).Atual.Root;
                ultimoNode   = execucoes.Last().Atual.Root;
            }

            var bestNodeModel  = _mapper.Map <NodeRootModel>(bestNode);
            var execucoesModel = _mapper.Map <List <ExecucaoModel> >(execucoes.Select(p => p).ToList());

            _cache.Remove(CACHE_KEY);
            var entry = _cache.Set(CACHE_KEY, execucoesModel);

            var model = new LocalSearchModel
            {
                Algoritmo            = algoritmo,
                Problema             = problema,
                Estado               = bestNodeModel.State,
                Valor                = primeiroNode.Best,
                ValorInicial         = primeiroNode.Value,
                ValorFinal           = ultimoNode.Best,
                PopulacaoInicial     = _mapper.Map <List <NodeModel> >(primeiroNode.Populacao),
                Coordenadas          = coordenadas,
                Execucoes            = execucoesModel.Skip(0).Take(1000).ToList(),
                NumeroTotalExecucoes = execucoesModel.Count
            };

            return(model);
        }