static void FigureViewBinding(CommandBinding binding)
    {
        var sobj   = new SerializedObject(binding);
        var vcprop = sobj.FindProperty("_view");
        var veprop = sobj.FindProperty("_viewEvent");

        if (string.IsNullOrEmpty(veprop.stringValue))
        {
            return;
        }

        var vcomp = vcprop.objectReferenceValue as Component;

        if (vcomp == null)
        {
            return;
        }

        var @event = INPCBindingEditor.GetEvent(vcomp, veprop);

        if (@event != null)
        {
            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(@event, binding.ExecuteCommand);
        }

        sobj.ApplyModifiedProperties();
    }
    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();
    }
示例#3
0
    private static void BuildPath(SerializedProperty prop, StringBuilder sw)
    {
        SerializedProperty cprop;
        SerializedProperty pprop;

        INPCBindingEditor.GetCPathProperties(prop, out cprop, out pprop);

        var oval = cprop.objectReferenceValue;

        if (oval == null)
        {
            return;
        }

        var ppath = new INPCBinding.PropertyPath(pprop.stringValue, oval.GetType());

        if (!ppath.IsValid)
        {
            return;
        }

        if (_paths.Contains(ppath.PPath))
        {
            return;
        }
        _paths.Add(ppath.PPath);

        sw.AppendFormat(@"  ppa.Register(
    new[]
    {{
{0}
    }},
    obj => 
    {{
        if(obj == null) return null; 
        var v0 = (({1})obj).{2};
{3}
    }},
    (obj, value) =>
    {{
{4}
    }});",
                        string.Join(",\r\n", ppath.PPath.Select(p =>
                                                                string.Format("        INPCBinding.PropertyPath.GetProperty(typeof({0}), \"{1}\")",
                                                                              GetFullName(p.DeclaringType),
                                                                              p.Name))
                                    .ToArray()),
                        GetFullName(ppath.PPath[0].DeclaringType),
                        ppath.Parts[0],
                        BuildGetterEnd(ppath),
                        BuildSetterEnd(ppath))
        .AppendLine().AppendLine();
    }
    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();
    }
    static void FigureViewBinding(CommandBinding binding)
    {
        var sobj   = new SerializedObject(binding);
        var vcprop = sobj.FindProperty("_view");
        var veprop = sobj.FindProperty("_viewEvent");

        if (string.IsNullOrEmpty(veprop.stringValue))
        {
            return;
        }

        var vcomp = vcprop.objectReferenceValue as Component;

        if (vcomp == null)
        {
            return;
        }

        var @event = INPCBindingEditor.GetEvent(vcomp, veprop);

        if (@event != null)
        {
            // Fixing adding multiple command binding event handlers when using prefabs
            var eventCount = @event.GetPersistentEventCount();
            for (var idx = 0; idx < eventCount; idx++)
            {
                var perTarget = @event.GetPersistentTarget(idx);
                // if we find a duplicate event skip over adding it
                if (perTarget == binding)
                {
                    return;
                }
            }

            UnityEditor.Events.UnityEventTools.AddVoidPersistentListener(@event, binding.ExecuteCommand);
        }

        sobj.ApplyModifiedProperties();
    }
示例#6
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();
        }
    }
示例#7
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();
        }
    }