Exemple #1
0
        private void LoadStates()
        {
            if (fsmData.canvasControls == null)
            {
                fsmData.nodes          = new List <UINode>();
                fsmData.canvasControls = new Controls();
                foreach (FsmStateData stateData in fsmData.states)
                {
                    FsmNodeData node   = stateData.node;
                    UINode      uiNode = new UINode(stateData, node);

                    uiNode.grid.PointerPressed += (object sender, PointerPressedEventArgs e) =>
                    {
                        if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
                        {
                            return;
                        }

                        foreach (UINode uiNode2 in fsmData.nodes)
                        {
                            uiNode2.Selected = false;
                        }
                        uiNode.Selected = true;
                        StateSidebarData(stateData);
                    };

                    graphCanvas.Children.Add(uiNode.grid);
                    fsmData.nodes.Add(uiNode);

                    PlaceTransitions(node, false);
                }
                foreach (FsmNodeData globalTransition in fsmData.globalTransitions)
                {
                    FsmNodeData node   = globalTransition;
                    UINode      uiNode = new UINode(null, node);

                    graphCanvas.Children.Add(uiNode.grid);
                    fsmData.nodes.Add(uiNode);

                    PlaceTransitions(node, true);
                }
                fsmData.canvasControls.AddRange(graphCanvas.Children);
            }
            else
            {
                graphCanvas.Children.Clear();
                graphCanvas.Children.AddRange(fsmData.canvasControls);
            }
        }
Exemple #2
0
        public static Point ComputeLocation(FsmNodeData node1, FsmNodeData node2, float yPos, out bool isLeft)
        {
            Rect   nodetfm1 = node1.transform;
            Rect   nodetfm2 = node2.transform;
            double midx1    = nodetfm1.X + nodetfm1.Width / 2;
            double midx2    = nodetfm2.X + nodetfm2.Width / 2;
            double midy1    = nodetfm1.Y + nodetfm1.Height / 2;
            double midy2    = nodetfm2.Y + nodetfm2.Height / 2;

            Point loc = new Point(
                nodetfm1.X + nodetfm1.Width / 2,
                nodetfm1.Y + yPos
                );

            if (midx1 == midx2)
            {
                isLeft = true;
            }
            else
            {
                if (Math.Abs(midx1 - midx2) * 2 < nodetfm1.Width + nodetfm2.Width)
                {
                    if (midy2 > midy1)
                    {
                        isLeft = midx1 < midx2;
                    }
                    else
                    {
                        isLeft = midx1 > midx2;
                    }
                }
                else
                {
                    isLeft = midx1 < midx2;
                }
            }

            if (isLeft)
            {
                loc = new Point(loc.X + nodetfm1.Width / 2, loc.Y);
            }
            else
            {
                loc = new Point(loc.X - nodetfm1.Width / 2, loc.Y);
            }

            return(loc);
        }
Exemple #3
0
        public FsmNodeData(FsmDataInstance dataInst, FsmGlobalTransition transition)
        {
            isGlobal = true;
            FsmStateData toState = dataInst.states.FirstOrDefault(s => s.state.name == transition.toState);

            if (toState != null)
            {
                FsmNodeData toNode = toState.node;
                transform = new Rect(toNode.transform.X, toNode.transform.Y - 50, toNode.transform.Width, 18);
            }
            else
            {
                transform = new Rect(-100, -100, 100, 18);
            }

            stateColor      = Constants.STATE_COLORS[transition.colorIndex];
            transitionColor = Constants.TRANSITION_COLORS[transition.colorIndex];
            name            = transition.fsmEvent.name;
            transitions     = new FsmTransition[1]
            {
                new FsmTransition(transition)
            };
        }
Exemple #4
0
        public FsmDataInstance LoadFSM(long id)
        {
            AssetFileInfoEx     info      = curFile.table.GetAssetInfo(id);
            AssetTypeValueField baseField = am.GetMonoBaseFieldCached(curFile, info, Path.Combine(Path.GetDirectoryName(curFile.path), "Managed"));
            AssetNameResolver   namer     = new AssetNameResolver(am, curFile);

            FsmDataInstance dataInstance = new FsmDataInstance();

            AssetTypeValueField fsm               = baseField.Get("fsm");
            AssetTypeValueField states            = fsm.Get("states");
            AssetTypeValueField events            = fsm.Get("events");
            AssetTypeValueField variables         = fsm.Get("variables");
            AssetTypeValueField globalTransitions = fsm.Get("globalTransitions");
            AssetTypeValueField dataVersionField  = fsm.Get("dataVersion");

            dataInstance.fsmName = fsm.Get("name").GetValue().AsString();

            AssetTypeInstance goAti = am.GetExtAsset(curFile, baseField.Get("m_GameObject")).instance;

            if (goAti != null)
            {
                string m_Name = goAti.GetBaseField().Get("m_Name").GetValue().AsString();
                dataInstance.goName = m_Name;
            }

            if (dataVersionField.IsDummy())
            {
                dataInstance.dataVersion = fsm.Get("version").GetValue().AsInt() + 1;
            }
            else
            {
                dataInstance.dataVersion = dataVersionField.GetValue().AsInt();
            }

            dataInstance.states = new List <FsmStateData>();
            for (int i = 0; i < states.GetChildrenCount(); i++)
            {
                FsmStateData stateData = new FsmStateData();
                stateData.ActionData = new List <ActionScriptEntry>();
                stateData.state      = new FsmState(namer, states[i]);
                stateData.node       = new FsmNodeData(stateData.state);

                GetActionData(stateData.ActionData, stateData.state.actionData, dataInstance.dataVersion);

                dataInstance.states.Add(stateData);
            }

            dataInstance.events = new List <FsmEventData>();
            for (int i = 0; i < events.GetChildrenCount(); i++)
            {
                FsmEventData eventData = new FsmEventData();
                eventData.Global = events[i].Get("isGlobal").GetValue().AsBool();
                eventData.Name   = events[i].Get("name").GetValue().AsString();

                dataInstance.events.Add(eventData);
            }

            dataInstance.variables = new List <FsmVariableData>();
            GetVariableValues(dataInstance.variables, namer, variables);

            dataInstance.globalTransitions = new List <FsmNodeData>();
            for (int i = 0; i < globalTransitions.GetChildrenCount(); i++)
            {
                AssetTypeValueField globalTransitionField = globalTransitions[i];
                FsmGlobalTransition globalTransition      = new FsmGlobalTransition()
                {
                    fsmEvent       = new FsmEvent(globalTransitionField.Get("fsmEvent")),
                    toState        = globalTransitionField.Get("toState").GetValue().AsString(),
                    linkStyle      = globalTransitionField.Get("linkStyle").GetValue().AsInt(),
                    linkConstraint = globalTransitionField.Get("linkConstraint").GetValue().AsInt(),
                    colorIndex     = (byte)globalTransitionField.Get("colorIndex").GetValue().AsInt()
                };

                FsmNodeData node = new FsmNodeData(dataInstance, globalTransition);
                dataInstance.globalTransitions.Add(node);
            }

            //dataInstance.events = new List<FsmEventData>();
            //for (int i = 0; i < events.GetChildrenCount(); i++)
            //{
            //    FsmEventData eventData = new FsmEventData();
            //    AssetTypeValueField evt = events[i];
            //    eventData.Name = evt.Get("name").GetValue().AsString();
            //    eventData.Global = evt.Get("isGlobal").GetValue().AsBool();
            //}
            //
            //dataInstance.variables = new List<FsmVariableData>();
            //for (int i = 0; i < variables.GetChildrenCount(); i++)
            //{
            //    FsmVariableData variableData = new FsmVariableData();
            //    AssetTypeValueField vars = events[i];
            //}

            return(dataInstance);
        }
Exemple #5
0
        private async void PlaceTransitions(FsmNodeData node, bool global)
        {
            float yPos = 27;

            foreach (FsmTransition trans in node.transitions)
            {
                try
                {
                    FsmStateData endState = fsmData.states.FirstOrDefault(s => s.node.name == trans.toState);
                    if (endState != null)
                    {
                        FsmNodeData endNode = endState.node;

                        Point start, end, startMiddle, endMiddle;

                        if (!global)
                        {
                            start = ArrowUtil.ComputeLocation(node, endNode, yPos, out bool isLeftStart);
                            end   = ArrowUtil.ComputeLocation(endNode, node, 10, out bool isLeftEnd);

                            double dist = 40;

                            if (isLeftStart == isLeftEnd)
                            {
                                dist *= 0.5;
                            }

                            if (!isLeftStart)
                            {
                                startMiddle = new Point(start.X - dist, start.Y);
                            }
                            else
                            {
                                startMiddle = new Point(start.X + dist, start.Y);
                            }

                            if (!isLeftEnd)
                            {
                                endMiddle = new Point(end.X - dist, end.Y);
                            }
                            else
                            {
                                endMiddle = new Point(end.X + dist, end.Y);
                            }
                        }
                        else
                        {
                            start = new Point(node.transform.X + node.transform.Width / 2,
                                              node.transform.Y + node.transform.Height / 2);
                            end = new Point(endNode.transform.X + endNode.transform.Width / 2,
                                            endNode.transform.Y);
                            startMiddle = new Point(start.X, start.Y + 1);
                            endMiddle   = new Point(end.X, end.Y - 1);
                        }

                        Color           color = Constants.TRANSITION_COLORS[trans.colorIndex];
                        SolidColorBrush brush = new SolidColorBrush(color);

                        Path line = ArrowUtil.CreateLine(start, startMiddle, endMiddle, end, brush);

                        line.PointerMoved += (object sender, PointerEventArgs e) =>
                        {
                            line.Stroke = Brushes.Black;
                        };

                        line.PointerLeave += (object sender, PointerEventArgs e) =>
                        {
                            line.Stroke = brush;
                        };

                        line.ZIndex = -1;

                        graphCanvas.Children.Add(line);
                    }
                    yPos += 16;
                }
                catch (Exception ex)
                {
                    var messageBoxStandardWindow = MessageBoxManager
                                                   .GetMessageBoxStandardWindow("Exception", ex.ToString());
                    await messageBoxStandardWindow.Show();
                }
            }
        }