Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.LabelField(position, label);
            EditorGUI.indentLevel++;

            SerializedProperty component, propertyPath;

            GetCPathProperties(property, out component, out propertyPath);

            using (var changeScope = new EditorGUI.ChangeCheckScope())
            {
                position = EditorGUILayout.GetControlRect(false);
                ComponentReferenceDrawer.PropertyField(position, component);

                if (changeScope.changed)
                {
                    // Notify the suggestion provider that any cached list of suggestions are now invalid.
                    _suggestionProvider.FireSuggestionsChangedEvent();
                }
            }

            if (_autoSuggestField == null)
            {
                _suggestionProvider = new PropertyPathSuggestionProvider(property);
                _autoSuggestField   = new AutoSuggestField(
                    _suggestionProvider,
                    new GUIContent(propertyPath.displayName),
                    new AutoSuggestField.Options
                {
                    DisplayMode = DisplayMode.Inline,
                });
            }

            propertyPath.stringValue = _autoSuggestField.OnGUI(propertyPath.stringValue);

            EditorGUI.indentLevel--;
        }
Exemplo n.º 2
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        var tprop = serializedObject.FindProperty("_type");
        var iprop = serializedObject.FindProperty("_instantiateOnAwake");
        var bprop = serializedObject.FindProperty("_propertyBinding");

        if (_autoSuggestField == null)
        {
            _suggestionProvider = new TypeSuggestionProvider();
            _autoSuggestField   = new AutoSuggestField(
                _suggestionProvider,
                new GUIContent(SearchFieldLabel),
                new AutoSuggestField.Options
            {
                DisplayMode = DisplayMode.Inline,
            });
        }

        if (_searchString == null)
        {
            // On first frame, _searchString will be null.
            // After block line, it will be non-null.

            _tval         = Type.GetType(tprop.stringValue);
            _searchString = _tval?.FullName ?? string.Empty;
        }

        _searchString = _autoSuggestField.OnGUI(_searchString);

        if (_suggestionProvider.SelectedTypeIsValid && Event.current.type == EventType.Layout)
        {
            _tval             = _suggestionProvider.SelectedType;
            tprop.stringValue = _tval?.AssemblyQualifiedName;
        }

        if (_tval != null)
        {
            if (typeof(UnityEngine.Object).IsAssignableFrom(_tval))
            {
                GUILayout.Label("Auto-instantiation not possible with UnityEngine.Object types");
            }
            else
            {
                EditorGUILayout.PropertyField(iprop);
                EditorGUILayout.PropertyField(bprop);
            }
        }

        serializedObject.ApplyModifiedProperties();

        var dc = target as DataContext;

        if (dc != null)
        {
            using (var disabledGroupScope = new EditorGUI.DisabledGroupScope(true))
            {
                EditorGUILayout.Toggle("Value is non-null?", dc.Value != null);
            }
        }
    }