public GraphElementSearcherDatabase AddGraphsMethods() { string[] assetGUIDs = AssetDatabase.FindAssets($"t:{typeof(VSGraphAssetModel).Name}"); List <Tuple <IGraphModel, FunctionModel> > methods = assetGUIDs.SelectMany(assetGuid => { string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid); VSGraphAssetModel graphAssetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(assetPath); if (!graphAssetModel || graphAssetModel.GraphModel == null) { return(Enumerable.Empty <Tuple <IGraphModel, FunctionModel> >()); } var functionModels = graphAssetModel.GraphModel.NodeModels.OfExactType <FunctionModel>() .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm)); return(functionModels.Concat(graphAssetModel.GraphModel.NodeModels.OfExactType <EventFunctionModel>() .Select(fm => new Tuple <IGraphModel, FunctionModel>(fm.GraphModel, fm)))); }).ToList(); if (methods.Count == 0) { return(this); } TypeHandle voidTypeHandle = typeof(void).GenerateTypeHandle(Stencil); foreach (Tuple <IGraphModel, FunctionModel> method in methods) { IGraphModel graphModel = method.Item1; FunctionModel functionModel = method.Item2; string graphName = graphModel.AssetModel.Name; SearcherItem graphRoot = SearcherItemUtility.GetItemFromPath(Items, $"{k_Graphs}/{graphName}"); if (functionModel.ReturnType == voidTypeHandle) { graphRoot.AddChild(new StackNodeModelSearcherItem( new FunctionRefSearcherItemData(graphModel, functionModel), data => data.CreateFunctionRefCallNode(functionModel), () => $"{k_Function} {functionModel.Title}" )); continue; } graphRoot.AddChild(new GraphNodeModelSearcherItem( new FunctionRefSearcherItemData(graphModel, functionModel), data => data.CreateFunctionRefCallNode(functionModel), () => $"{k_Function} {functionModel.Title}" )); } return(this); }
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 SearcherFilter GetOutputToGraphSearcherFilter(IPortModel portModel) { // 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); VSGraphAssetModel assetModel = portModel.AssetModel as VSGraphAssetModel; return(new SearcherFilter(SearcherContext.Graph) .WithVisualScriptingNodes() .WithUnaryOperators(type, portModel.NodeModel is IConstantNodeModel) .WithBinaryOperators(type) .WithGraphAsset(assetModel)); }
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()); }
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); }
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 GetOutputToStackSearcherFilter(IPortModel portModel, IStackModel stackModel) { // 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); VSGraphAssetModel assetModel = portModel.AssetModel as VSGraphAssetModel; return(new SearcherFilter(SearcherContext.Stack) .WithVisualScriptingNodes() .WithFields(type) .WithUnaryOperators(type) .WithIfConditions(typeHandle, stackModel) .WithMethods(type) .WithProperties(type) .WithGraphAsset(assetModel)); }
public void SetParent(Type type, VSGraphAssetModel asset) { Assert.IsTrue(typeof(Stencil).IsAssignableFrom(type)); m_Parent = (Stencil)CreateInstance(type); Utility.SaveAssetIntoObject(m_Parent, asset); }
public override void OnInspectorGUI() { bool dirty = false; ScriptingGraphAuthoring authoring = target as ScriptingGraphAuthoring; VSGraphAssetModel assetModel = null; if (authoring.ScriptingGraph) { var path = AssetDatabase.GetAssetPath(authoring.ScriptingGraph); assetModel = AssetDatabase.LoadAssetAtPath <VSGraphAssetModel>(path); } var newAssetModel = EditorGUILayout.ObjectField("Scripting Graph", assetModel, typeof(VSGraphAssetModel)) as VSGraphAssetModel; if (assetModel != newAssetModel) { dirty = true; if (newAssetModel) { authoring.ScriptingGraph = ((DotsStencil)newAssetModel.GraphModel.Stencil).CompiledScriptingGraphAsset; } else { authoring.ScriptingGraph = null; } } // I/O if (!(newAssetModel?.GraphModel is VSGraphModel graph)) { return; } if (m_ProcessedBindings == null) { m_ProcessedBindings = new HashSet <BindingId>(); } else { m_ProcessedBindings.Clear(); } foreach (var graphVariableModel in graph.GraphVariableModels) { var variableType = GraphBuilder.GetVariableType(graphVariableModel); switch (variableType) { case GraphBuilder.VariableType.SmartObject: case GraphBuilder.VariableType.ObjectReference: BindingId id = GetExistingBinding(graphVariableModel, authoring, out var binding); m_ProcessedBindings.Add(id); if (binding == null) { dirty = true; authoring.Values.Add(binding = new ScriptingGraphAuthoring.InputBindingAuthoring(id)); } var valueType = graphVariableModel.DataType.TypeHandleToValueType(); EditorGUI.BeginChangeCheck(); switch (valueType) { case ValueType.Entity: binding.Object = EditorGUILayout.ObjectField(graphVariableModel.Name, binding.Object, typeof(GameObject), true); break; default: EditorGUILayout.LabelField(graphVariableModel.Name, valueType.ToString()); break; } if (EditorGUI.EndChangeCheck()) { dirty = true; } break; case GraphBuilder.VariableType.InputOutput: case GraphBuilder.VariableType.Variable: continue; default: throw new ArgumentOutOfRangeException(); } } if (authoring.Values != null) { for (var index = authoring.Values.Count - 1; index >= 0; index--) { var binding = authoring.Values[index]; if (!m_ProcessedBindings.Contains(binding.Id)) { authoring.Values.RemoveAt(index); dirty = true; } } } if (dirty) { EditorUtility.SetDirty(authoring); } }