Ejemplo n.º 1
0
        /*----------Functions----------*/
        //PRIVATE

        /// <summary>
        /// Initialise the object with the available object definitions
        /// </summary>
        static ParameterDrawers()
        {
            //Create the lookup dictionaries
            CustomParameterDrawerComparer comp = new CustomParameterDrawerComparer();

            parameterDrawers = new Dictionary <CustomParameterDrawerAttribute, Type>(comp);
            cachedDrawers    = new Dictionary <CustomParameterDrawerAttribute, AParameterDrawer>(comp);
            typeMapping      = new Dictionary <Type, AParameterDrawer>();

            //Find all of the usable drawers within the project
            foreach (Type type in AssemblyTypeScanner.GetTypesWithinAssembly <AParameterDrawer>())
            {
                //Look for the custom drawer processor attribute of the object
                CustomParameterDrawerAttribute descriptor = type.GetFirstCustomAttributeOf <CustomParameterDrawerAttribute>();

                //If there is no attribute can't use it
                if (descriptor == null)
                {
                    continue;
                }

                //Check if the type has already been used
                if (parameterDrawers.ContainsKey(descriptor))
                {
                    Debug.LogWarningFormat("Class '{0}' is being used to Draw for Types '{1}' (Include Children: {2}) and will override the processor '{3}'", type.FullName, descriptor.DrawerType.FullName, descriptor.HandleChildren, parameterDrawers[descriptor].FullName);
                }

                //Save the drawer for later use
                parameterDrawers[descriptor] = type;
            }
        }
Ejemplo n.º 2
0
        /*----------Functions----------*/
        //PRIVATE

        /// <summary>
        /// Setup the initial mapping elements for the identified generic enums
        /// </summary>
        static GenericEnumDrawer()
        {
            //Find all enum types with the generic option attribute
            List <Type> genericEnums = new List <Type>();

            foreach (Type type in AssemblyTypeScanner.GetTypesWithinAssembly <Enum>())
            {
                //Look for the generic option attribute
                if (type.IsEnum && type.GetFirstCustomAttributeOf <GenericEnumOptionAttribute>() != null)
                {
                    genericEnums.Add(type);
                }
            }

            //Sort the stored types based on their names
            genericEnums.Sort((left, right) => left.Name.CompareTo(right.Name));

            //Create the mapping dictionaries
            ENUM_TO_INDEX = new Dictionary <Enum, int>();
            INDEX_TO_ENUM = new Dictionary <int, Enum>();

            //Store a list of the labels that are pulled from the identified elements
            int prog = 0;
            List <GUIContent> labels = new List <GUIContent>();

            foreach (Type generic in genericEnums)
            {
                //Retrieve the names from the list
                string[] enumNames = Enum.GetNames(generic);

                //Boost the list capacity for the new entries
                labels.Capacity += enumNames.Length;

                //Retrieve the values for this enumeration
                Array values = Enum.GetValues(generic);

                //Add the options to the list
                for (int i = 0; i < enumNames.Length; i++)
                {
                    //Add this label entry to the list
                    labels.Add(new GUIContent(string.Format("{0}/{1}", generic.Name, enumNames[i])));

                    //Add the mapping options to the
                    Enum val = (Enum)values.GetValue(i);

                    //Add the mapping options
                    ENUM_TO_INDEX[val]  = prog;
                    INDEX_TO_ENUM[prog] = val;

                    //Increment the progress
                    ++prog;
                }
            }

            //Store the final label options list
            GENERIC_OPTION_LABELS = labels.ToArray();
        }
Ejemplo n.º 3
0
        /*----------Functions----------*/
        //PRIVATE

        /// <summary>
        /// Identify the object elements within the currently loaded assembly for display
        /// </summary>
        static SerialDataPropertyDrawer()
        {
            // Find all of the drawer types that can be used
            Type drawerAttributeType             = typeof(CustomDataDrawerAttribute);
            TypeMarkerAttributeComparer comparer = new TypeMarkerAttributeComparer();

            dataDrawerTypes = new Dictionary <TypeMarkerAttribute, Type>(comparer);
            foreach (Type type in AssemblyTypeScanner.GetTypesWithinAssembly <IDataDrawer>())
            {
                // Look for the drawer marker attribute for use
                object[] atts = type.GetCustomAttributes(drawerAttributeType, false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                // Get the attribute that will be used to identify the type it will be used for
                CustomDataDrawerAttribute att = null;
                for (int i = 0; i < atts.Length; ++i)
                {
                    att = atts[i] as CustomDataDrawerAttribute;
                    if (att != null)
                    {
                        break;
                    }
                }
                if (att == null || att.AssociatedType == null)
                {
                    continue;
                }

                // Check that this type can be created for use
                if (type.IsAbstract)
                {
                    Debug.LogErrorFormat("Unable to use Drawer type '{0}' for the type '{1}' as the drawer is abstract", type, att.AssociatedType);
                    continue;
                }
                else if (type.GetConstructor(Type.EmptyTypes) == null)
                {
                    Debug.LogErrorFormat("Unable to use Drawer type '{0}' for the type '{1}' as the drawer has no default constructor", type, att.AssociatedType);
                    continue;
                }

                // If there is an existing drawer for this type, warn of override
                if (dataDrawerTypes.ContainsKey(att))
                {
                    Debug.LogWarningFormat("Drawer Type '{0}' is overriding '{1}' for use to draw '{2}'", type, dataDrawerTypes[att], att);
                }
                dataDrawerTypes[att] = type;
            }

            // Find all of the serial storage types that can be used
            Type serialAttributeType = typeof(CustomSerialStorageAttribute);

            dataStorageTypes = new Dictionary <TypeMarkerAttribute, Type>(comparer);
            foreach (Type type in AssemblyTypeScanner.GetTypesWithinAssembly <SerialStorage>())
            {
                // Look for the storage attribute for use
                object[] atts = type.GetCustomAttributes(serialAttributeType, false);
                if (atts == null || atts.Length == 0)
                {
                    continue;
                }

                // Get the attribute that will be used to identify the type it will be used for
                CustomSerialStorageAttribute att = null;
                for (int i = 0; i < atts.Length; ++i)
                {
                    att = atts[i] as CustomSerialStorageAttribute;
                    if (att != null)
                    {
                        break;
                    }
                }
                if (att == null || att.AssociatedType == null)
                {
                    continue;
                }

                // If there is an existing storage type for the value type, warn of override
                if (dataStorageTypes.ContainsKey(att))
                {
                    Debug.LogWarningFormat("Storage Type '{0}' is overriding '{1}' for storage of type '{2}'", type, dataStorageTypes[att], att.AssociatedType);
                }
                dataStorageTypes[att] = type;
            }

            // Create the management drawer objects
            mismatchDrawer      = new TypeMismatchDataDrawer();
            nonSerialDrawer     = new NonSerialDataDrawer();
            generateDrawer      = new GenerateStorageDataDrawer();
            missingSerialDrawer = new MissingSerialPropertyDrawer();
            defaultDrawer       = new DefaultDataDrawer();
        }