Exemplo n.º 1
0
        public static bool CheckAccess(MemberInfo memberInfo, OSCReflectionAccess access)
        {
            if (memberInfo is FieldInfo)
            {
                return(true);
            }
            if (memberInfo is PropertyInfo)
            {
                return(CheckAccess((PropertyInfo)memberInfo, access));
            }
            if (memberInfo is MethodInfo)
            {
                return(CheckAccess((MethodInfo)memberInfo, access));
            }

            return(false);
        }
        public OSCReflectionMemberDrawer(
            SerializedProperty serializedProperty,
            Type memberType,
            OSCReflectionAccess reflectionAccess,
            OSCReflectionType reflectionType)
        {
            // Setup.
            _serializedProperty = serializedProperty;
            _memberType         = memberType;
            _reflectionAccess   = reflectionAccess;
            _reflectionType     = reflectionType;

            // Setup contents.
            _memberContent = _memberDefaultContent;
            _targetContent = _targetDefaultContent;

            // Find internal properties.
            _targetProperty = _serializedProperty.FindPropertyRelative("Target");
            _memberProperty = _serializedProperty.FindPropertyRelative("MemberName");
        }
Exemplo n.º 3
0
        public static bool CheckAccess(MethodInfo methodInfo, OSCReflectionAccess access)
        {
            if (access == OSCReflectionAccess.Read)
            {
                return(!(methodInfo.ReturnType == null || methodInfo.ReturnType == typeof(void)) && GetMethodWriteType(methodInfo) == null);
            }
            if (access == OSCReflectionAccess.Write)
            {
                return(GetMethodWriteType(methodInfo) != null);
            }
            if (access == OSCReflectionAccess.ReadWrite)
            {
                return(false);
            }
            if (access == OSCReflectionAccess.Any)
            {
                return(CheckAccess(methodInfo, OSCReflectionAccess.Read) || CheckAccess(methodInfo, OSCReflectionAccess.Write));
            }

            return(false);
        }
Exemplo n.º 4
0
        public static bool CheckAccess(PropertyInfo propertyInfo, OSCReflectionAccess access)
        {
            if (access == OSCReflectionAccess.ReadWrite && propertyInfo.CanWrite && propertyInfo.CanRead)
            {
                return(true);
            }
            if (access == OSCReflectionAccess.Read && propertyInfo.CanRead)
            {
                return(true);
            }
            if (access == OSCReflectionAccess.Write && propertyInfo.CanWrite)
            {
                return(true);
            }
            if (access == OSCReflectionAccess.Any)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 5
0
        public static MemberInfo[] GetMembersByAccess(Type targetType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
        {
            var members       = new List <MemberInfo>();
            var targetMembers = GetMembers(targetType, memberTypes);

            foreach (var memberInfo in targetMembers)
            {
                if (memberInfo is FieldInfo)
                {
                    members.Add(memberInfo);
                }
                else if (memberInfo is PropertyInfo)
                {
                    var propertyInfo = (PropertyInfo)memberInfo;

                    if (!CheckAccess(propertyInfo, valueAccess))
                    {
                        continue;
                    }

                    members.Add(memberInfo);
                }
                else if (memberInfo is MethodInfo)
                {
                    var methodInfo = memberInfo as MethodInfo;

                    if (!CheckAccess(methodInfo, valueAccess))
                    {
                        continue;
                    }

                    members.Add(memberInfo);
                }
            }

            return(members.ToArray());
        }
        private static void ReflectionMember(Rect rect, SerializedProperty reflectionMemberProperty, Type reflectionType, OSCReflectionAccess access)
        {
            var targetProperty     = reflectionMemberProperty.FindPropertyRelative("Target");
            var memberNameProperty = reflectionMemberProperty.FindPropertyRelative("MemberName");

            var firstLine  = new Rect(rect.x, rect.y, rect.width, EditorGUIUtility.singleLineHeight);
            var secondLine = new Rect(rect.x, rect.y + rect.height / 2f, rect.width, EditorGUIUtility.singleLineHeight);


            EditorGUI.PropertyField(firstLine, targetProperty, _targetContent);

            if (targetProperty.objectReferenceValue != null)
            {
                GUI.enabled = memberNameProperty.stringValue != "- None -";

                memberNameProperty.stringValue = PropertiesPopup(secondLine,
                                                                 targetProperty.objectReferenceValue,
                                                                 memberNameProperty.stringValue,
                                                                 reflectionType,
                                                                 _propertyContent,
                                                                 access);
            }
            else
            {
                GUI.enabled = false;

                EditorGUI.Popup(secondLine, _propertyContent, 0, _propertyPopupOptions);
            }

            GUI.enabled = true;
        }
        private static string PropertiesPopup(Rect rect, object target, string memberName, Type propertyType, GUIContent content, OSCReflectionAccess access)
        {
            var members   = OSCReflection.GetMembersByType(target, propertyType, access, OSCReflectionType.All);
            var clearName = new List <GUIContent>();

            var currentIndex = 0;

            // GET INDEX
            foreach (var member in members)
            {
                if (member.Name == memberName)
                {
                    currentIndex = clearName.Count;
                }

                clearName.Add(new GUIContent(OSCEditorUtils.MemberName(member)));
            }

            if (clearName.Count == 0)
            {
                clearName.Add(new GUIContent("- None -"));
            }

            currentIndex = EditorGUI.Popup(rect, content, currentIndex, clearName.ToArray());
            currentIndex = Mathf.Clamp(currentIndex, 0, clearName.Count - 1);

            return(members.Length > 0 ? members[currentIndex].Name : "- None -");
        }
Exemplo n.º 8
0
        public static void ReflectionMember(SerializedProperty reflectionMemberProperty, Type reflectionType, OSCReflectionAccess access)
        {
            var targetProperty     = reflectionMemberProperty.FindPropertyRelative("Target");
            var memberNameProperty = reflectionMemberProperty.FindPropertyRelative("MemberName");

            EditorGUILayout.PropertyField(targetProperty, _targetContent);

            if (targetProperty.objectReferenceValue != null)
            {
                GUI.enabled = memberNameProperty.stringValue != "- None -";

                memberNameProperty.stringValue = PropertiesPopup(targetProperty.objectReferenceValue,
                                                                 memberNameProperty.stringValue,
                                                                 reflectionType,
                                                                 _propertyContent,
                                                                 access);
            }
            else
            {
                GUI.enabled = false;

                EditorGUILayout.Popup(_propertyContent, 0, _propertyPopupOptions);
            }

            GUI.enabled = true;
        }
Exemplo n.º 9
0
        public static MemberInfo[] GetMembersByType(Type targetType, Type valueType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
        {
            var members       = new List <MemberInfo>();
            var targetMembers = GetMembers(targetType, memberTypes);

            foreach (var memberInfo in targetMembers)
            {
                if (memberInfo is FieldInfo)
                {
                    var fieldInfo = (FieldInfo)memberInfo;

                    if (fieldInfo.FieldType == valueType)
                    {
                        members.Add(memberInfo);
                    }
                }
                else if (memberInfo is PropertyInfo)
                {
                    var propertyInfo = (PropertyInfo)memberInfo;

                    if (!CheckAccess(propertyInfo, valueAccess))
                    {
                        continue;
                    }

                    if (propertyInfo.PropertyType == valueType)
                    {
                        members.Add(memberInfo);
                    }
                }
                else if (memberInfo is MethodInfo)
                {
                    var methodInfo = memberInfo as MethodInfo;

                    if (!CheckAccess(methodInfo, valueAccess))
                    {
                        continue;
                    }

                    if (valueAccess == OSCReflectionAccess.Any)
                    {
                        if (GetMethodReadType(methodInfo) == valueType ||
                            GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.ReadWrite)
                    {
                        if (GetMethodReadType(methodInfo) == valueType ||
                            GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.Read)
                    {
                        if (GetMethodReadType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                    if (valueAccess == OSCReflectionAccess.Write)
                    {
                        if (GetMethodWriteType(methodInfo) == valueType)
                        {
                            members.Add(memberInfo);
                        }

                        continue;
                    }
                }
            }

            return(members.ToArray());
        }
Exemplo n.º 10
0
 public static MemberInfo[] GetMembersByType(object memberTarget, Type valueType, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
 {
     return(GetMembersByType(memberTarget.GetType(), valueType, valueAccess, memberTypes));
 }
Exemplo n.º 11
0
 public static MemberInfo[] GetMembersByAccess(object target, OSCReflectionAccess valueAccess, OSCReflectionType memberTypes)
 {
     return(GetMembersByAccess(target.GetType(), valueAccess, memberTypes));
 }