Ejemplo n.º 1
0
        /// <summary>
        /// Gets a renderer from a field/method info. Will look first for the renderer type specified in the field info attribute. If it was not specified, will look for
        /// the default renderer for this field/meothod info.
        /// </summary>
        /// <returns>The renderer generated from the entity info.</returns>
        /// <param name="entityInfo">Entity info.</param>
        /// <param name="caller">The object from which the method should be called if entity info is wrapping a methodInfo.</param>
        static private InspectorItemRenderer GetRendererFromEntityInfo(EntityInfo entityInfo)
        {
            InspectorItemRenderer renderer           = null;
            InspectorAttribute    inspectorAttribute = AttributeHelper.GetAttribute <InspectorAttribute> (entityInfo);

            if (inspectorAttribute != null)
            {
                if (inspectorAttribute.rendererType != null)
                {
                    Type renderClassType = Type.GetType("EasyEditor." + inspectorAttribute.rendererType);
                    renderer = InspectorItemRenderer.GetSpecifiedRendererFromEntityInfo(entityInfo, renderClassType);
                }
                else
                {
                    renderer = InspectorItemRenderer.GetDefaultRendererFromEntityInfo(entityInfo);
                }
            }
            else
            {
                if (entityInfo.isField)
                {
                    renderer = InspectorItemRenderer.GetDefaultRendererFromEntityInfo(entityInfo);
                }
            }

            return(renderer);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        protected void InitializeInspectorAttribute()
        {
            InspectorAttribute inspectorAttribute = AttributeHelper.GetAttribute <InspectorAttribute> (entityInfo);

            if (inspectorAttribute != null)
            {
                _inspectorAttribute = inspectorAttribute;
            }
            else
            {
                _inspectorAttribute = InspectorAttribute.DefaultInspectorAttribute;
            }
        }
Ejemplo n.º 4
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);
        }