Ejemplo n.º 1
0
 private static void RebuildDrawers()
 {
     GUIDrawer.drawers = new Dictionary <Type, PropertyDrawer>();
     Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
     for (int i = 0; i < (int)assemblies.Length; i++)
     {
         Assembly assembly = assemblies[i];
         Type[]   types    = assembly.GetExportedTypes();
         for (int j = 0; j < (int)types.Length; j++)
         {
             Type type = types[j];
             if (typeof(PropertyDrawer).IsAssignableFrom(type) && type.IsClass && !type.IsAbstract)
             {
                 Type inspectedType = AttributeUtility.GetCustomDrawerAttribute(type);
                 if (inspectedType != null && !GUIDrawer.drawers.ContainsKey(inspectedType))
                 {
                     PropertyDrawer drawer = (PropertyDrawer)Activator.CreateInstance(type);
                     GUIDrawer.drawers.Add(inspectedType, drawer);
                     Type[] subTypes = TypeUtility.GetSubTypes(inspectedType);
                     for (int s = 0; s < subTypes.Length; s++)
                     {
                         Type subType = subTypes[s];
                         if (!GUIDrawer.drawers.ContainsKey(subType))
                         {
                             GUIDrawer.drawers.Add(subType, drawer);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        public static void OnGUI(UnityEngine.Object targetObject)
        {
            EditorGUI.BeginChangeCheck();
            SerializedObject serializedObject = new SerializedObject(targetObject);

            serializedObject.Update();
            FieldInfo[] fields;
            if (!fieldsLookup.TryGetValue(targetObject.GetType(), out fields))
            {
                fields = targetObject.GetPublicFields().OrderBy(field => field.MetadataToken).ToArray();

                fieldsLookup.Add(targetObject.GetType(), fields);
            }
            if (PreferencesEditor.GetBool(Preference.ShowActionTooltips) && !string.IsNullOrEmpty(targetObject.GetTooltip()))
            {
                GUILayout.BeginVertical((GUIStyle)"hostview");

                GUILayout.Label(targetObject.GetTooltip(), FsmEditorStyles.wrappedLabelLeft);
                GUILayout.EndVertical();
            }


            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo field = fields[i];
                if (field.HasAttribute(typeof(HideInInspector)))
                {
                    continue;
                }
                PropertyDrawer     drawer   = GUIDrawer.GetDrawer(field);
                GUIContent         content  = field.GetInspectorGUIContent();
                SerializedProperty property = serializedObject.FindProperty(field.Name);
                if (PreferencesEditor.GetBool(Preference.ShowVariableTooltips) && !string.IsNullOrEmpty(field.GetTooltip()))
                {
                    GUILayout.BeginVertical("box");
                    GUILayout.Label(field.GetTooltip(), FsmEditorStyles.wrappedLabelLeft);
                    GUILayout.EndVertical();
                }

                if (drawer != null)
                {
                    drawer.fieldInfo = field;
                    drawer.OnGUI(property, content);
                }
                else
                {
                    int indentLevel = EditorGUI.indentLevel;
                    EditorGUI.indentLevel = typeof(IList).IsAssignableFrom(field.FieldType)?indentLevel + 1:indentLevel;
                    EditorGUILayout.PropertyField(property, content, true);
                    EditorGUI.indentLevel = indentLevel;
                }
            }


            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
                ErrorChecker.CheckForErrors();
            }
        }