Ejemplo n.º 1
0
        private void DrawContextData(Context context, int level)
        {
            var prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = level;

            var contextMemberInfos = ContextTypeCache.GetMemberInfos(context.GetType());

            foreach (var contextMemberInfo in contextMemberInfos)
            {
                if (contextMemberInfo.Property != null)
                {
                    var memberValue    = contextMemberInfo.Property.GetValue(context, null);
                    var newMemberValue = this.DrawContextData(contextMemberInfo.Name,
                                                              contextMemberInfo.Property.PropertyType, memberValue, level);
                    if (contextMemberInfo.Property.CanWrite && !Equals(newMemberValue, memberValue))
                    {
                        contextMemberInfo.Property.SetValue(context, newMemberValue, null);
                    }
                }
                else if (contextMemberInfo.Method != null)
                {
                    this.DrawContextMethod(context, contextMemberInfo.Method);
                }
            }

            EditorGUI.indentLevel = prevIndentLevel;
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var contextPathAttribute = this.attribute as ContextPathAttribute;
            var pathDisplayName      =
                contextPathAttribute != null && !string.IsNullOrEmpty(contextPathAttribute.PathDisplayName)
                    ? contextPathAttribute.PathDisplayName
                    : "Path";

            var targetObject = property.serializedObject.targetObject;

            // Check if target object has a custom context type.
            var contextTypeProperty = property.serializedObject.FindProperty("ContextType");
            var dataContextType     = contextTypeProperty != null
                ? ReflectionUtils.FindType(contextTypeProperty.stringValue)
                : ContextTypeEditorUtils.GetContextType((Component)targetObject);

            if (dataContextType != this.currentDataContextType)
            {
                this.dataContextPaths = ContextTypeCache.GetPaths(
                    dataContextType,
                    contextPathAttribute != null ? contextPathAttribute.Filter : ContextMemberFilter.All);
                this.currentDataContextType = dataContextType;
            }

            var hasCustomPath = this.HasCustomPath(property.propertyPath);

            property.stringValue = PathPopup(
                position,
                property.stringValue, this.dataContextPaths,
                pathDisplayName,
                ref hasCustomPath);
            this.hasPropertyCustomPath[property.propertyPath] = hasCustomPath;
        }
Ejemplo n.º 3
0
        private void DrawObjectData(object obj, int level)
        {
            if (obj == null)
            {
                return;
            }

            var prevIndentLevel = EditorGUI.indentLevel;

            EditorGUI.indentLevel = level;

            var memberInfos = ContextTypeCache.GetMemberInfos(obj.GetType());

            foreach (var memberInfo in memberInfos)
            {
                if (memberInfo.Property != null)
                {
                    var propertySetMethod = memberInfo.Property.GetSetMethod();
                    if (memberInfo.Property.CanWrite && propertySetMethod != null && propertySetMethod.IsPublic)
                    {
                        var memberValue    = memberInfo.Property.GetValue(obj, null);
                        var newMemberValue = this.DrawMemberData(memberInfo.Name,
                                                                 memberInfo.Property.PropertyType, memberValue, level);
                        if (!Equals(newMemberValue, memberValue))
                        {
                            memberInfo.Property.SetValue(obj, newMemberValue, null);
                        }
                    }
                }
                else if (memberInfo.Method != null)
                {
                    this.DrawObjectMethod(obj, memberInfo.Method);
                }
                else if (memberInfo.Field != null)
                {
                    if (memberInfo.Field.IsPublic)
                    {
                        var memberValue    = memberInfo.Field.GetValue(obj);
                        var newMemberValue = this.DrawMemberData(memberInfo.Name,
                                                                 memberInfo.Field.FieldType, memberValue, level);
                        if (!Equals(newMemberValue, memberValue))
                        {
                            memberInfo.Field.SetValue(obj, newMemberValue);
                        }
                    }
                }
            }

            EditorGUI.indentLevel = prevIndentLevel;
        }
Ejemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var contextPathAttribute = this.attribute as ContextPathAttribute;
            var pathDisplayName      = contextPathAttribute != null &&
                                       !string.IsNullOrEmpty(contextPathAttribute.PathDisplayName)
                 ? contextPathAttribute.PathDisplayName
                 : "Path";

            var targetObject  = property.serializedObject.targetObject;
            var contextType   = ContextTypeEditorUtils.GetContextType((Component)targetObject);
            var hasCustomPath = this.HasCustomPath(property.propertyPath);

            property.stringValue = PathPopup(
                position,
                property.stringValue,
                ContextTypeCache.GetPaths(
                    contextType,
                    contextPathAttribute != null ? contextPathAttribute.Filter : ContextMemberFilter.All),
                pathDisplayName,
                ref hasCustomPath);
            this.hasPropertyCustomPath[property.propertyPath] = hasCustomPath;
        }