Esempio n. 1
0
        public static void TypeEditor(this Stencil stencil, TypeHandle typeHandle, Action <TypeHandle, int> onSelection,
                                      SearcherFilter filter = null, TypeOptions options = TypeOptions.None)
        {
            var wasArray             = typeHandle.IsVsArrayType(stencil);
            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),
                    (t, i) => onSelection(wasArray ? t.MakeVsArrayType(stencil) : t, i),
                    filter
                    );
            }
            EditorGUILayout.EndHorizontal();

            if (!options.HasFlag(TypeOptions.AllowArray))
            {
                return;
            }

            var newIsArray = EditorGUILayout.Toggle("Is Array", wasArray);

            if (newIsArray != wasArray)
            {
                onSelection(newIsArray ? typeHandle.MakeVsArrayType(stencil) : typeHandle.GetVsArrayElementType(stencil), 0);
            }
        }
Esempio n. 2
0
        public void Test_UpdateRankAction([Values] TestingMode mode)
        {
            TypeHandle intType      = typeof(int).GenerateTypeHandle(Stencil);
            TypeHandle intArrayType = intType.MakeVsArrayType(Stencil);
            VariableDeclarationModel declaration = GraphModel.CreateGraphVariableDeclaration("decl0", typeof(int).GenerateTypeHandle(Stencil), true);

            GraphModel.CreateVariableNode(declaration, Vector2.zero);
            GraphModel.CreateVariableNode(declaration, Vector2.zero);

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));

                Assert.That(declaration.DataType.IsVsArrayType(Stencil), Is.False);
                Assert.That(((ConstantNodeModel)declaration.InitializationModel).Type, Is.EqualTo(typeof(int)));

                foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>())
                {
                    Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(intType));
                }
                return(new UpdateTypeRankAction(declaration, true));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));

                Assert.That(declaration.DataType.IsVsArrayType(Stencil), Is.True);
                Assert.That(((ConstantNodeModel)declaration.InitializationModel), Is.Null, "Array type have no initialization values");

                foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>())
                {
                    Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(intArrayType));
                }
            });

            TestPrereqActionPostreq(mode,
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(declaration.DataType.IsVsArrayType(Stencil), Is.True);
                Assert.That(((ConstantNodeModel)declaration.InitializationModel), Is.Null, "Array type have no initialization values");
                foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>())
                {
                    Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(intArrayType));
                }
                return(new UpdateTypeRankAction(declaration, false));
            },
                                    () =>
            {
                Assert.That(GetNodeCount(), Is.EqualTo(2));
                Assert.That(GetEdgeCount(), Is.EqualTo(0));
                Assert.That(declaration.DataType.IsVsArrayType(Stencil), Is.False);
                Assert.That(((ConstantNodeModel)declaration.InitializationModel), Is.Not.Null);
                foreach (var variableNodeModel in GraphModel.NodeModels.OfType <VariableNodeModel>())
                {
                    Assert.That(variableNodeModel.OutputPort.DataType, Is.EqualTo(intType));
                }
            });
        }