示例#1
0
        private void SetBeginLayout(InspectorItemRenderer renderer)
        {
            if (renderer.horizontalLayout == HorizontalLayout.BeginHorizontal)
            {
                EditorGUILayout.BeginHorizontal();
                currentLayoutIsHorizontal = true;
            }

            if (renderer.verticalLayout == VerticalLayout.BeginVertical)
            {
                EditorGUILayout.BeginVertical();
            }
        }
示例#2
0
        private void SetEndLayout(InspectorItemRenderer renderer)
        {
            if (renderer.horizontalLayout == HorizontalLayout.EndHorizontal)
            {
                EditorGUILayout.EndHorizontal();
                currentLayoutIsHorizontal = false;
            }

            if (renderer.verticalLayout == VerticalLayout.EndVertical)
            {
                EditorGUILayout.EndVertical();
            }
        }
示例#3
0
        //// <summary>
        /// Gets the message renderer for <c>InspectorItemRenderer</c> with the attribute MessageAttribute.
        /// </summary>
        /// <returns>The message renderer created to render MessageAttribute in the inspector.</returns>
        /// <param name="renderer">An item renderer.</param>
        protected override MessageRenderer GetMessageRenderer(InspectorItemRenderer renderer)
        {
            MessageRenderer result = null;

            MessageAttribute messageAttribute = AttributeHelper.GetAttribute <MessageAttribute>(renderer.entityInfo);

            if (messageAttribute != null)
            {
                result = new MessageRenderer(renderer, subtarget, subtarget, renderers.ToArray());
            }

            return(result);
        }
示例#4
0
        public void Render()
        {
            bool renderMessage = true;

            if (!string.IsNullOrEmpty(method))
            {
                MethodInfo methodInfo = caller.GetType().GetMethod(method, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
                if (methodInfo != null)
                {
                    if (methodInfo.ReturnType == typeof(bool))
                    {
                        renderMessage = (bool)methodInfo.Invoke(caller, null);
                    }
                    else
                    {
                        Debug.LogError("The method specified in the attribute Message have to return a bool.");
                    }
                }
                else
                {
                    Debug.LogError("The method specified in the attribute Message does not exist.");
                }
            }
            else if (!string.IsNullOrEmpty(id) && value != null)
            {
                InspectorItemRenderer conditionalRenderer = LookForRenderer(id);
                if (conditionalRenderer != null && conditionalRenderer.entityInfo.isField)
                {
                    if (!value.Equals(conditionalRenderer.entityInfo.fieldInfo.GetValue(classFieldBelongTo)))
                    {
                        renderMessage = false;
                    }
                }
                else
                {
                    Debug.LogWarning("The identifier " + id + " was not found in the list of renderers, or this renderer " +
                                     "was not initialized from a field. Ensure that the id parameter of the attribute Visibility refers to the id of a field " +
                                     "(name of the field if you did not specify explicitly the id of the field in [Inspector(id = \"...\").");
                }
            }

            if (renderMessage)
            {
                if (!string.IsNullOrEmpty(text))
                {
                    EditorGUILayout.HelpBox(text, messageType, true);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Looks for renderer in the renderers list based on an id. The default id is the field or the method name of a renderer.
        /// But this id can be modified with Inspector attribute.
        /// </summary>
        /// <returns>The found renderer.</returns>
        /// <param name="rendererId">Renderer identifier.</param>
        /// <param name="rendererList">The list of Renderers to look in.</param>
        public static InspectorItemRenderer LookForRenderer(string rendererId, InspectorItemRenderer[] rendererList)
        {
            InspectorItemRenderer result = null;

            foreach (InspectorItemRenderer renderer in rendererList)
            {
                if (renderer.GetIdentifier() == rendererId)
                {
                    result = renderer;
                    break;
                }
            }

            return(result);
        }
示例#6
0
        /// <summary>
        /// Looks for renderer in the renderers list based on an id. The default id is the field or the method name of a renderer.
        /// But this id can be modified with Inspector attribute.
        /// </summary>
        /// <returns>The for renderer.</returns>
        /// <param name="rendererId">Renderer identifier.</param>
        private InspectorItemRenderer LookForRenderer(string rendererId)
        {
            InspectorItemRenderer result = null;

            foreach (InspectorItemRenderer renderer in otherRenderers)
            {
                if (renderer.GetIdentifier() == rendererId)
                {
                    result = renderer;
                    break;
                }
            }

            return(result);
        }
示例#7
0
        public VisibilitySetter(InspectorItemRenderer inspectorItemRenderer, object caller, object classFieldBelongTo, InspectorItemRenderer[] otherRenderers = null)
        {
            visibilityAttribute = AttributeHelper.GetAttribute <VisibilityAttribute>(inspectorItemRenderer.entityInfo);

            if (visibilityAttribute != null)
            {
                this.method = visibilityAttribute.method;
                this.id     = visibilityAttribute.id;
                this.value  = visibilityAttribute.value;
            }

            this.caller                = caller;
            this.classFieldBelongTo    = classFieldBelongTo;
            this.inspectorItemRenderer = inspectorItemRenderer;
            this.otherRenderers        = otherRenderers;
        }
示例#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);
        }
示例#9
0
        /// <summary>
        /// Gets the list of methods to render in the inspector interface.
        /// </summary>
        /// <param name="caller">The caller.</param>
        /// <returns></returns>
        public static List <InspectorItemRenderer> GetListOfMethods(object caller)
        {
            List <InspectorItemRenderer> methodRenderers = new List <InspectorItemRenderer>();

            MethodInfo[] methodInfos = caller.GetType().GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            foreach (MethodInfo methodInfo in methodInfos)
            {
                InspectorItemRenderer renderer = InspectorItemRenderer.GetRendererFromMethodInfo(methodInfo, caller);

                if (renderer != null)
                {
                    methodRenderers.Add(renderer);
                }
            }

            return(methodRenderers);
        }
示例#10
0
        /// <summary>
        /// Gets a default renderer for the entity info. Called when no type for the renderer was specified in <c>InspectorAttribute</c> for example
        /// </summary>
        /// <returns>The default renderer for the specified entity info.</returns>
        /// <param name="entityInfo">The entity info which needs a renderer.</param>
        /// <param name="caller">The object from which the method should be called if entity info is wrapping a methodInfo.</param>
        static private InspectorItemRenderer GetDefaultRendererFromEntityInfo(EntityInfo entityInfo)
        {
            InspectorItemRenderer renderer = null;
            Type rendererType = null;

            if (entityInfo.isMethod)
            {
                rendererType = Type.GetType("EasyEditor.ButtonRenderer");
            }
            else if (entityInfo.isField)
            {
                rendererType = GetDefaultRendererTypeForField(entityInfo.fieldInfo);
            }

            renderer = InspectorItemRenderer.GetSpecifiedRendererFromEntityInfo(entityInfo, rendererType);
            return(renderer);
        }
        /// <summary>
        /// Gets the list of methods to render in the inspector interface.
        /// </summary>
        /// <param name="caller">The caller.</param>
        /// <returns></returns>
        public static List <InspectorItemRenderer> GetListOfMethods(object caller, SerializedObject serializedObject, string pathToCaller = null)
        {
            List <InspectorItemRenderer> methodRenderers = new List <InspectorItemRenderer>();

            BindingFlags      flags       = (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
            List <MethodInfo> methodInfos = MethodInfoHelper.GetAllMethodsTillUnityBaseClass(caller.GetType(), flags);

            foreach (MethodInfo methodInfo in methodInfos)
            {
                InspectorItemRenderer renderer = InspectorItemRenderer.GetRendererFromMethodInfo(methodInfo, caller, serializedObject, pathToCaller);

                if (renderer != null)
                {
                    methodRenderers.Add(renderer);
                }
            }

            return(methodRenderers);
        }
示例#12
0
        //// <summary>
        /// Gets the message renderer for <c>InspectorItemRenderer</c> with the attribute MessageAttribute.
        /// </summary>
        /// <returns>The message renderer created to render MessageAttribute in the inspector.</returns>
        /// <param name="renderer">An item renderer.</param>
        /// <param name="contextRenderer">The context in which the renderer is rendered.</param>
        public static MessageRenderer[] GetMessageRenderers(InspectorItemRenderer renderer, FullObjectRenderer contextRenderer)
        {
            List <MessageRenderer> result = new List <MessageRenderer>();

            object caller             = null;
            object classFieldBelongTo = null;

            FullObjectRenderer.GetContextualObjects(renderer, contextRenderer, out caller, out classFieldBelongTo);

            MessageAttribute[] messageAttributes = AttributeHelper.GetAttributes <MessageAttribute>(renderer.entityInfo);
            if (messageAttributes != null)
            {
                foreach (MessageAttribute messageAttribute in messageAttributes)
                {
                    result.Add(new MessageRenderer(messageAttribute, caller, classFieldBelongTo, contextRenderer.renderers.ToArray()));
                }
            }

            return(result.ToArray());
        }
示例#13
0
        /// <summary>
        /// Sets the visibility of a renderer based on the attribute [Visibility(string id, object value)]. If the object with the id 'id'
        /// has the value 'value', the the renderer holding the attribute is visible, otherwise it is not display in the inspector.
        /// </summary>
        private void SetVisibility()
        {
            foreach (InspectorItemRenderer renderer in renderers)
            {
                FieldInfo fieldInfo = null;

                if (renderer.entityInfo.isField)
                {
                    fieldInfo = renderer.entityInfo.fieldInfo;
                }

                if (fieldInfo != null)
                {
                    VisibilityAttribute visibilityAttribute = AttributeHelper.GetAttribute <VisibilityAttribute>(fieldInfo);
                    if (visibilityAttribute != null)
                    {
                        InspectorItemRenderer conditionalRenderer = LookForRenderer(visibilityAttribute.id);
                        if (conditionalRenderer != null && conditionalRenderer.entityInfo.isField)
                        {
                            if (visibilityAttribute.value.Equals(conditionalRenderer.entityInfo.fieldInfo.GetValue(_serializedObject.targetObject)))
                            {
                                ShowRenderer(renderer.GetIdentifier());
                            }
                            else
                            {
                                HideRenderer(renderer.GetIdentifier());
                            }
                        }
                        else
                        {
                            Debug.LogWarning("The identifier " + visibilityAttribute.id + " was not found in the list of renderers, or this renderer " +
                                             "was not initialized from a field. Ensure that the id parameter of the attribute Visibility refers to the id of a field " +
                                             "(name of the field if you did not specify explicitly the id of the field in [Inspector(id = \"...\").");
                        }
                    }
                }
            }
        }
示例#14
0
        //// <summary>
        /// Gets the message renderer for <c>InspectorItemRenderer</c> with the attribute MessageAttribute.
        /// If the renderer belongs to the editor script, then the method specified in MessageAttribute
        /// is looked for in the editor script.
        /// </summary>
        /// <returns>The message renderer created to render MessageAttribute in the inspector.</returns>
        /// <param name="renderer">An item renderer.</param>
        protected override MessageRenderer GetMessageRenderer(InspectorItemRenderer renderer)
        {
            MessageRenderer result = null;

            MessageAttribute messageAttribute = AttributeHelper.GetAttribute <MessageAttribute>(renderer.entityInfo);

            if (messageAttribute != null)
            {
                object caller = serializedObject.targetObject;

                if (renderer.entityInfo.isMethod)
                {
                    if (typeof(EasyEditorBase).IsAssignableFrom(renderer.entityInfo.methodInfo.DeclaringType))
                    {
                        caller = editorScript;
                    }
                }

                result = new MessageRenderer(renderer, caller, serializedObject.targetObject, renderers.ToArray());
            }

            return(result);
        }
示例#15
0
 /// <summary>
 /// Gets the message renderer for <c>InspectorItemRenderer</c> with the attribute MessageAttribute.
 /// Since messages can be displayed based on other fields or condition external to a specific
 /// InspectorItemRenderer, the renderer in charge of rendering a group of renderers (like ScriptObjectRenderer or
 /// InlineClassRenderer) needs to implement this function.
 /// </summary>
 /// <returns>The message renderer created to render MessageAttribute in the inspector.</returns>
 /// <param name="renderer">An item renderer.</param>
 protected virtual MessageRenderer GetMessageRenderer(InspectorItemRenderer renderer)
 {
     return(null);
 }
        /// <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 = "";

            Type currentType = null;
            IEnumerable <FieldInfo> fieldInfoList = fieldInfos as IList <FieldInfo> ?? fieldInfos.ToList();

            if (fieldInfoList.Any())
            {
                currentType = fieldInfoList.First().DeclaringType;
            }

            foreach (FieldInfo fieldInfo in fieldInfoList)
            {
                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 (renderer.entityInfo.fieldInfo.DeclaringType != currentType)
                    {
                        currentGroup = "";
                        currentType  = renderer.entityInfo.fieldInfo.DeclaringType;
                    }

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

                    fieldRenderers.Add(renderer);
                }
            }

            return(fieldRenderers);
        }
示例#17
0
 public InspectorItemRenderer LookForRenderer(string id)
 {
     return(InspectorItemRenderer.LookForRenderer(id, renderers.ToArray()));
 }
示例#18
0
 /// <summary>
 /// Called when the editor script is enable, usually when it is going to be displayed in the inspector.
 /// </summary>
 public void OnEnable()
 {
     scriptObjectRenderer = (ScriptObjectRenderer)InspectorItemRenderer.CreateRenderer(typeof(ScriptObjectRenderer));
     scriptObjectRenderer.Initialize(this.serializedObject, this);
 }