Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
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.º 3
0
        public MessageRenderer(InspectorItemRenderer inspectorItemRenderer, object caller, object classFieldBelongTo, InspectorItemRenderer[] otherRenderers = null)
        {
            MessageAttribute messageAttribute = AttributeHelper.GetAttribute <MessageAttribute>(inspectorItemRenderer.entityInfo);

            this.text               = messageAttribute.text;
            this.method             = messageAttribute.method;
            this.id                 = messageAttribute.id;
            this.value              = messageAttribute.value;
            this.caller             = caller;
            this.classFieldBelongTo = classFieldBelongTo;

            switch (messageAttribute.messageType)
            {
            case MessageType.Info:
                this.messageType = UnityEditor.MessageType.Info;
                break;

            case MessageType.Warning:
                this.messageType = UnityEditor.MessageType.Warning;
                break;

            case MessageType.Error:
                this.messageType = UnityEditor.MessageType.Error;
                break;
            }

            this.otherRenderers = otherRenderers;
        }
Ejemplo n.º 4
0
        public void SetVisibility()
        {
            bool renderRenderer = !inspectorItemRenderer.hidden;

            if (inspectorItemRenderer.entityInfo.isField &&
                AttributeHelper.GetAttribute <HideInInspector>(inspectorItemRenderer.entityInfo.fieldInfo) != null)
            {
                renderRenderer = false;
            }
            else 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))
                    {
                        renderRenderer = (bool)methodInfo.Invoke(caller, null);
                    }
                    else
                    {
                        Debug.LogError("The method specified in the attribute Visibility have to return a bool.");
                    }
                }
                else
                {
                    Debug.LogError("The method specified in the attribute Visibility does not exist.");
                }
            }
            else if (!string.IsNullOrEmpty(id) && value != null)
            {
                InspectorItemRenderer conditionalRenderer = InspectorItemRenderer.LookForRenderer(id, otherRenderers);
                if (conditionalRenderer != null && conditionalRenderer.entityInfo.isField)
                {
                    if (!value.Equals(conditionalRenderer.entityInfo.fieldInfo.GetValue(classFieldBelongTo)))
                    {
                        renderRenderer = false;
                    }
                    else
                    {
                        renderRenderer = true;
                    }
                }
                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 (renderRenderer)
            {
                inspectorItemRenderer.hidden = false;
            }
            else
            {
                inspectorItemRenderer.hidden = true;
            }
        }
Ejemplo n.º 5
0
        protected void InitializeCommentAttribute()
        {
            CommentAttribute commentAttribute = AttributeHelper.GetAttribute <CommentAttribute> (entityInfo);

            if (commentAttribute != null)
            {
                this.comment = commentAttribute.comment;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        public override void InitializeFromEntityInfo(EntityInfo entityInfo)
        {
            base.InitializeFromEntityInfo(entityInfo);

            EETooltipAttribute tooltipAttribute = AttributeHelper.GetAttribute <EETooltipAttribute> (entityInfo.methodInfo);

            if (tooltipAttribute != null && !string.IsNullOrEmpty(tooltipAttribute.tooltip))
            {
                tooltip = tooltipAttribute.tooltip;
            }

            this.label = ObjectNames.NicifyVariableName(entityInfo.methodInfo.Name);
        }
Ejemplo n.º 8
0
        protected override void RetrieveGroupList()
        {
            GroupsAttribute groupsAttribute = AttributeHelper.GetAttribute <GroupsAttribute>(editorScript.GetType());

            if (groupsAttribute != null)
            {
                groups = new Groups(groupsAttribute.groups);
            }
            else
            {
                groups = new Groups(new string[] { "" });
            }
        }
Ejemplo n.º 9
0
        protected void InitializeInspectorAttribute()
        {
            InspectorAttribute inspectorAttribute = AttributeHelper.GetAttribute <InspectorAttribute> (entityInfo);

            if (inspectorAttribute != null)
            {
                _inspectorAttribute = inspectorAttribute;
            }
            else
            {
                _inspectorAttribute = InspectorAttribute.DefaultInspectorAttribute;
            }
        }
Ejemplo n.º 10
0
        protected override void RetrieveGroupList()
        {
            GroupsAttribute groupAttribute = AttributeHelper.GetAttribute <GroupsAttribute>(entityInfo.fieldInfo.FieldType);

            if (groupAttribute != null)
            {
                groups = new Groups(groupAttribute.groups);
            }
            else
            {
                groups = new Groups(new string[] { "" });
            }
        }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        private void RetrieveCustomClassGroup()
        {
            GroupsAttribute groupAttribute = AttributeHelper.GetAttribute <GroupsAttribute>(GetClassType());

            if (groupAttribute != null)
            {
                groups = new Groups(groupAttribute.groups);
            }
            else
            {
                groups = new Groups(new string[] { "" });
            }
        }
Ejemplo n.º 13
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;
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
0
        protected void InitializeLayouts()
        {
            if (AttributeHelper.GetAttribute <BeginHorizontalAttribute> (_entityInfo) != null)
            {
                this.horizontalLayout = HorizontalLayout.BeginHorizontal;
            }
            else if (AttributeHelper.GetAttribute <EndHorizontalAttribute> (_entityInfo) != null)
            {
                this.horizontalLayout = HorizontalLayout.EndHorizontal;
            }

            if (AttributeHelper.GetAttribute <BeginVerticalAttribute> (_entityInfo) != null)
            {
                this.verticalLayout = VerticalLayout.BeginVertical;
            }
            else if (AttributeHelper.GetAttribute <EndVerticalAttribute> (_entityInfo) != null)
            {
                this.verticalLayout = VerticalLayout.EndVertical;
            }
        }
Ejemplo n.º 16
0
        private void RetrieveObjectClassGroup()
        {
            IEnumerable <Type> collection = Utils.FindSubClassesOf <EasyEditorBase>();

            foreach (Type editorScript in collection)
            {
                CustomEditor customEditorAttribute = AttributeHelper.GetAttribute <CustomEditor>(editorScript);
                if (customEditorAttribute != null)
                {
                    Type inspectedType = typeof(CustomEditor).
                                         GetField("m_InspectedType", BindingFlags.NonPublic | BindingFlags.Instance).
                                         GetValue(customEditorAttribute) as Type;

                    bool editorForChildClasses = (bool)typeof(CustomEditor).
                                                 GetField("m_EditorForChildClasses", BindingFlags.NonPublic | BindingFlags.Instance).
                                                 GetValue(customEditorAttribute);

                    if (GetClassType() == inspectedType ||
                        (inspectedType.IsAssignableFrom(GetClassType()) &&
                         editorForChildClasses))
                    {
                        GroupsAttribute groupAttribute = AttributeHelper.GetAttribute <GroupsAttribute>(editorScript);
                        if (groupAttribute != null)
                        {
                            groups = new Groups(groupAttribute.groups);
                        }
                        else
                        {
                            groups = new Groups(new string[] { "" });
                        }

                        break;
                    }
                }
            }

            if (groups == null)
            {
                groups = new Groups(new string[] { "" });
            }
        }
Ejemplo n.º 17
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 = \"...\").");
                        }
                    }
                }
            }
        }
        private void InitializeLayouts()
        {
            horizontalLayout = HorizontalLayout.None;
            verticalLayout   = VerticalLayout.None;

            if (AttributeHelper.GetAttribute <BeginHorizontalAttribute> (renderer.entityInfo) != null)
            {
                this.horizontalLayout = HorizontalLayout.BeginHorizontal;
            }
            else if (AttributeHelper.GetAttribute <EndHorizontalAttribute> (renderer.entityInfo) != null)
            {
                this.horizontalLayout = HorizontalLayout.EndHorizontal;
            }

            if (AttributeHelper.GetAttribute <BeginVerticalAttribute> (renderer.entityInfo) != null)
            {
                this.verticalLayout = VerticalLayout.BeginVertical;
            }
            else if (AttributeHelper.GetAttribute <EndVerticalAttribute> (renderer.entityInfo) != null)
            {
                this.verticalLayout = VerticalLayout.EndVertical;
            }
        }
Ejemplo n.º 19
0
        public override void Render(Action preRender = null)
        {
            base.Render(preRender);

            if (!checkedIfReadOnly)
            {
                isReadOnly        = (AttributeHelper.GetAttribute <ReadOnlyAttribute>(entityInfo.fieldInfo) != null);
                checkedIfReadOnly = true;
            }

            ReorderableListGUI.Title(label);
            if (isReadOnly)
            {
                ReorderableListGUI.ListField(serializedProperty, ReorderableListFlags.DisableReordering
                                             | ReorderableListFlags.DisableContextMenu
                                             | ReorderableListFlags.HideAddButton
                                             | ReorderableListFlags.HideRemoveButtons);
            }
            else
            {
                ReorderableListGUI.ListField(serializedProperty);
            }
        }
Ejemplo n.º 20
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);
        }
Ejemplo n.º 21
0
        public static bool IsHideInInspector(FieldInfo fieldInfo)
        {
            HideInInspector attribute = AttributeHelper.GetAttribute <HideInInspector>(fieldInfo);

            return(attribute != null);
        }
Ejemplo n.º 22
0
        public static bool HasNotSerializedFieldAttribute(FieldInfo fieldInfo)
        {
            NonSerializedAttribute attribute = AttributeHelper.GetAttribute <NonSerializedAttribute>(fieldInfo);

            return(attribute != null);
        }
Ejemplo n.º 23
0
        public static bool HasSerializedFieldAttribute(FieldInfo fieldInfo)
        {
            Attribute attribute = AttributeHelper.GetAttribute <SerializeField>(fieldInfo);

            return(attribute != null);
        }