Наследование: UnityEngine.MonoBehaviour
Пример #1
0
        /**
         * Find the best matching pb_ComponentEditor for a type.
         */
        public static pb_ComponentEditor GetEditor(Component component)
        {
            GameObject go = new GameObject();

            Type editorType = null;

            if (!builtInComponentEditors.TryGetValue(component.GetType(), out editorType))
            {
                foreach (KeyValuePair <Type, Type> kvp in builtInComponentEditors)
                {
                    if (kvp.Key.IsAssignableFrom(component.GetType()))
                    {
                        editorType = kvp.Value;
                        break;
                    }
                }
            }

            go.name = component.name;
            pb_ComponentEditor editor = (pb_ComponentEditor)go.AddComponent(editorType ?? typeof(pb_ComponentEditor));

            editor.SetComponent(component);

            return(editor);
        }
Пример #2
0
        public void RebuildInspector(GameObject go)
        {
            ClearInspector();

            if (go == null)
            {
                return;
            }

            foreach (Component component in go.GetComponents <Component>())
            {
                if (component == null ||
                    userIgnoredTypes.Contains(component.GetType()) ||
                    pb_Reflection.HasIgnoredAttribute(component.GetType()) ||
                    System.Attribute.GetCustomAttribute(component.GetType(), typeof(pb_InspectorIgnoreAttribute)) != null ||
                    (!showUnityComponents && pb_Config.IgnoredComponentsInInspector.Contains(component.GetType())))
                {
                    continue;
                }

                string panelLabelTitleString = component.GetType().ToString();

                //check if the component has the custom inspector name attribute
                if (component.GetType().GetCustomAttributes(typeof(pb_InspectorNameAttribute), true).Length > 0)
                {
                    //get first instance of the attribute.
                    pb_InspectorNameAttribute attr = (pb_InspectorNameAttribute)component.GetType().GetCustomAttributes(typeof(pb_InspectorNameAttribute), true)[0];

                    if (attr.name != null && attr.name.Length > 0)
                    {
                        panelLabelTitleString = attr.name; //set the title to the name set on the attribute
                    }
                }

                GameObject panel = pb_GUIUtility.CreateLabeledVerticalPanel(panelLabelTitleString);
                panel.transform.SetParent(inspectorScrollPanel.transform);

                pb_ComponentEditor inspector = null;

                if (typeof(pb_ICustomEditor).IsAssignableFrom(component.GetType()))
                {
                    inspector = ((pb_ICustomEditor)component).InstantiateInspector(component);
                }
                else
                {
                    inspector = pb_ComponentEditorResolver.GetEditor(component);
                }

                inspector.transform.SetParent(panel.transform);

                componentEditors.Add(inspector);
            }
        }