示例#1
0
        void TypeReferencePicker(SerializedProperty iterator, TypeSearcherAttribute attribute, GUIContent label, Action onChangedCallback)
        {
            //Fetch typename
            var typeHandleIdProperty       = iterator.FindPropertyRelative(nameof(TypeHandle.Identification));
            var typeHandleAssetRefProperty = iterator.FindPropertyRelative(nameof(TypeHandle.GraphModelReference));

            var handle  = new TypeHandle(typeHandleAssetRefProperty.objectReferenceValue as VSGraphModel, typeHandleIdProperty.stringValue);
            var stencil = model.GraphModel.Stencil;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(label);

            var friendlyName = handle.GetMetadata(stencil).FriendlyName;

            if (GUILayout.Button(friendlyName))
            {
                var mousePosition = mainContainer.LocalToWorld(Event.current.mousePosition);
                void Callback(TypeHandle type, int index)
                {
                    Assert.IsNotNull(typeHandleIdProperty);
                    Assert.IsNotNull(typeHandleAssetRefProperty);
                    typeHandleIdProperty.stringValue = type.Identification;
                    typeHandleAssetRefProperty.objectReferenceValue = type.GraphModelReference;
                    iterator.serializedObject.ApplyModifiedProperties();
                    onChangedCallback();
                }

                SearcherService.ShowTypes(stencil, mousePosition, Callback, attribute.Filter?.GetFilter(model));
            }

            EditorGUILayout.EndHorizontal();
        }
示例#2
0
        SearcherFilter MakeSearcherAdapterFromAttribute(TypeSearcherAttribute attribute, INodeModel model)
        {
            var stencil      = model.VSGraphModel.Stencil;
            var typeSearcher = new SearcherFilter(SearcherContext.Type);

            if (attribute is ComponentSearcherAttribute componentSearcher)
            {
                return(componentSearcher.ComponentOptions == ComponentOptions.OnlyAuthoringComponents
                    ? typeSearcher.WithAuthoringComponentTypes(stencil)
                    : typeSearcher.WithComponentTypes(stencil));
            }
            return(typeSearcher.WithTypesInheriting(stencil, attribute?.FilteredType ?? typeof(IComponentData)));
        }