コード例 #1
0
        static State RefactorExtractMacro(State previousState, RefactorExtractMacroAction action)
        {
            var        graphModel = (VSGraphModel)previousState.CurrentGraphModel;
            INodeModel newMacro;

            using (new AssetWatcher.Scope())
            {
                var assetName = string.IsNullOrEmpty(action.MacroPath)
                    ? null
                    : Path.GetFileNameWithoutExtension(action.MacroPath);
                var macroGraphAssetModel = (VSGraphAssetModel)GraphAssetModel.Create(
                    assetName, action.MacroPath, typeof(VSGraphAssetModel));
                var macroGraph = macroGraphAssetModel.CreateVSGraph <MacroStencil>(assetName);

                // A MacroStencil cannot be a parent stencil, so use its parent instead
                var parentGraph = graphModel.Stencil is MacroStencil macroStencil
                    ? macroStencil.ParentType
                    : graphModel.Stencil.GetType();

                ((MacroStencil)macroGraph.Stencil).SetParent(parentGraph, macroGraph);
                Utility.SaveAssetIntoObject((Object)macroGraph.AssetModel, macroGraphAssetModel);
                newMacro = graphModel.ExtractNodesAsMacro(macroGraph, action.Position, action.Selection);
                AssetDatabase.SaveAssets();
            }
            previousState.EditorDataModel.ElementModelToRename = newMacro;
            previousState.MarkForUpdate(UpdateFlags.GraphTopology);
            return(previousState);
        }
        static State CreateGraphAsset(State previousState, CreateGraphAssetAction action)
        {
            previousState.AssetModel?.Dispose();
            using (new AssetWatcher.Scope())
            {
                GraphAssetModel graphAssetModel = GraphAssetModel.Create(action.Name, action.AssetPath, action.AssetType, action.WriteOnDisk);

                var graphModel = graphAssetModel.CreateGraph(action.GraphType, action.Name, action.StencilType, action.WriteOnDisk);
                if (action.GraphTemplate != null)
                {
                    action.GraphTemplate.InitBasicGraph(graphModel as VSGraphModel);
                    graphModel.LastChanges.ModelsToAutoAlign.AddRange(graphModel.Stencil.GetEntryPoints((VSGraphModel)graphModel));
                }

                previousState.AssetModel = graphAssetModel;
                if (action.Instance)
                {
                    previousState.EditorDataModel.BoundObject = action.Instance;
                }
            }
            if (action.WriteOnDisk)
            {
                AssetDatabase.SaveAssets();
            }

            AssetWatcher.Instance.WatchGraphAssetAtPath(action.AssetPath, (GraphAssetModel)previousState.AssetModel);
            previousState.MarkForUpdate(UpdateFlags.All);


            return(previousState);
        }
コード例 #3
0
        static State CreateGraphAsset(State previousState, CreateGraphAssetAction action)
        {
            previousState.AssetModel?.Dispose();
            using (new AssetWatcher.Scope())
            {
                GraphAssetModel graphAssetModel = GraphAssetModel.Create(action.Name, action.AssetPath, action.AssetType, action.WriteOnDisk);

                var graphModel = graphAssetModel.CreateGraph <VSGraphModel>(action.Name, action.GraphType, action.WriteOnDisk);
                if (action.GraphTemplate != null)
                {
                    action.GraphTemplate.InitBasicGraph(graphModel);
                    previousState.requestNodeAlignment = true;
                }

                previousState.AssetModel = graphAssetModel;
                if (action.Instance)
                {
                    previousState.EditorDataModel.BoundObject = action.Instance;
                }
            }
            if (action.WriteOnDisk)
            {
                AssetDatabase.SaveAssets();
            }

            previousState.MarkForUpdate(UpdateFlags.All);

            return(previousState);
        }
コード例 #4
0
        private void GenerateNodeDoc()
        {
            const string docPath = UIHelper.NodeDocumentationPath;

            if (Directory.Exists(docPath))
            {
                foreach (var enumerateFile in Directory.EnumerateFiles(docPath, "*.md", SearchOption.AllDirectories))
                {
                    File.Delete(enumerateFile);
                }
            }
            Directory.CreateDirectory(docPath);

            var gam = GraphAssetModel.Create("Doc", null, typeof(VSGraphAssetModel), false);
            var stateCurrentGraphModel = gam.CreateGraph <VSGraphModel>("Doc", typeof(DotsStencil), false);
            var stencil    = stateCurrentGraphModel.Stencil;
            var dbProvider = stencil.GetSearcherDatabaseProvider();
            var dbs        = dbProvider.GetGraphElementsSearcherDatabases();

            HashSet <string> fileNames = new HashSet <string>();

            foreach (var searcherItem in dbs[0].ItemList.OfType <GraphNodeModelSearcherItem>())
            {
                var graphElementModels = GraphNodeSearcherAdapter.CreateGraphElementModels(stateCurrentGraphModel, searcherItem);
                if (graphElementModels.Count() != 1)
                {
                    continue;
                }

                var model = graphElementModels.Single();

                if (model is INodeModel nodeModel)
                {
                    string fileName;
                    if (string.IsNullOrWhiteSpace(searcherItem.Path))
                    {
                        fileName = nodeModel.GetType().Name;
                    }
                    else
                    {
                        fileName = MakePath(searcherItem, Path.DirectorySeparatorChar);
                    }
                    // fileName = fileName.Replace('/', Path.DirectorySeparatorChar);
                    Assert.IsTrue(fileNames.Add(fileName), "Duplicate filename: " + fileName);

                    var formatter = new MarkdownNodeDocumentationFormatter();
                    formatter.DocumentNode(searcherItem, nodeModel);

                    var filePath = Path.Combine(docPath, $"{fileName}.md");
                    Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    var contents = formatter.ToString();
                    if (!File.Exists(filePath) || File.ReadAllText(filePath) != contents)
                    {
                        File.WriteAllText(filePath, contents);
                    }
                }
            }

            GenerateToc();
        }
コード例 #5
0
        public override void SetUp()
        {
            base.SetUp();
            m_ADecl = GraphModel.CreateGraphVariableDeclaration("A", typeof(float).GenerateTypeHandle(Stencil), true);
            m_BDecl = GraphModel.CreateGraphVariableDeclaration("B", typeof(float).GenerateTypeHandle(Stencil), true);
            m_CDecl = GraphModel.CreateGraphVariableDeclaration("C", typeof(float).GenerateTypeHandle(Stencil), true);
            var macroAssetModel = (VSGraphAssetModel)GraphAssetModel.Create("macro", null, typeof(VSGraphAssetModel));

            m_MacroGraphModel = macroAssetModel.CreateVSGraph <MacroStencil>("macro");
        }
コード例 #6
0
        public virtual SearcherFilter GetOutputToStackSearcherFilter(IPortModel portModel, IStackModel stackModel)
        {
            // TODO : Need to be handled by TypeHandle.Resolve
            TypeHandle      typeHandle = portModel.DataTypeHandle == TypeHandle.ThisType ? m_Stencil.GetThisType() : portModel.DataTypeHandle;
            Type            type       = typeHandle.Resolve(m_Stencil);
            GraphAssetModel assetModel = portModel.AssetModel as GraphAssetModel;

            return(new SearcherFilter(SearcherContext.Stack)
                   .WithVisualScriptingNodes()
                   .WithUnaryOperators(type)
                   .WithGraphAsset(assetModel));
        }
コード例 #7
0
        public void Test_FunctionParameterDeclarationsWithSameName()
        {
            VSGraphAssetModel graphAssetModel = (VSGraphAssetModel)GraphAssetModel.Create("test", "", typeof(VSGraphAssetModel));
            VSGraphModel      graph           = graphAssetModel.CreateVSGraph <ClassStencil>("test");

            var method = graph.CreateFunction("TestFunction", Vector2.zero);

            var declaration0 = method.CreateAndRegisterFunctionParameterDeclaration("param", typeof(int).GenerateTypeHandle(graph.Stencil));
            var declaration1 = method.CreateAndRegisterFunctionParameterDeclaration("param", typeof(int).GenerateTypeHandle(graph.Stencil));

            Assert.That(declaration0, Is.Not.EqualTo(declaration1));
            Assert.That(method.FunctionParameterModels.Count(), Is.EqualTo(2));
        }
        public void CloningAVariableClonesFields()
        {
            VSGraphAssetModel graphAssetModel = (VSGraphAssetModel)GraphAssetModel.Create("test", "", typeof(VSGraphAssetModel));
            VSGraphModel      graph           = graphAssetModel.CreateVSGraph <ClassStencil>("test");
            var decl = graph.CreateGraphVariableDeclaration("asd", TypeHandle.Float, true);

            decl.Tooltip = "asdasd";
            var clone = ((VariableDeclarationModel)decl).Clone();

            Assert.IsFalse(ReferenceEquals(decl, clone));
            Assert.AreEqual(decl.Tooltip, clone.Tooltip);
            Assert.AreNotEqual(decl.GetId(), clone.GetId());
        }
コード例 #9
0
 public void WatchGraphAssetAtPath(string path, GraphAssetModel graphAssetModel)
 {
     if (graphAssetModel != null)
     {
         if (Instance.m_ProjectAssetPaths.ContainsKey(path))
         {
             Instance.m_ProjectAssetPaths[path] = (graphAssetModel.GraphModel as VSGraphModel)?.SourceFilePath;
         }
         else
         {
             Instance.m_ProjectAssetPaths.Add(path, (graphAssetModel.GraphModel as VSGraphModel)?.SourceFilePath);
         }
     }
 }
コード例 #10
0
        public void Test_FunctionVariableDeclarationsIsSerializedInGraphAsset()
        {
            VSGraphAssetModel graphAssetModel = (VSGraphAssetModel)GraphAssetModel.Create("test", "Assets/MyGraphTest.asset", typeof(VSGraphAssetModel));
            VSGraphModel      graph           = graphAssetModel.CreateVSGraph <ClassStencil>("test");
            FunctionModel     method          = graph.CreateFunction("TestFunction", Vector2.zero);

            VariableDeclarationModel declaration = method.CreateFunctionVariableDeclaration("var", typeof(int).GenerateTypeHandle(graph.Stencil));

            string nodeModelPath       = AssetDatabase.GetAssetPath(declaration.InitializationModel.NodeAssetReference);
            string graphAssetModelPath = AssetDatabase.GetAssetPath(graphAssetModel);

            Assert.That(nodeModelPath, Is.EqualTo(graphAssetModelPath));
            AssetDatabase.DeleteAsset(graphAssetModelPath);
        }
コード例 #11
0
        public void SetNameFromUserNameTest(string userInput, string expectedName, string expectedTitle)
        {
            VSGraphAssetModel graphAssetModel = (VSGraphAssetModel)GraphAssetModel.Create("test", "", typeof(VSGraphAssetModel));
            VSGraphModel      graph           = graphAssetModel.CreateVSGraph <ClassStencil>("test");

            var method = graph.CreateFunction("method", Vector2.left * 200);

            method.CreateFunctionVariableDeclaration("bar", typeof(int).GenerateTypeHandle(graph.Stencil));
            var variable = method.CreateFunctionVariableDeclaration("temp", typeof(int).GenerateTypeHandle(graph.Stencil));

            variable.SetNameFromUserName(userInput);
            Assert.That(variable.VariableName, Is.EqualTo(expectedName));
            Assert.That(variable.Title, Is.EqualTo(expectedTitle));
        }
        public virtual SearcherFilter GetOutputToGraphSearcherFilter(IPortModel portModel)
        {
            // TODO : Need to be handled by TypeHandle.Resolve
            TypeHandle      typeHandle = portModel.DataType == TypeHandle.ThisType ? m_Stencil.GetThisType() : portModel.DataType;
            Type            type       = typeHandle.Resolve(m_Stencil);
            GraphAssetModel assetModel = portModel.AssetModel as GraphAssetModel;

            return(new SearcherFilter(SearcherContext.Graph)
                   .WithVisualScriptingNodes()
                   .WithFields(type)
                   .WithUnaryOperators(type, portModel.NodeModel is IConstantNodeModel)
                   .WithBinaryOperators(type)
                   .WithMethods(type)
                   .WithProperties(type, false)
                   .WithGraphAsset(assetModel));
        }
        private void GenerateNodeDoc()
        {
            const string docPath = UIHelper.NodeDocumentationPath;

            if (Directory.Exists(docPath))
            {
                Directory.Delete(docPath, true);
            }
            Directory.CreateDirectory(docPath);

            var gam = GraphAssetModel.Create("Doc", null, typeof(VSGraphAssetModel), false);
            var stateCurrentGraphModel = gam.CreateGraph <VSGraphModel>("Doc", typeof(DotsStencil), false);
            var stencil    = stateCurrentGraphModel.Stencil;
            var dbProvider = stencil.GetSearcherDatabaseProvider();
            var dbs        = dbProvider.GetGraphElementsSearcherDatabases();

            HashSet <string> fileNames = new HashSet <string>();

            foreach (var searcherItem in dbs[0].ItemList.OfType <GraphNodeModelSearcherItem>())
            {
                var graphElementModels = GraphNodeSearcherAdapter.CreateGraphElementModels(stateCurrentGraphModel, searcherItem);
                if (graphElementModels.Count() != 1)
                {
                    continue;
                }

                var model = graphElementModels.Single();
                if (model is IDotsNodeModel dotsNodeModel)
                {
                    var formatter = new MarkdownNodeDocumentationFormatter();

                    formatter.DocumentNode(searcherItem, dotsNodeModel);
                    var fileName = string.IsNullOrWhiteSpace(dotsNodeModel.Title) ? dotsNodeModel.GetType().Name : dotsNodeModel.Title;
                    Assert.IsTrue(fileNames.Add(fileName), "Duplicate filename: " + fileName);
                    var filePath = Path.Combine(docPath, $"{fileName}.md");
                    var contents = formatter.ToString();
                    if (!File.Exists(filePath) || File.ReadAllText(filePath) != contents)
                    {
                        File.WriteAllText(filePath, contents);
                    }
                }
            }
        }
コード例 #14
0
 public OpenedGraph(GraphAssetModel graphAssetModel, GameObject boundObject)
 {
     GraphAssetModel = graphAssetModel;
     BoundObject     = boundObject;
 }