Exemplo n.º 1
0
        private void StateSidebarData(FsmStateData stateData)
        {
            stateList.Children.Clear();
            var entries = stateData.ActionData;

            for (int i = 0; i < entries.Count; i++)
            {
                var    entry      = entries[i];
                string actionName = entry.Name;
                var    fields     = entry.Values;

                stateList.Children.Add(CreateSidebarHeader(actionName, i, entry.Enabled));

                foreach (var field in fields)
                {
                    string key         = field.Item1;
                    object value       = field.Item2;
                    string valueString = value.ToString();

                    if (value is bool)
                    {
                        valueString = valueString.ToLower();
                    }

                    stateList.Children.Add(CreateSidebarRow(key, valueString, entry.Enabled));
                }
            }
        }
Exemplo n.º 2
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)
            };
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
                }
            }
        }