コード例 #1
0
ファイル: RendererFinder.cs プロジェクト: two-d/monkey-game
        /// <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);
        }
コード例 #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, 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);
        }