Exemplo n.º 1
0
        public void DrawProperties(Type componentType, object component, PropertyInfo[] properties)
        {
            OldSettings settings = OldInspectorSidekick.Current.Settings;             // Grab the active window's settings

            for (int j = 0; j < properties.Length; j++)
            {
                if (properties[j].DeclaringType == typeof(Component) ||
                    properties[j].DeclaringType == typeof(UnityEngine.Object))
                {
                    continue;
                }

                if (!string.IsNullOrEmpty(settings.SearchTerm) && !properties[j].Name.Contains(settings.SearchTerm, StringComparison.InvariantCultureIgnoreCase))
                {
                    // Does not match search term, skip it
                    continue;
                }


                MethodInfo getMethod = properties[j].GetGetMethod(true);
                MethodInfo setMethod = properties[j].GetSetMethod(true);

                string metaSuffix = "";
                if (setMethod == null)
                {
                    GUI.enabled = false;
                }

                object[] attributes = properties[j].GetCustomAttributes(false);

                // Don't try to get the value of properties that error on access
                bool isObsoleteWithError = AttributeHelper.IsObsoleteWithError(attributes);

                if (getMethod != null &&
                    !isObsoleteWithError &&
                    !(componentType == typeof(MeshFilter) && properties[j].Name == "mesh"))
                {
                    object oldValue = getMethod.Invoke(component, null);
                    EditorGUI.BeginChangeCheck();
                    object newValue = DrawVariable(properties[j].PropertyType, properties[j].Name, oldValue, metaSuffix, true, componentType);
                    if (EditorGUI.EndChangeCheck() && setMethod != null)
                    {
                        setMethod.Invoke(component, new object[] { newValue });
                    }
                }
                else
                {
                    GUILayout.Label(properties[j].PropertyType + " " + properties[j].Name);
                }

                if (setMethod == null)
                {
                    GUI.enabled = true;
                }
            }
        }
Exemplo n.º 2
0
        public void DrawProperties(Type componentType, object component, string searchTerm, PropertyInfo[] properties)
        {
            foreach (var property in properties)
            {
                if (property.DeclaringType == typeof(Component) ||
                    property.DeclaringType == typeof(UnityEngine.Object))
                {
                    continue;
                }

                if (!SearchMatches(searchTerm, property.Name))
                {
                    // Does not match search term, skip it
                    continue;
                }

                if (property.GetIndexParameters().Length != 0)
                {
                    // Indexer, show it in Methods instead as it takes parameters
                    continue;
                }

                MethodInfo getMethod = property.GetGetMethod(true);
                MethodInfo setMethod = property.GetSetMethod(true);

                object[] attributes = property.GetCustomAttributes(false);

                VariableAttributes variableAttributes = VariableAttributes.None;

                if (getMethod != null && getMethod.IsStatic || setMethod != null && setMethod.IsStatic)
                {
                    variableAttributes |= VariableAttributes.Static;
                }

                if (setMethod == null)
                {
                    variableAttributes |= VariableAttributes.ReadOnly;
                }

                if (getMethod == null)
                {
                    variableAttributes |= VariableAttributes.WriteOnly;
                }

                string tooltip = TypeUtility.GetTooltip(property, variableAttributes);

                if (getMethod == null)
                {
                    EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("No get method", SidekickEditorGUI.ErrorIconSmall));
                }
                else if (InspectionExclusions.IsPropertyExcluded(componentType, property))
                {
                    EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("Excluded due to rule", SidekickEditorGUI.ErrorIconSmall, "See InspectionExclusions.cs"));
                }
                else if (AttributeHelper.IsObsoleteWithError(attributes))
                {
                    // Don't try to get the value of properties that error on access
                    EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent("[Obsolete] error", SidekickEditorGUI.ErrorIconSmall));
                }
                else
                {
                    object    oldValue = null;
                    Exception error    = null;
                    try
                    {
                        oldValue = getMethod.Invoke(component, null);
                    }
                    catch (Exception e)
                    {
                        error = e;
                    }

                    if (error != null)
                    {
                        EditorGUILayout.LabelField(new GUIContent(property.Name, tooltip), new GUIContent(error.GetType().Name, SidekickEditorGUI.ErrorIconSmall));
                    }
                    else
                    {
                        DrawVariable(property.PropertyType, property.Name, oldValue, tooltip, variableAttributes, property.GetCustomAttributes(), true, componentType, newValue =>
                        {
                            setMethod?.Invoke(component, new[] { newValue });
                        });
                    }
                }
            }
        }