示例#1
0
        public static SystemGraphState GetStateForWorld(World world, ref List <SystemGraphState> stateForWorlds,
                                                        ref List <string> worldNames)
        {
            if (world == null)
            {
                return(new SystemGraphState());
            }

            if (stateForWorlds == null)
            {
                stateForWorlds = new List <SystemGraphState>();
                worldNames     = new List <string>();
            }
            var currentWorldName = world.Name;

            SystemGraphState stateForCurrentWorld = null;

            for (var i = 0; i < stateForWorlds.Count; ++i)
            {
                if (worldNames[i] == currentWorldName)
                {
                    stateForCurrentWorld = stateForWorlds[i];
                    break;
                }
            }
            if (stateForCurrentWorld == null)
            {
                stateForCurrentWorld = new SystemGraphState();
                stateForWorlds.Add(stateForCurrentWorld);
                worldNames.Add(currentWorldName);
            }
            return(stateForCurrentWorld);
        }
        private MsaglNode AddNode(SystemViewData view, SystemGraphState state)
        {
            ICurve    curve   = CurveFactory.CreateRectangle(view.position.width, view.position.height, new Point());
            MsaglNode newNode = new MsaglNode(curve, state.systemViews.IndexOf(view).ToString())
            {
                UserData = view
            };

            resultGraph.Nodes.Add(newNode);
            return(newNode);
        }
示例#3
0
        public void SetSystemsAndState(Type[] systemTypes, SystemGraphState savedState)
        {
            state = savedState;

            var systemViewIndicesByType = new Dictionary <Type, int>();

            if (systemTypes != null)
            {
                foreach (var type in systemTypes)
                {
                    var systemViewIndex = state.systemViews.FindIndex(x => x.fullName == type.FullName);
                    if (systemViewIndex < 0)
                    {
                        var size = GUI.skin.label.CalcSize(new GUIContent(type.Name));
                        state.systemViews.Add(new SystemViewData(type.Name, type.FullName, new Rect(Vector2.zero, size)));
                        systemViewIndex = state.systemViews.Count - 1;
                    }
                    state.systemViews[systemViewIndex].updateAfter  = new List <int>();
                    state.systemViews[systemViewIndex].updateBefore = new List <int>();
                    systemViewIndicesByType.Add(type, systemViewIndex);
                }
                foreach (var systemType in systemTypes)
                {
                    var systemView = state.systemViews[systemViewIndicesByType[systemType]];
                    foreach (var attribute in systemType.GetCustomAttributesData())
                    {
                        if (attribute.AttributeType == typeof(UpdateAfterAttribute))
                        {
                            var type = (Type)attribute.ConstructorArguments[0].Value;
                            if (systemViewIndicesByType.ContainsKey(type))
                            {
                                systemView.updateAfter.Add(systemViewIndicesByType[type]);
                            }
                        }
                        if (attribute.AttributeType == typeof(UpdateBeforeAttribute))
                        {
                            var type = (Type)attribute.ConstructorArguments[0].Value;
                            if (systemViewIndicesByType.ContainsKey(type))
                            {
                                systemView.updateBefore.Add(systemViewIndicesByType[type]);
                            }
                        }
                    }
                }
            }
            GraphLayout();
        }
        public MsaglGraphAdapter(SystemGraphState state)
        {
            var nodes = new List <MsaglNode>();

            state.systemViews.ForEach(node =>
            {
                nodes.Add(AddNode(node, state));
            });

            for (var i = 0; i < state.systemViews.Count; ++i)
            {
                var view = state.systemViews[i];
                var node = nodes[i];
                view.updateAfter.ForEach(otherId =>
                {
                    AddEdge(node, nodes[otherId]);
                });
                view.updateBefore.ForEach(otherId =>
                {
                    AddEdge(nodes[otherId], node);
                });
            }
        }