DrawCRefProp() public static méthode

draw an INPCBinding.ComponentPath property
public static DrawCRefProp ( UnityEditor.SerializedProperty property, GUIContent label, Type filter, bool resolveDataContext = true ) : void
property UnityEditor.SerializedProperty
label GUIContent
filter Type
resolveDataContext bool
Résultat void
    public override void OnInspectorGUI()
    {
        // Only update the focused element name during the Layout event, since all controls must be static between Layout & Repaint.
        if (Event.current.type == EventType.Layout)
        {
            _focusedControl = GUI.GetNameOfFocusedControl();
        }

        serializedObject.Update();

        EditorGUILayout.PropertyField(_vprop);
        if (_vprop.objectReferenceValue != null)
        {
            INPCBindingEditor.DrawComponentEvents(_vprop, _veprop);
        }

        INPCBindingEditor.DrawCRefProp(serializedObject.targetObject.GetInstanceID(), _focusedControl, _vmprop, GUIContent.none, typeof(ICommand));

        var rect  = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
        var label = EditorGUI.BeginProperty(rect, null, _parmprop);

        GUI.Label(rect, label);

        //parameter type
        var typeProp = _parmprop.FindPropertyRelative("Type");
        var trect    = rect;

        trect.x     += EditorGUIUtility.labelWidth;
        trect.width -= EditorGUIUtility.labelWidth;
        EditorGUI.PropertyField(trect, typeProp);

        //value field
        var typeValue = (BindingParameterType)Enum.GetValues(typeof(BindingParameterType)).GetValue(typeProp.enumValueIndex);
        SerializedProperty valueProp = null;

        switch (typeValue)
        {
        case BindingParameterType.None:
            break;

        default:
            valueProp = _parmprop.FindPropertyRelative(typeValue.ToString());
            break;
        }
        if (valueProp != null)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(valueProp);
            EditorGUI.indentLevel--;
        }

        EditorGUI.EndProperty();

        serializedObject.ApplyModifiedProperties();
    }
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(_vprop);
        if (_vprop.objectReferenceValue != null)
        {
            INPCBindingEditor.DrawComponentEvents(_vprop, _veprop);
        }

        INPCBindingEditor.DrawCRefProp(_vmprop, GUIContent.none, typeof(ICommand));

        var rect  = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight);
        var label = EditorGUI.BeginProperty(rect, null, _parmprop);

        GUI.Label(rect, label);

        //parameter type
        var typeProp = _parmprop.FindPropertyRelative("Type");
        var trect    = rect;

        trect.x     += EditorGUIUtility.labelWidth;
        trect.width -= EditorGUIUtility.labelWidth;
        EditorGUI.PropertyField(trect, typeProp);

        //value field
        var typeValue = (BindingParameterType)Enum.GetValues(typeof(BindingParameterType)).GetValue(typeProp.enumValueIndex);
        SerializedProperty valueProp = null;

        switch (typeValue)
        {
        case BindingParameterType.None:
            break;

        default:
            valueProp = _parmprop.FindPropertyRelative(typeValue.ToString());
            break;
        }
        if (valueProp != null)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(valueProp);
            EditorGUI.indentLevel--;
        }

        EditorGUI.EndProperty();

        serializedObject.ApplyModifiedProperties();
    }
Exemple #3
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

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

        if (_tval == null && !string.IsNullOrEmpty(tprop.stringValue))
        {
            _tval = Type.GetType(tprop.stringValue);
            if (_tval == null) //invalid type name. Clear it so we don't keep looking for an invalid type.
            {
                // Handle invalid DataContext types
                var style = new GUIStyle(EditorStyles.textField);
                style.normal.textColor = Color.red;

                EditorGUILayout.TextField(string.Format("Error: Invalid type \"{0}\"",
                                                        tprop.stringValue),
                                          style);
            }
        }

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

                INPCBindingEditor.DrawCRefProp(serializedObject.targetObject.GetInstanceID(), bprop, GUIContent.none);
            }
        }

        if (_tval != null)
        {
            _searchString = EditorGUILayout.TextField(SearchFieldLabel, _tval.FullName);
            if (_searchString != _tval.FullName)
            {
                tprop.stringValue = null;
                iprop.boolValue   = false;
                _tval             = null;
            }
            else
            {
                //_cvis = EditorGUILayout.Foldout(_cvis, "Commands");
                //if (_cvis)
                //{
                //    EditorGUI.indentLevel++;
                //    var cprops = _tval.GetProperties().Where(p => p.PropertyType == typeof(ICommand));
                //    foreach (var prop in cprops)
                //    {
                //        GUILayout.Label(prop.Name);
                //    }
                //    EditorGUI.indentLevel--;
                //}
            }
        }
        else
        {
            GUI.SetNextControlName(SearchFieldControlName);
            _searchString = EditorGUILayout.TextField(SearchFieldLabel, _searchString);
        }

        if (_tval == null && !string.IsNullOrEmpty(_searchString))
        {
            if (!_previousSearchString.Equals(_searchString))
            {
                _previousSearchString = _searchString;
                _types = null;
            }

            if (_types == null && GUILayout.Button("Search"))
            {
                var typeQuery = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a =>
                {
                    try
                    {
                        return(a.GetTypes());
                    }
                    catch (Exception)
                    {
                        return(new Type[] { });
                    }
                }).Where(t => t.AssemblyQualifiedName.IndexOf(_searchString, StringComparison.OrdinalIgnoreCase) >= 0);

                // Calling ToList forces the query to execute this one time, instead of executing every single time "types" is enumerated.
                _types = typeQuery.ToList();
            }

            EditorGUI.FocusTextInControl(SearchFieldControlName);

            if (_types != null)
            {
                _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Height(100));
                foreach (var type in _types)
                {
                    if (GUILayout.Button(type.FullName))
                    {
                        _tval             = type;
                        tprop.stringValue = _tval.AssemblyQualifiedName;
                    }
                }
                EditorGUILayout.EndScrollView();
            }
        }

        serializedObject.ApplyModifiedProperties();

        var dc = target as DataContext;

        if (dc != null)
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.Toggle("Value is non-null?", dc.Value != null);
            EditorGUI.EndDisabledGroup();
        }
    }
Exemple #4
0
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

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

        if (_tval == null && !string.IsNullOrEmpty(tprop.stringValue))
        {
            _tval = Type.GetType(tprop.stringValue);
            if (_tval == null) //invalid type name. Clear it so we don't keep looking for an invalid type.
            {
                tprop.stringValue = null;
                iprop.boolValue   = false;
            }
        }

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

                INPCBindingEditor.DrawCRefProp(serializedObject.targetObject.GetInstanceID(), bprop, GUIContent.none);
            }
        }

        if (_tval != null)
        {
            _searchString = EditorGUILayout.TextField(_tval.FullName);
            if (_searchString != _tval.FullName)
            {
                tprop.stringValue = null;
                iprop.boolValue   = false;
                _tval             = null;
            }
            else
            {
                //_cvis = EditorGUILayout.Foldout(_cvis, "Commands");
                //if (_cvis)
                //{
                //    EditorGUI.indentLevel++;
                //    var cprops = _tval.GetProperties().Where(p => p.PropertyType == typeof(ICommand));
                //    foreach (var prop in cprops)
                //    {
                //        GUILayout.Label(prop.Name);
                //    }
                //    EditorGUI.indentLevel--;
                //}
            }
        }
        else
        {
            _searchString = EditorGUILayout.TextField(_searchString);
        }

        if (_tval == null && !string.IsNullOrEmpty(_searchString))
        {
            var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).Where(t => t.Name.IndexOf(_searchString, StringComparison.OrdinalIgnoreCase) >= 0);
            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUILayout.Height(100));
            foreach (var type in types)
            {
                if (GUILayout.Button(type.FullName))
                {
                    _tval             = type;
                    tprop.stringValue = _tval.AssemblyQualifiedName;
                }
            }
            EditorGUILayout.EndScrollView();
        }



        serializedObject.ApplyModifiedProperties();

        var dc = target as DataContext;

        if (dc != null)
        {
            EditorGUI.BeginDisabledGroup(true);
            EditorGUILayout.Toggle("Value?", dc.Value != null);
            EditorGUI.EndDisabledGroup();
        }
    }