Exemple #1
0
        void RenderObjectClass(Action preRender = null)
        {
            EditorGUILayout.PropertyField(FieldInfoHelper.GetSerializedPropertyFromPath(entityInfo.propertyPath,
                                                                                        serializedObject));

            if (subtarget != null)
            {
                CreateSerializedObject();
                subSerializedObject.Update();

                EditorGUI.indentLevel += 2 * Settings.indentation;

                foldout = EditorGUILayout.Foldout(foldout, "");
                if (foldout)
                {
                    GUILayout.Space(15 * Settings.indentation);
                    EditorGUILayout.BeginHorizontal(InspectorStyle.DefaultStyle.inlineFoldableBackgroundStyle);

                    base.Render(preRender);

                    EditorGUILayout.EndHorizontal();
                }

                EditorGUI.indentLevel -= 2 * Settings.indentation;

                subSerializedObject.ApplyModifiedProperties();
            }

            CheckIfTargetNotNull();
        }
Exemple #2
0
        /// <summary>
        /// Finds the serialized property starting from the root object (the Monobehaviour or the ScriptableObject) and
        /// going down through every composed fields (custom serializable class and struct).
        /// </summary>
        private void FindSerializedProperty()
        {
            serializedProperty = FieldInfoHelper.GetSerializedPropertyFromPath(entityInfo.propertyPath,
                                                                               serializedObject,
                                                                               out directParentSerializedObject);

            if (serializedProperty == null)
            {
                string path = FieldInfoHelper.GetFieldInfoPath(entityInfo.fieldInfo, serializedObject.targetObject.GetType());
                if (!string.IsNullOrEmpty(path))
                {
                    string[] pathTable = path.Split('.');
                    if (pathTable.Length > 0)
                    {
                        serializedProperty = serializedObject.FindProperty(pathTable [0]);
                        for (int i = 1; i < pathTable.Length; i++)
                        {
                            serializedProperty = serializedProperty.FindPropertyRelative(pathTable [i]);
                        }
                    }
                }
                else
                {
                    Debug.LogWarning("The field info " + entityInfo.fieldInfo.Name + " you initialized this renderer with cannot be found in the children properties of the target.");
                }
            }
        }
Exemple #3
0
        private void HandleOnItemSelected(int index, SerializedProperty list)
        {
            if (isSelectable)
            {
                inlineClassRenderer = null;

                SerializedProperty propertyToRender = list.GetArrayElementAtIndex(index);
                if (propertyToRender.propertyType == SerializedPropertyType.ObjectReference || propertyToRender.propertyType == SerializedPropertyType.Generic)
                {
                    object listElement = FieldInfoHelper.GetObjectFromPath(propertyToRender.propertyPath, serializedObject.targetObject);

                    if (listElement != null)
                    {
                        EntityInfo info = new EntityInfo(listElement.GetType(),
                                                         serializedObject, propertyToRender.propertyPath);
                        inlineClassRenderer = InspectorItemRenderer.CreateRenderer <InlineClassRenderer>();
                        inlineClassRenderer.InitializeFromEntityInfo(info);

                        if (propertyToRender.propertyType == SerializedPropertyType.Generic)
                        {
                            inlineClassRenderer.FoldoutTitle = propertyToRender.displayName;
                        }
                    }
                }
            }
        }
        public override void InitializeFromEntityInfo(EntityInfo entityInfo)
        {
            base.InitializeFromEntityInfo(entityInfo);

            isReadOnly   = (AttributeHelper.GetAttribute <ReadOnlyAttribute>(entityInfo.fieldInfo) != null);
            isSelectable = (AttributeHelper.GetAttribute <SelectableAttribute>(entityInfo.fieldInfo) != null);

            list        = FieldInfoHelper.GetSerializedPropertyFromPath(entityInfo.propertyPath, entityInfo.serializedObject);
            listControl = new ReorderableListControl();

            listControl.ItemInserted += ListControl_OnItemInsertedHandler;
            listControl.ItemRemoving += ListControl_OnItemRemovingHandler;
            listControl.ItemMoved    += ListControl_OnItemMovedHandler;

            if (isReadOnly)
            {
                listControl.Flags = ReorderableListFlags.DisableReordering
                                    | ReorderableListFlags.DisableContextMenu
                                    | ReorderableListFlags.HideAddButton
                                    | ReorderableListFlags.HideRemoveButtons;
            }

            listAdaptor = new EESerializedPropertyAdaptor(serializedProperty, isReadOnly);
            listAdaptor.OnItemSelected       += ListAdaptor_HandleOnItemSelected;
            listAdaptor.OnItemInserted       += ListAdaptor_HandleOnItemInserted;
            listAdaptor.OnDrawItem           += ListAdaptor_HandleOnDrawItem;
            listAdaptor.OnDrawItemBackground += ListAdaptor_HandleOnDrawItemBackground;
        }
Exemple #5
0
 private void GetCallers()
 {
     for (int i = 0; i < serializedObject.targetObjects.Length; i++)
     {
         callers[i] = FieldInfoHelper.GetObjectFromPath(pathToCaller, serializedObject.targetObjects[i]);
     }
 }
Exemple #6
0
        /// <summary>
        /// Gets the list of fields to render in inspector interface.
        /// </summary>
        /// <param name="target">The targeted object.</param>
        /// <returns></returns>
        public static List <InspectorItemRenderer> GetListOfFields(object target, SerializedObject serializedObject, string targetPath = "")
        {
            List <InspectorItemRenderer> fieldRenderers = new List <InspectorItemRenderer>();
            BindingFlags            flags      = (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            IEnumerable <FieldInfo> fieldInfos = FieldInfoHelper.GetAllFieldsTillUnityBaseClass(target.GetType(), flags);
            string currentGroup     = "";
            bool   reachedBaseClass = false;

            foreach (FieldInfo fieldInfo in fieldInfos)
            {
                InspectorItemRenderer renderer = null;

                if (FieldInfoHelper.IsSerializedInUnity(fieldInfo))
                {
                    string propertyPath = "";
                    if (string.IsNullOrEmpty(targetPath))
                    {
                        propertyPath = fieldInfo.Name;
                    }
                    else
                    {
                        propertyPath = targetPath + "." + fieldInfo.Name;
                    }

                    renderer = InspectorItemRenderer.GetRendererFromFieldInfo(fieldInfo, serializedObject, propertyPath);
                }
                else
                {
                    InspectorAttribute inspectorAttribute = AttributeHelper.GetAttribute <InspectorAttribute> (fieldInfo);

                    if (inspectorAttribute != null && !FieldInfoHelper.IsSerializedInUnity(fieldInfo))
                    {
                        Debug.LogWarning("You assigned the attribute" +
                                         " [Inspector] to the field " + fieldInfo.Name + " of object " + target.GetType() + " which is not serialized by Unity. EasyEditor will not render it.");
                    }
                }

                if (renderer != null)
                {
                    if (!reachedBaseClass)
                    {
                        if (renderer.entityInfo.fieldInfo.DeclaringType != target.GetType())
                        {
                            currentGroup     = "";
                            reachedBaseClass = true;
                        }
                    }

                    AssignGroup(renderer, currentGroup);
                    currentGroup = renderer.inspectorAttribute.group;

                    fieldRenderers.Add(renderer);
                }
            }

            return(fieldRenderers);
        }
Exemple #7
0
 private void CheckIfTargetNotNull()
 {
     if (Event.current.type == EventType.Repaint)
     {
         subtarget = FieldInfoHelper.GetObjectFromPath(entityInfo.propertyPath, serializedObject.targetObject);
         if (subtarget == null)
         {
             subtargetWasNull = true;
         }
         else if (subtarget != null && subtargetWasNull)
         {
             InitializeRenderers();
             subtargetWasNull = false;
         }
     }
 }
Exemple #8
0
        /// <summary>
        /// Gets the list of fields to render in inspector interface.
        /// </summary>
        /// <param name="target">The targeted object.</param>
        /// <returns></returns>
        public static List <InspectorItemRenderer> GetListOfFields(object target, string targetPath = "")
        {
            List <InspectorItemRenderer> fieldRenderers = new List <InspectorItemRenderer>();

            FieldInfo[] fieldInfos   = target.GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            string      currentGroup = "";

            foreach (FieldInfo fieldInfo in fieldInfos)
            {
                InspectorItemRenderer renderer = null;

                if (FieldInfoHelper.RenderedByEasyEditor(fieldInfo))
                {
                    string propertyPath = "";
                    if (string.IsNullOrEmpty(targetPath))
                    {
                        propertyPath = fieldInfo.Name;
                    }
                    else
                    {
                        propertyPath = targetPath + "." + fieldInfo.Name;
                    }

                    renderer = InspectorItemRenderer.GetRendererFromFieldInfo(fieldInfo, propertyPath);
                }
                else
                {
                    InspectorAttribute inspectorAttribute = AttributeHelper.GetAttribute <InspectorAttribute> (fieldInfo);

                    if (inspectorAttribute != null && !FieldInfoHelper.IsSerializedInUnity(fieldInfo))
                    {
                        Debug.LogWarning("You assigned the attribute" +
                                         " [Inspector] to the field " + fieldInfo.Name + " of object " + target.GetType() + " which is not serialized by Unity. EasyEditor will not render it.");
                    }
                }

                if (renderer != null)
                {
                    AssignGroup(renderer, currentGroup);
                    currentGroup = renderer.inspectorAttribute.group;

                    fieldRenderers.Add(renderer);
                }
            }

            return(fieldRenderers);
        }
        /// <summary>
        /// Gets the custom class reference from the source object containing it. The custom class is
        /// not necessarily a direct member of the source object.
        /// </summary>
        /// <returns>The custom class reference.</returns>
        /// <param name="fieldInfo">Field info representing the custom class.</param>
        /// <param name="sourceObject">Source object.</param>
        public static object GetCustomClassReference(FieldInfo fieldInfo, object sourceObject)
        {
            object result = null;

            string path = FieldInfoHelper.GetFieldInfoPath(fieldInfo, sourceObject.GetType());

            if (!string.IsNullOrEmpty(path))
            {
                result = sourceObject;
                string[] pathTable = path.Split('.');
                for (int i = 0; i < pathTable.Length; i++)
                {
                    result = FieldInfoHelper.GetFieldReferenceFromName(pathTable [i], BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, result);
                }
            }

            return(result);
        }
Exemple #10
0
 public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     if (property.isExpanded)
     {
         return(property.CountInProperty() * 16f);
     }
     else
     if (FieldInfoHelper.IsTypeOrCollectionOfType <Bounds>(fieldInfo.FieldType))
     {
         return(2 * 16f);
     }
     else if (property.propertyType == SerializedPropertyType.Vector3 && inspectorWidth < 306f + (Settings.indentation + 7) * EditorGUI.indentLevel)
     {
         return(2 * 16f);
     }
     else
     {
         return(base.GetPropertyHeight(property, label));
     }
 }
        protected override void InitializeRenderersList()
        {
            base.InitializeRenderersList();

            subtarget = FieldInfoHelper.GetObjectFromPath(entityInfo.propertyPath, _serializedObject.targetObject);
            List <InspectorItemRenderer> fieldsRenderers  = RendererFinder.GetListOfFields(subtarget, entityInfo.propertyPath);
            List <InspectorItemRenderer> methodsRenderers = RendererFinder.GetListOfMethods(subtarget);

            renderers = new List <InspectorItemRenderer>();
            renderers.AddRange(fieldsRenderers);
            renderers.AddRange(methodsRenderers);

            InspectorItemRendererOrderComparer comparer = new InspectorItemRendererOrderComparer(groups, renderers);

            renderers.Sort(comparer);

            foreach (InspectorItemRenderer renderer in renderers)
            {
                renderer.serializedObject = _serializedObject;
            }
        }
Exemple #12
0
        static private Type GetDefaultRendererTypeForField(FieldInfo fieldInfo)
        {
            Type result = null;

            IEnumerable <Type> collection = Utils.FindSubClassesOf <InspectorItemRenderer>();

            foreach (Type inspectorItemRendererType in collection)
            {
                RenderTypeAttribute[] renderTypeAttributes = AttributeHelper.GetAttributes <RenderTypeAttribute>(inspectorItemRendererType);
                if (renderTypeAttributes != null)
                {
                    foreach (RenderTypeAttribute renderTypeAttribute in renderTypeAttributes)
                    {
                        if (fieldInfo.FieldType == renderTypeAttribute.type || renderTypeAttribute.type.IsAssignableFrom(fieldInfo.FieldType))
                        {
                            result = inspectorItemRendererType;
                            break;
                        }
                    }
                }
            }

            if (result == null && FieldInfoHelper.HasSerializableAttribute(fieldInfo.FieldType))
            {
                result = typeof(SerializedFieldRenderer);
            }

            if (result == null)
            {
                Debug.LogWarning("The field '" + fieldInfo.Name + "' does not fit any renderer. If you want this type of field to be rendered, ensure that " +
                                 "a class inheriting from InspectorItemRenderer have the attribute RenderType with the type of the field as argument OR " +
                                 "add [Inspector(rendererType = \" class name of the renderer to use\" on top of the field, Ex : [Inspector(rendererType = \"SerializedFieldRenderer\"].");
            }

            return(result);
        }