Ejemplo n.º 1
0
        /// <inheritdoc />
        public override void SetupInterface(object attribute, object setValue, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var parametersProvider = attribute as IDrawerSetupDataProvider;

            if (parametersProvider == null)
            {
                parametersProvider = setMemberInfo.GetAttribute <IDrawerSetupDataProvider>();

                                #if DEV_MODE
                if (parametersProvider == null)
                {
                    throw new NullReferenceException("StyledTextDrawer.Setup MemberInfo did not contain attribute that implements IDrawerSetupDataProvider");
                }
                Debug.LogWarning("StyledTextDrawer.SetupInterface - provided attribute " + (attribute == null ? "null" : attribute.GetType().Name) + " did not implement IDrawerSetupDataProvider, but fetched it manually from LinkedMemberInfo.");
                                #endif
            }
            var parameters  = parametersProvider.GetSetupParameters();
            var setGuiStyle = Inspector.Preferences.GetStyle((string)parameters[0]);

            string text = setValue as string;
            if (text == null)
            {
                text = StringUtils.ToString(setValue);
            }

            Setup(setGuiStyle, text, typeof(string), setMemberInfo, setParent, setLabel, setReadOnly, setMemberInfo != null && setMemberInfo.GetAttribute <TextAreaAttribute>() != null, setMemberInfo != null && setMemberInfo.GetAttribute <DelayedAttribute>() != null);
        }
Ejemplo n.º 2
0
 protected bool GetIsReadOnly([CanBeNull] LinkedMemberInfo memberInfo, bool defaultValue)
 {
     if (memberInfo != null && memberInfo.GetAttribute <ReadOnlyAttribute>() != null)
     {
         return(true);
     }
     return(defaultValue);
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var      button = setMemberInfo.GetAttribute <ButtonAttribute>();
            string   setButtonText;
            GUIStyle setGUIStyle;

            if (button != null)
            {
                if (!string.IsNullOrEmpty(button.buttonText))
                {
                    setButtonText = button.buttonText;
                }
                else
                {
                    if (setLabel != null)
                    {
                        setButtonText = setLabel.text;
                    }
                    else
                    {
                        setButtonText = setMemberInfo.DisplayName;
                    }
                }

                GUIContentPool.Replace(ref setLabel, button.prefixLabelText);

                if (!string.IsNullOrEmpty(button.guiStyle))
                {
                    setGUIStyle = InspectorUtility.Preferences.GetStyle(button.guiStyle);
                    if (setGUIStyle == null)
                    {
                        setGUIStyle = InspectorPreferences.Styles.Button;
                    }
                }
                else
                {
                    setGUIStyle = InspectorPreferences.Styles.Button;
                }
            }
            else
            {
                setGUIStyle = InspectorPreferences.Styles.Button;

                if (setLabel != null)
                {
                    setButtonText = setLabel.text;
                }
                else
                {
                    setButtonText = setMemberInfo.DisplayName;
                }

                GUIContentPool.Replace(ref setLabel, "");
            }

            Setup(setMemberInfo, setParent, setLabel, GUIContentPool.Create(setButtonText), setGUIStyle, setReadOnly);
        }
Ejemplo n.º 4
0
        /// <inheritdoc cref="IFieldDrawer.SetupInterface"/>
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var parameterProvider = setMemberInfo.GetAttribute <IDrawerSetupDataProvider>();
            var parameters        = parameterProvider.GetSetupParameters();
            var setStyle          = Inspector.Preferences.GetStyle((string)parameters[0]);
            int parameterCount    = parameters.Length;
            var setIndent         = parameterCount > 1 ? (int)parameters[1] : 1;
            var setDrawHeader     = parameterCount > 2 ? (bool)parameters[2] : true;

            Setup(setStyle, setIndent, setDrawHeader, setValue, setValueType, setMemberInfo, setParent, setDrawHeader ? setLabel : GUIContent.none, setReadOnly);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            var parametersProvider = setMemberInfo.GetAttribute <IDrawerSetupDataProvider>();
            var parameters         = parametersProvider.GetSetupParameters();
            var setGuiStyle        = Inspector.Preferences.GetStyle((string)parameters[0]);

            string text = setValue as string;

            if (text == null)
            {
                text = StringUtils.ToString(setValue);
            }
            Setup(setGuiStyle, text, setValueType, setMemberInfo, setParent, setLabel, setReadOnly, setMemberInfo != null && setMemberInfo.GetAttribute <TextAreaAttribute>() != null, setMemberInfo != null && setMemberInfo.GetAttribute <DelayedAttribute>() != null);
        }
Ejemplo n.º 6
0
 /// <inheritdoc/>
 public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
                 #if UNITY_2019_2_OR_NEWER
     var        inspectorName = setMemberInfo.GetAttribute <InspectorNameAttribute>();
     GUIContent setButtonLabel;
     if (inspectorName != null)
     {
         setButtonLabel = GUIContentPool.Create(inspectorName.displayName);
     }
     else
     {
         setButtonLabel = null;
     }
     Setup(setMemberInfo, setParent, setLabel, setButtonLabel, setReadOnly);
                 #else
     Setup(setMemberInfo, setParent, setLabel, null, setReadOnly);
                 #endif
 }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        protected override void Setup(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(memberBuildState == MemberBuildState.Unstarted);
                        #endif

            if (setValue == null)
            {
                setValueType = DrawerUtility.GetType(setMemberInfo, setValue);
            }

            // This is an important step, because parent is referenced by DebugMode
            parent          = setParent;
            drawInSingleRow = (setMemberInfo != null && setMemberInfo.GetAttribute <Attributes.DrawInSingleRowAttribute>() != null) || (setValueType != null && setValueType.GetCustomAttributes(typeof(Attributes.DrawInSingleRowAttribute), false).Length > 0) || DrawerUtility.CanDrawInSingleRow(setValueType, DebugMode);

            base.Setup(setValue, setValueType, setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && DEBUG_DRAW_IN_SINGLE_ROW
            if (drawInSingleRow)
            {
                Debug.Log(Msg(ToString(setLabel, setMemberInfo) + ".Setup with drawInSingleRow=", drawInSingleRow, ", setValueType=", setValueType, ", DebugMode=", DebugMode, ", setMemberInfo.Type=" + (setMemberInfo == null ? "n/a" : StringUtils.ToString(setMemberInfo.Type)) + ", setValue.GetType()=", StringUtils.TypeToString(setValue)));
            }
                        #endif
        }
Ejemplo n.º 8
0
        private void Setup(object setValue, [CanBeNull] object attribute, [CanBeNull] UnityEditor.PropertyDrawer setDrawerInstance, [NotNull] Type drawerType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerType != null);
                        #endif

            if (setDrawerInstance == null)
            {
                setDrawerInstance = (UnityEditor.PropertyDrawer)drawerType.CreateInstance();
            }
            drawerInstance = setDrawerInstance;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerInstance != null, "Failed to create PropertyDrawer instance of type " + StringUtils.ToString(drawerType) + " for field of type " + StringUtils.ToString(DrawerUtility.GetType(setMemberInfo, setValue)) + " and attribute " + StringUtils.TypeToString(setMemberInfo == null ? null : setMemberInfo.GetAttribute <PropertyAttribute>()));
                        #endif

            memberInfo = setMemberInfo;

            var attField = drawerType.GetField("m_Attribute", BindingFlags.Instance | BindingFlags.NonPublic);

            if (setMemberInfo != null)
            {
                if (attribute != null)
                {
                                        #if DEV_MODE && DEBUG_ENABLED
                    Debug.Log("Setting field " + drawerType.Name + ".m_Attribute value to " + StringUtils.TypeToString(attribute));
                                        #endif

                    attField.SetValue(drawerInstance, attribute);
                }

                attField = drawerType.GetField("m_FieldInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                attField.SetValue(drawerInstance, setMemberInfo.FieldInfo);
            }
            else
            {
                Debug.LogError("PropertyDrawerDrawer(\"" + (setLabel != null ? setLabel.text : "") + "\").Setup(" + drawerType.Name + ") - fieldInfo was null (parent=" + StringUtils.ToString(setParent) + ")");
            }

            base.Setup(setValue, DrawerUtility.GetType(setMemberInfo, setValue), setMemberInfo, setParent, setLabel, setReadOnly);

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(SerializedProperty != null, StringUtils.ToColorizedString(GetDevInfo()));
                        #endif
        }
Ejemplo n.º 9
0
 /// <inheritdoc cref="IFieldDrawer.SetupInterface" />
 public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
     SetupInterface(setMemberInfo.GetAttribute <PropertyAttribute>(), setValue, setMemberInfo, setParent, setLabel, setReadOnly);
 }
Ejemplo n.º 10
0
        /// <inheritdoc/>
        public virtual void SetupInterface(object attribute, object setValue, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
            bool setTextArea = attribute is TextAreaAttribute || attribute is MultilineAttribute || attribute is PTextAreaAttribute || attribute is PMultilineAttribute || (setMemberInfo != null && setMemberInfo.HasAnyAttribute <TextAreaAttribute, MultilineAttribute, PTextAreaAttribute, PMultilineAttribute>());
            bool setDelayed  = attribute is DelayedAttribute || (setMemberInfo != null && setMemberInfo.GetAttribute <DelayedAttribute>() != null);

            Setup(setValue as string, setMemberInfo, setParent, setLabel, setReadOnly, setTextArea, setDelayed);
        }
Ejemplo n.º 11
0
 /// <inheritdoc cref="IFieldDrawer.SetupInterface" />
 public override void SetupInterface(object setValue, Type setValueType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
 {
     Setup(setValue as string, setMemberInfo, setParent, setLabel, setReadOnly, setMemberInfo != null && setMemberInfo.GetAttribute <TextAreaAttribute>() != null, setMemberInfo != null && setMemberInfo.GetAttribute <DelayedAttribute>() != null);
 }
Ejemplo n.º 12
0
        /// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary>
        /// <param name="guiStyle"> The starting cached value of the drawer. </param>
        /// <param name="text"> The starting cached value of the drawer. </param>
        /// <param name="memberInfo"> LinkedMemberInfo for the field, property or parameter that the drawer represents. Can be null. </param>
        /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param>
        /// <param name="label"> The prefix label. </param>
        /// <param name="readOnly"> True if control should be read only. </param>
        /// <returns> The instance, ready to be used. </returns>
        public static StyledTextDrawer Create([NotNull] GUIStyle guiStyle, string text, [CanBeNull] IParentDrawer parent, LinkedMemberInfo memberInfo = null, GUIContent label = null, bool readOnly = false)
        {
            StyledTextDrawer result;

            if (!DrawerPool.TryGet(out result))
            {
                result = new StyledTextDrawer();
            }
            result.Setup(guiStyle, text, typeof(string), memberInfo, parent, label, readOnly, memberInfo != null && memberInfo.GetAttribute <TextAreaAttribute>() != null, memberInfo != null && memberInfo.GetAttribute <DelayedAttribute>() != null);
            result.LateSetup();
            return(result);
        }
Ejemplo n.º 13
0
        public string GetTooltip([NotNull] LinkedMemberInfo linkedInfo)
        {
            var memberInfo = linkedInfo.MemberInfo;

            string tooltip;

            if (memberInfo == null)
            {
                var parameterInfo = linkedInfo.ParameterInfo;
                if (parameterInfo != null)
                {
                    var parent = linkedInfo.Parent;
                    if (parent == null)
                    {
                                                #if DEV_MODE && DEBUG_GET_TOOLTIP
                        Debug.Log(linkedInfo + " can't have tooltip because had no parent.");
                                                #endif

                        return("");
                    }
                    return(GetTooltipFromParent(parameterInfo, parent, linkedInfo.DisplayName));
                }

                                #if DEV_MODE && DEBUG_GET_TOOLTIP
                Debug.Log(linkedInfo + " can't have tooltip because had no MemberInfo and was not a parameter.");
                                #endif

                return("");
            }

            if (memberTooltips.TryGetValue(memberInfo, out tooltip))
            {
                                #if DEV_MODE && DEBUG_GET_TOOLTIP
                Debug.Log(linkedInfo + " cached tooltip: \"" + tooltip + "\"");
                                #endif
                return(tooltip);
            }

            var tooltipAttribute = linkedInfo.GetAttribute <TooltipAttribute>();
            if (tooltipAttribute != null)
            {
                tooltip = tooltipAttribute.tooltip;
                memberTooltips.Add(memberInfo, tooltip);
                                #if DEV_MODE && DEBUG_GET_TOOLTIP
                Debug.Log(linkedInfo + " tooltip from TooltipAttribute: \"" + tooltip + "\"");
                                #endif
                return(tooltip);
            }

            Dictionary <string, string> tooltips;
            var memberName = memberInfo.Name;

            // Try finding tooltip via parent LinkedMemberInfos types
            for (var parent = linkedInfo.Parent; parent != null; parent = parent.Parent)
            {
                tooltips = GetMemberTooltips(parent.Type);
                if (TryGetTooltip(tooltips, memberName, out tooltip))
                {
                    memberTooltips.Add(memberInfo, tooltip);

                                        #if DEV_MODE && DEBUG_GET_TOOLTIP
                    if (tooltip.Length > 0)
                    {
                        Debug.Log(linkedInfo + " tooltip from xml docs via parent " + parent.Type + ": \"" + tooltip + "\"");
                    }
                    else
                    {
                        Debug.Log(linkedInfo + " no tooltip found.");
                    }
                                        #endif

                    return(tooltip);
                }
            }

            // Try finding tooltip via UnityEngine.Object target type.
            // NOTE: Doing this even if LinkedMemberInfo has parent LinkedMemberInfos, because it's possible that
            // there's another class defined inside a script file that also defines the target UnityEngine.Object class.
            var unityObject = linkedInfo.Hierarchy.Target;
            if (unityObject != null)
            {
                tooltips = GetMemberTooltips(unityObject);
                if (TryGetTooltip(tooltips, memberName, out tooltip))
                {
                    memberTooltips.Add(memberInfo, tooltip);

                                        #if DEV_MODE && DEBUG_GET_TOOLTIP
                    if (tooltip.Length > 0)
                    {
                        Debug.Log(linkedInfo + " tooltip from xml docs via UnityObject " + unityObject.GetType().Name + ": \"" + tooltip + "\"");
                    }
                    else
                    {
                        Debug.Log(linkedInfo + " no tooltip found.");
                    }
                                        #endif

                    return(tooltip);
                }
            }

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(string.IsNullOrEmpty(tooltip));
                        #endif

            memberTooltips.Add(memberInfo, "");

                        #if DEV_MODE && DEBUG_GET_TOOLTIP
            Debug.Log(linkedInfo + " no tooltip found.");
                        #endif

            return("");
        }
Ejemplo n.º 14
0
        private void Setup(object setValue, [CanBeNull] UnityEditor.PropertyDrawer setDrawerInstance, [NotNull] Type drawerType, LinkedMemberInfo setMemberInfo, IParentDrawer setParent, GUIContent setLabel, bool setReadOnly)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerType != null);
                        #endif

            if (setDrawerInstance == null)
            {
                setDrawerInstance = (UnityEditor.PropertyDrawer)drawerType.CreateInstance();
            }
            drawerInstance = setDrawerInstance;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(drawerInstance != null, "Failed to create PropertyDrawer instance of type " + StringUtils.ToString(drawerType) + " for field of type " + StringUtils.ToString(DrawerUtility.GetType(setMemberInfo, setValue)) + " and attribute " + StringUtils.TypeToString(setMemberInfo == null ? null : setMemberInfo.GetAttribute <PropertyAttribute>()));
                        #endif

            memberInfo = setMemberInfo;

            var serializedProperty = SerializedProperty;
            if (serializedProperty != null)
            {
                // This is not fool-proof, because e.g. a custom property might use a foldout drawer
                // but could not figure out a better solution yet
                usesFoldout = serializedProperty.isArray;
            }
            else
            {
                usesFoldout = false;
            }

            var attField = drawerType.GetField("m_Attribute", BindingFlags.Instance | BindingFlags.NonPublic);

            if (setMemberInfo != null)
            {
                var atts = setMemberInfo.GetAttributes(Types.PropertyAttribute);
                if (atts.Length > 0)
                {
                    attField.SetValue(drawerInstance, atts[0]);
                }

                attField = drawerType.GetField("m_FieldInfo", BindingFlags.Instance | BindingFlags.NonPublic);
                attField.SetValue(drawerInstance, setMemberInfo.FieldInfo);
            }
            else
            {
                Debug.LogError("PropertyDrawerDrawer(\"" + (setLabel != null ? setLabel.text : "") + "\").Setup(" + drawerType.Name + ") - fieldInfo was null (parent=" + StringUtils.ToString(setParent) + ")");
            }

            base.Setup(setValue, DrawerUtility.GetType(setMemberInfo, setValue), setMemberInfo, setParent, setLabel, setReadOnly);
        }