Ejemplo n.º 1
0
        public void TestWithFields(string name, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithFields(typeof(FakeObject));
            var data   = new FieldSearcherItemData(typeof(FakeObject).GetField(name));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 2
0
        public void TestWithPropertiesOfType(Type type, string name, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithProperties(type);
            var data   = new PropertySearcherItemData(typeof(FakeObject).GetProperty(name));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 3
0
        public void TestWithConstants()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithConstants();
            var data   = new TypeSearcherItemData(Stencil.GenerateTypeHandle(typeof(string)), SearcherItemTarget.Constant);

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Ejemplo n.º 4
0
        public void TestWithMethodsOfType(Type type, string name, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithMethods(typeof(FakeObject));
            var data   = new MethodSearcherItemData(type.GetMethod(name));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 5
0
        public void TestWithUnaryOperatorsForType(Type type, UnaryOperatorKind kind, bool isConstant, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithUnaryOperators(type, isConstant);
            var data   = new UnaryOperatorSearcherItemData(kind);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 6
0
        public void TestWithUnaryOperators()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithUnaryOperators();
            var data   = new UnaryOperatorSearcherItemData(UnaryOperatorKind.Minus);

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Ejemplo n.º 7
0
        public void TestWithStack()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithStack();
            var data   = new SearcherItemData(SearcherItemTarget.Stack);

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Ejemplo n.º 8
0
        public void TestWithInlineExpression()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithInlineExpression();
            var data   = new SearcherItemData(SearcherItemTarget.InlineExpression);

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Ejemplo n.º 9
0
        public void TestVisualScriptingNodes()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithVisualScriptingNodes();
            var data   = new NodeSearcherItemData(typeof(SetVariableNodeModel));

            Assert.IsTrue(filter.ApplyFilters(data));
        }
Ejemplo n.º 10
0
        public void TestVisualScriptingNodesOfType(Type type, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithVisualScriptingNodes(type);
            var data   = new NodeSearcherItemData(typeof(SetVariableNodeModel));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 11
0
        public static SearcherFilter WithControlFlowExcept <T>(this SearcherFilter self, IStackModel stackModel)
        {
            var type = typeof(T);

            self.RegisterControlFlow(data => type.IsAssignableFrom(data.Type) && stackModel.AcceptNode(data.Type));
            return(self);
        }
        public static void TypeEditor(this Stencil stencil, TypeHandle typeHandle, Action <TypeHandle, int> onSelection,
                                      SearcherFilter filter = null, TypeOptions options = TypeOptions.None)
        {
            var missingTypeReference = TypeHandle.MissingType;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel("Type");

            var selected = EditorGUILayout.DropdownButton(new GUIContent(typeHandle != missingTypeReference ? typeHandle.GetMetadata(stencil).FriendlyName : "<unknown type>"), FocusType.Passive, GUI.skin.button);

            if (Event.current.type == EventType.Repaint)
            {
                s_ButtonRect = GUILayoutUtility.GetLastRect();
            }

            if (selected)
            {
                SearcherService.ShowTypes(
                    stencil,
                    EditorWindow.focusedWindow.rootVisualElement.LocalToWorld(s_ButtonRect.center),
                    onSelection,
                    filter
                    );
            }
            EditorGUILayout.EndHorizontal();
        }
Ejemplo n.º 13
0
        static object InvokeApplyFiltersMethod(SearcherFilter filter, TypeSearcherItemData data)
        {
            var method = filter.GetType().GetMethod("ApplyFilters",
                                                    BindingFlags.NonPublic | BindingFlags.Instance);

            return(method?.Invoke(filter, new object[] { data }));
        }
 public static SearcherFilter WithControlFlowExcept(this SearcherFilter self, IStackModel stackModel,
                                                    IEnumerable <Type> exceptions)
 {
     self.RegisterControlFlow(data =>
                              !exceptions.Any(e => e.IsAssignableFrom(data.Type)) && stackModel.AcceptNode(data.Type));
     return(self);
 }
Ejemplo n.º 15
0
        public void TestWithEnums(Type type, bool expectedResult)
        {
            var filter = new SearcherFilter(SearcherContext.Type).WithEnums(Stencil);
            var data   = new TypeSearcherItemData(type.GenerateTypeHandle(Stencil), SearcherItemTarget.Type);

            Assert.AreEqual(expectedResult, filter.ApplyFilters(data));
        }
        public static void ConstantEditorGUI(SerializedObject o, GUIContent label, Stencil stencil,
                                             ConstantEditorMode mode = ConstantEditorMode.ValueOnly, Action onChange = null)
        {
            if (!(o.targetObject is AbstractNodeAsset asset))
            {
                return;
            }

            switch (asset.Model)
            {
            case ConstantNodeModel constantNodeModel when constantNodeModel.IsLocked:
                return;

            case EnumConstantNodeModel enumModel:
            {
                if (mode != ConstantEditorMode.ValueOnly)
                {
                    var filter = new SearcherFilter(SearcherContext.Type).WithEnums(stencil);
                    stencil.TypeEditor(enumModel.value.EnumType,
                                       (type, index) =>
                        {
                            enumModel.value.EnumType = type;
                            onChange?.Invoke();
                        }, filter);
                }
                enumModel.value.Value = Convert.ToInt32(EditorGUILayout.EnumPopup("Value", enumModel.EnumValue));
                break;
            }

            default:
                EditorGUILayout.PropertyField(o.FindProperty("m_NodeModel.value"), label, true);
                break;
            }
        }
Ejemplo n.º 17
0
        public void TestFunctionRefs(IGraphModel graph, IFunctionModel functionModel, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithFunctionReferences();
            var data   = new FunctionRefSearcherItemData(graph, functionModel);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 18
0
        public void TestWithGraphAssets(IGraphAssetModel graphAssetModel, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithMacros();
            var data   = new GraphAssetSearcherItemData(graphAssetModel);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 19
0
        public void TestWithVisualScriptingNodesExcept(Type exception, Type dataType, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithVisualScriptingNodesExcept(new [] { exception });
            var data   = new NodeSearcherItemData(dataType);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 20
0
        public void TestWithMethods(MethodInfo methodInfo, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithMethods();
            var data   = new MethodSearcherItemData(methodInfo);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 21
0
        public void TestWithControlFlowOfType(Type filterType, Type returnType, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithControlFlow(filterType);
            var data   = new ControlFlowSearcherItemData(returnType);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
        public void TestWithSharedComponentData(Type type, bool expectedResult)
        {
            var filter = new SearcherFilter(SearcherContext.Type).WithSharedComponentData(m_Stencil);
            var data   = new TypeSearcherItemData(type.GenerateTypeHandle(m_Stencil), SearcherItemTarget.Type);
            var result = InvokeApplyFiltersMethod(filter, data);

            Assert.AreEqual(expectedResult, result);
        }
Ejemplo n.º 23
0
        public void TestWithPropertiesOfDeclaringAndReturnTypes(string propertyName, Type declaringType,
                                                                Type returnType, bool allowConstant, bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithProperties(declaringType, returnType, allowConstant);
            var data   = new PropertySearcherItemData(typeof(FakeObject).GetProperty(propertyName));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 24
0
        public void TestWithFieldsOfDeclaringAndFieldTypes(string fieldName, Type declaringType, Type fieldType,
                                                           bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithFields(declaringType, fieldType);
            var data   = new FieldSearcherItemData(typeof(FakeObject).GetField(fieldName));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 25
0
        public void TestWithMethodsOfDeclaringAndReturnTypes(string methodName, Type declaringType, Type returnType,
                                                             bool result)
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithMethods(declaringType, returnType);
            var data   = new MethodSearcherItemData(typeof(FakeObject).GetMethod(methodName));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 26
0
        public virtual SearcherFilter GetGraphSearcherFilter()
        {
            var filter = new SearcherFilter(SearcherContext.Graph)
                         .WithStickyNote();

            return(m_Stencil is DotsStencil dotsStencil && dotsStencil.Type == DotsStencil.GraphType.Subgraph
                ? filter.WithVisualScriptingNodesExcept(Enumerable.Repeat <Type>(typeof(IEntryPointNode), 1))
                : filter.WithVisualScriptingNodes());
        }
Ejemplo n.º 27
0
        public void TestWithConstructors()
        {
            var filter = new SearcherFilter(SearcherContext.Graph).WithConstructors();
            var data   = new ConstructorSearcherItemData(typeof(FakeObject).GetConstructors()[0]);

            Assert.IsTrue(filter.ApplyFilters(data));

            data = new ConstructorSearcherItemData(null);
            Assert.IsFalse(filter.ApplyFilters(data));
        }
Ejemplo n.º 28
0
        public void TestWithConstantsOfType(Type constType, Type portDataType, bool result)
        {
            var portMock = new Mock <IPortModel>();

            portMock.Setup(p => p.DataType).Returns(Stencil.GenerateTypeHandle(portDataType));

            var filter = new SearcherFilter(SearcherContext.Graph).WithConstants(Stencil, portMock.Object);
            var data   = new TypeSearcherItemData(Stencil.GenerateTypeHandle(constType), SearcherItemTarget.Constant);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 29
0
        public void TestWithVisualScriptingNodesOfTypeInStack(Type nodeType, bool acceptNode, bool result)
        {
            var stackMock = new Mock <IStackModel>();

            stackMock.Setup(s => s.AcceptNode(It.IsAny <Type>())).Returns(acceptNode);

            var filter = new SearcherFilter(SearcherContext.Stack).WithVisualScriptingNodes(nodeType, stackMock.Object);
            var data   = new NodeSearcherItemData(typeof(SetVariableNodeModel));

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }
Ejemplo n.º 30
0
        public void TestWithControlFlowOfTypeInStack(Type filterType, Type returnType, bool acceptNode, bool result)
        {
            var stackMock = new Mock <IStackModel>();

            stackMock.Setup(s => s.AcceptNode(It.IsAny <Type>())).Returns(acceptNode);

            var filter = new SearcherFilter(SearcherContext.Stack).WithControlFlow(filterType, stackMock.Object);
            var data   = new ControlFlowSearcherItemData(returnType);

            Assert.AreEqual(result, filter.ApplyFilters(data));
        }