예제 #1
0
        public void Build(IEnumerable <GraphAssetModel> vsGraphAssetModels, Action <string, CompilerMessage[]> roslynCompilationOnBuildFinished)
        {
            VseUtility.RemoveLogEntries();
            foreach (GraphAssetModel vsGraphAssetModel in vsGraphAssetModels)
            {
                VSGraphModel graphModel = (VSGraphModel)vsGraphAssetModel.GraphModel;
                var          t          = graphModel.Stencil.CreateTranslator();

                try
                {
                    // important for codegen, otherwise most of it will be skipped
                    graphModel.Stencil.PreProcessGraph(graphModel);
                    var result         = t.TranslateAndCompile(graphModel, AssemblyType.Source, CompilationOptions.Default);
                    var graphAssetPath = AssetDatabase.GetAssetPath(vsGraphAssetModel);
                    foreach (var error in result.errors)
                    {
                        VseUtility.LogSticky(LogType.Error, LogOption.None, error.ToString(), graphAssetPath, vsGraphAssetModel.GetInstanceID());
                    }
                }
                catch (Exception e)
                {
                    Debug.LogWarning(e);
                }
            }

            AssetDatabase.Refresh();
        }
예제 #2
0
        public static GraphElementSearcherDatabase AddEcsControlFlows(this GraphElementSearcherDatabase db)
        {
            db.AddIfCondition(GraphElementSearcherDatabase.IfConditionMode.Basic);
            db.AddIfCondition(GraphElementSearcherDatabase.IfConditionMode.Advanced);
            db.AddIfCondition(GraphElementSearcherDatabase.IfConditionMode.Complete);

            var loopTypes = TypeCache.GetTypesDerivedFrom <LoopStackModel>()
                            .Where(t => !t.IsAbstract && !(t == typeof(CoroutineStackModel)))
                            .Concat(TypeCache.GetTypesDerivedFrom <ICoroutine>().Where(t => t.AssemblyQualifiedName != null &&
                                                                                       !t.AssemblyQualifiedName.Contains("VisualScripting.Ecs.Editor.Tests")));

            foreach (var loopType in loopTypes)
            {
                var isCoroutine = typeof(ICoroutine).IsAssignableFrom(loopType);
                var name        = isCoroutine ? VseUtility.GetTitle(loopType) : $"{VseUtility.GetTitle(loopType)}{k_LoopStack}";

                db.Items.AddAtPath(new StackNodeModelSearcherItem(
                                       new ControlFlowSearcherItemData(loopType),
                                       data =>
                {
                    var stackModel    = (StackBaseModel)data.StackModel;
                    var graphModel    = (VSGraphModel)stackModel.GraphModel;
                    var stackPosition = stackModel.Position + k_StackOffset;
                    var type          = isCoroutine ? typeof(CoroutineStackModel) : loopType;
                    var guidIndex     = 0;

                    var loopStack = graphModel.CreateLoopStack(
                        type,
                        stackPosition,
                        data.SpawnFlags,
                        data.GuidAt(guidIndex++));

                    var loopNode = loopStack.CreateLoopNode(
                        stackModel,
                        data.Index,
                        data.SpawnFlags,
                        PredefineSetup,
                        data.GuidAt(guidIndex));

                    var edge = data.SpawnFlags.IsOrphan()
                            ? graphModel.CreateOrphanEdge(loopStack.InputPort, loopNode.OutputPort)
                            : graphModel.CreateEdge(loopStack.InputPort, loopNode.OutputPort);

                    return(new IGraphElementModel[] { loopNode, loopStack, edge });

                    void PredefineSetup(NodeModel model)
                    {
                        if (model is CoroutineNodeModel coroutineNodeModel)
                        {
                            coroutineNodeModel.CoroutineType = loopType.GenerateTypeHandle(db.Stencil);
                        }
                    }
                },
                                       name),
                                   k_ControlFlow);
            }

            return(db);
        }
예제 #3
0
        public GraphElementSearcherDatabase AddControlFlows()
        {
            AddIfCondition(IfConditionMode.Basic);
            AddIfCondition(IfConditionMode.Advanced);
            AddIfCondition(IfConditionMode.Complete);

            SearcherItem parent    = null;
            var          loopTypes = TypeCache.GetTypesDerivedFrom <LoopStackModel>();

            foreach (var loopType in loopTypes.Where(t => !t.IsAbstract))
            {
                if (parent == null)
                {
                    parent = SearcherItemUtility.GetItemFromPath(Items, k_ControlFlow);
                }

                var name = $"{VseUtility.GetTitle(loopType)}{k_LoopStack}";
                parent.AddChild(new StackNodeModelSearcherItem(
                                    new ControlFlowSearcherItemData(loopType),
                                    data =>
                {
                    var stackModel = (StackBaseModel)data.StackModel;
                    var elements   = new List <IGraphElementModel>();

                    var graphModel    = (VSGraphModel)stackModel.GraphModel;
                    var stackPosition = new Vector2(
                        stackModel.Position.x + k_StackOffset.x,
                        stackModel.Position.y + k_StackOffset.y
                        );

                    LoopStackModel loopStack = graphModel.CreateLoopStack(
                        loopType,
                        stackPosition,
                        data.SpawnFlags
                        );

                    var node = loopStack.CreateLoopNode(
                        stackModel,
                        data.Index,
                        data.SpawnFlags);

                    elements.Add(node);
                    elements.Add(loopStack);

                    var edge = data.SpawnFlags.IsOrphan()
                            ? graphModel.CreateOrphanEdge(loopStack.InputPort, node.OutputPort)
                            : graphModel.CreateEdge(loopStack.InputPort, node.OutputPort);
                    elements.Add(edge);

                    return(elements.ToArray());
                },
                                    name
                                    ));
            }

            return(this);
        }
예제 #4
0
        static void CreateNewStruct(StructType structType)
        {
            string uniqueFilePath = VseUtility.GetUniqueAssetPathNameInActiveFolder("Component.cs");
            string modelName      = Path.GetFileName(uniqueFilePath);

            var endAction = CreateInstance <DoCreateComponent>();

            endAction.StructType = structType;
            ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, endAction, modelName, null, null);
        }
예제 #5
0
        public override List <TitleComponent> BuildTitle()
        {
            var connection    = InputPort.ConnectionPortModels.FirstOrDefault(p => p.NodeModel is CoroutineNodeModel);
            var coroutineType = ((CoroutineNodeModel)connection?.NodeModel)?.CoroutineType ?? TypeHandle.Unknown;

            var title = InputPort.Connected && !coroutineType.Equals(TypeHandle.Unknown)
                ? $"On {VseUtility.GetTitle(coroutineType.Resolve(Stencil))}"
                : "On Coroutine";

            return(new List <TitleComponent>
            {
                new TitleComponent
                {
                    titleComponentType = TitleComponentType.String,
                    titleObject = title
                }
            });
        }
예제 #6
0
        internal static MethodDetails GetMethodDetails(this MethodBase methodBase)
        {
            string menuName       = VseUtility.GetTitle(methodBase);
            string detailsPostFix = " (";
            string postFix        = "";
            bool   comma          = false;

            foreach (ParameterInfo parameterInfo in methodBase.GetParameters())
            {
                if (comma)
                {
                    detailsPostFix += ", ";
                    postFix        += ", ";
                }

                detailsPostFix += parameterInfo.ParameterType.FriendlyName() + " " + parameterInfo.Name;
                postFix        += parameterInfo.ParameterType.FriendlyName();
                comma           = true;
            }

            detailsPostFix += ")";

            MethodInfo methodInfo = methodBase as MethodInfo;

            if (methodInfo != null && methodInfo.ReturnType != typeof(void))
            {
                detailsPostFix += " => " + methodInfo.ReturnType.FriendlyName();
            }

            string className  = methodBase.DeclaringType.FriendlyName(false).Nicify();
            string methodName = $"{menuName} ({postFix})";
            string details    = methodBase.IsConstructor
                ? $"Create {className}"
                : (methodBase.IsStatic ? "Static " : "") + className + "." + menuName + detailsPostFix;

            return(new MethodDetails(className, methodName, details));
        }