コード例 #1
0
        public bool OnSelectEntry(SearchTreeEntry entry, SearchWindowContext context)
        {
            if (entry is SearchTreeGroupEntry)
            {
                return(false);
            }

            var actorConfig = (ActorConfig)entry.userData;
            var actorSetup  = ActorSystemSetupAnalyzer.CreateActorSetup(actorConfig);

            m_Asset.ActorSetups.Add(actorSetup);

            foreach (var inputConfig in actorConfig.InputConfigs)
            {
                var isValid = MultiplicityValidator.IsValid(m_Asset.ComponentConfigs.First(x => x.Id == inputConfig.ComponentConfigId).InputMultiplicity, 0);
                actorSetup.Inputs.Add(new ActorPort(Guid.NewGuid().ToString(), inputConfig.Id, new List <ActorLink>(), isValid, false));
            }

            foreach (var outputConfig in actorConfig.OutputConfigs)
            {
                var isValid = MultiplicityValidator.IsValid(m_Asset.ComponentConfigs.First(x => x.Id == outputConfig.ComponentConfigId).OutputMultiplicity, 0);
                actorSetup.Outputs.Add(new ActorPort(Guid.NewGuid().ToString(), outputConfig.Id, new List <ActorLink>(), isValid, false));
            }

            var node = CreateNode(actorSetup);

            var pointInWindow = context.screenMousePosition - position.position;
            var pointInGraph  = node.parent.WorldToLocal(pointInWindow);

            node.SetPosition(new Rect(pointInGraph, Vector2.zero));
            actorSetup.Position = pointInGraph;

            return(true);
        }
コード例 #2
0
        public static ActorSetup CreateActorSetup <T>(this ActorSystemSetup actorSystemSetup)
        {
            var actorConfig = actorSystemSetup.GetActorConfig <T>();
            var actorSetup  = actorConfig.CreateActorSetup();

            actorSystemSetup.ActorSetups.Add(actorSetup);
            foreach (var inputConfig in actorConfig.InputConfigs)
            {
                var isValid = MultiplicityValidator.IsValid(actorSystemSetup.ComponentConfigs.First(x => x.Id == inputConfig.ComponentConfigId).InputMultiplicity, 0);
                actorSetup.Inputs.Add(new ActorPort(Guid.NewGuid().ToString(), inputConfig.Id, new List <ActorLink>(), isValid, false));
            }
            foreach (var outputConfig in actorConfig.OutputConfigs)
            {
                var isValid = MultiplicityValidator.IsValid(actorSystemSetup.ComponentConfigs.First(x => x.Id == outputConfig.ComponentConfigId).OutputMultiplicity, 0);
                actorSetup.Outputs.Add(new ActorPort(Guid.NewGuid().ToString(), outputConfig.Id, new List <ActorLink>(), isValid, false));
            }
            return(actorSetup);
        }
コード例 #3
0
        GraphViewChange GraphViewChanged(GraphViewChange graphViewChange)
        {
            if (graphViewChange.elementsToRemove != null)
            {
                foreach (var element in graphViewChange.elementsToRemove)
                {
                    if (element is Node)
                    {
                        var setup = (ActorSetup)element.userData;
                        m_Asset.ActorSetups.Remove(setup);
                    }
                    else if (element is CustomEdge edge)
                    {
                        if (edge.userData is ActorLink link)
                        {
                            var inputSetup  = (ActorSetup)edge.input.node.userData;
                            var outputSetup = (ActorSetup)edge.output.node.userData;

                            var input = inputSetup.Inputs.FirstOrDefault(x => x.Id == link.InputId);
                            input?.Links.Remove(link);
                            var output = outputSetup.Outputs.FirstOrDefault(x => x.Id == link.OutputId);
                            output?.Links.Remove(link);

                            if (input != null)
                            {
                                var inputActorConfig     = m_Asset.ActorConfigs.First(x => x.Id == inputSetup.ConfigId);
                                var inputConfig          = inputActorConfig.InputConfigs.First(x => x.Id == input.ConfigId);
                                var inputComponentConfig = m_Asset.ComponentConfigs.First(x => x.Id == inputConfig.ComponentConfigId);
                                var inputMultiplicity    = inputComponentConfig.InputMultiplicity;
                                input.IsValid = MultiplicityValidator.IsValid(inputMultiplicity, input.Links.Count);
                                SetPortColor(edge.input, input);
                            }

                            if (output != null)
                            {
                                var outputActorConfig     = m_Asset.ActorConfigs.First(x => x.Id == outputSetup.ConfigId);
                                var outputConfig          = outputActorConfig.OutputConfigs.First(x => x.Id == output.ConfigId);
                                var outputComponentConfig = m_Asset.ComponentConfigs.First(x => x.Id == outputConfig.ComponentConfigId);
                                var outputMultiplicity    = outputComponentConfig.OutputMultiplicity;
                                output.IsValid = MultiplicityValidator.IsValid(outputMultiplicity, output.Links.Count);
                                SetPortColor(edge.output, output);
                            }
                        }
                    }
                    RemoveElement(element);
                }
            }

            if (graphViewChange.edgesToCreate != null)
            {
                foreach (var e in graphViewChange.edgesToCreate)
                {
                    var edge   = (CustomEdge)e;
                    var input  = (ActorPort)edge.input.userData;
                    var output = (ActorPort)edge.output.userData;

                    var link = new ActorLink(output.Id, input.Id, output.IsRemoved || input.IsRemoved);
                    input.Links.Add(link);
                    output.Links.Add(link);

                    edge.userData = link;
                    if (link.IsRemoved)
                    {
                        edge.EdgeState = EdgeState.Deleted;
                    }

                    if (!link.IsRemoved)
                    {
                        if (!input.IsRemoved)
                        {
                            var inputSetup           = (ActorSetup)edge.input.node.userData;
                            var inputActorConfig     = m_Asset.ActorConfigs.First(x => x.Id == inputSetup.ConfigId);
                            var inputConfig          = inputActorConfig.InputConfigs.First(x => x.Id == input.ConfigId);
                            var inputComponentConfig = m_Asset.ComponentConfigs.First(x => x.Id == inputConfig.ComponentConfigId);
                            var inputMultiplicity    = inputComponentConfig.InputMultiplicity;
                            input.IsValid = MultiplicityValidator.IsValid(inputMultiplicity, input.Links.Count);
                            SetPortColor(edge.input, input);
                        }

                        if (!output.IsRemoved)
                        {
                            var outputSetup           = (ActorSetup)edge.output.node.userData;
                            var outputActorConfig     = m_Asset.ActorConfigs.First(x => x.Id == outputSetup.ConfigId);
                            var outputConfig          = outputActorConfig.OutputConfigs.First(x => x.Id == output.ConfigId);
                            var outputComponentConfig = m_Asset.ComponentConfigs.First(x => x.Id == outputConfig.ComponentConfigId);
                            var outputMultiplicity    = outputComponentConfig.OutputMultiplicity;
                            output.IsValid = MultiplicityValidator.IsValid(outputMultiplicity, output.Links.Count);
                            SetPortColor(edge.output, output);
                        }
                    }

                    AddElement(edge, true);
                }
            }

            if (graphViewChange.movedElements != null)
            {
                foreach (var element in graphViewChange.movedElements)
                {
                    if (element is Node)
                    {
                        ((ActorSetup)element.userData).Position = element.GetPosition().position;
                    }
                }
            }

            return(graphViewChange);
        }