Exemple #1
0
        /**
         *	Get a type inspector that most closely matches type.
         *	If an exact type match is found, that inspector is returned.  If no exact match is found,
         *  the first base class match found.  If no base class is found, a generic object inspector
         *  is returned, which in turn will reflect the properties and fields contained and attempt to
         *	build inspectors for each.
         */
        public static pb_TypeInspector GetInspector(Type type)
        {
            if (inspectorLookup == null)
            {
                InitializeLookup();
            }

            GameObject inspectorObject;

            if (inspectorPool.TryGetValue(type, out inspectorObject))
            {
                return(GameObject.Instantiate(inspectorObject).GetComponent <pb_TypeInspector>());
            }

            List <GameObject> inspectors = new List <GameObject>();

            foreach (KeyValuePair <pb_TypeInspectorAttribute, GameObject> kvp in inspectorLookup)
            {
                pb_TypeInspectorAttribute attrib = kvp.Key;

                if (attrib.CanEditType(type))
                {
                    if (attrib.type == type)
                    {
                        inspectors.Insert(0, kvp.Value);
                        goto EXACT_TYPE_INSPECTOR_FOUND;
                    }
                    else
                    {
                        inspectors.Add(kvp.Value);
                    }
                }
            }

EXACT_TYPE_INSPECTOR_FOUND:

            if (inspectors.Count > 0)
            {
                inspectorPool.Add(type, inspectors[0]);
                inspectorObject = GameObject.Instantiate(inspectors[0]);
                pb_TypeInspector typeInspector = inspectorObject.GetComponent <pb_TypeInspector>();
                typeInspector.SetDeclaringType(type);
                return(typeInspector);
            }
            else
            {
                GameObject go = new GameObject();
                go.name = "Generic Object Inspector: " + type;
                pb_TypeInspector typeInspector = go.AddComponent <pb_ObjectInspector>();
                typeInspector.SetDeclaringType(type);
                return(typeInspector);
            }
        }
Exemple #2
0
        private static void InitializeLookup()
        {
            inspectorPool   = new Dictionary <Type, GameObject>();
            inspectorLookup = new Dictionary <pb_TypeInspectorAttribute, GameObject>();

            foreach (GameObject go in Resources.LoadAll(TYPE_INSPECTOR_PATH, typeof(GameObject)))
            {
                pb_TypeInspector typeInspector = go.GetComponent <pb_TypeInspector>();

                if (typeInspector == null)
                {
                    continue;
                }

                pb_TypeInspectorAttribute t = AttributeExtension.GetAttributeValue(typeInspector);
                Attribute[] typeAttribs     = new Attribute[1] {
                    t
                };
                inspectorLookup.Add(t, go);
            }
        }