예제 #1
0
        void RefreshBindingObject(M4uBindingObject bo, bool isRead)
        {
            if (bo.IsOwnGameObjectOnly)
            {
                bo.Object = binding.gameObject;
            }

            bo.Members.Clear();
            if (isRead)
            {
                var mes = bo.IsDynamicBinding ? EmptyDynamicReadMessage  : FirstSelectReadMessage;
                bo.Members.Add(new M4uBindingMember(mes));
            }
            else
            {
                var mes = bo.IsDynamicBinding ? EmptyDynamicWriteMessage : FirstSelectWriteMessage;
                bo.Members.Add(new M4uBindingMember(mes));
            }

            if (bo.Object is GameObject)
            {
                var components = ((GameObject)bo.Object).GetComponents <Component>();
                foreach (var component in components)
                {
                    LoadMembers(bo, component);
                }
            }
            else if (bo.Object != null)
            {
                LoadMembers(bo, bo.Object);
            }

            bo.MemberPaths = bo.Members.Select(m => m.MemberPath).ToArray();
        }
예제 #2
0
        void DrawBindingObject(M4uBindingObject bo)
        {
            EditorGUILayout.BeginHorizontal();

            var baseRect = EditorGUILayout.GetControlRect();

            if (bo.IsDynamicBinding)
            {
                var memberPath = EditorGUI.TextField(baseRect, bo.SelectMember.MemberPath);
                if (!Application.isPlaying)
                {
                    if (string.IsNullOrEmpty(memberPath) ||
                        memberPath == FirstSelectReadMessage ||
                        memberPath == FirstSelectWriteMessage)
                    {
                        bo.SelectMember.MemberPath = bo.MemberPaths[0];
                    }
                    else
                    {
                        bo.SelectMember.MemberPath = memberPath;
                    }
                }
            }
            else
            {
                var rect = baseRect;
                rect.width *= ObjectFieldWidthRate;

                if (bo.IsOwnGameObjectOnly)
                {
                    EditorGUI.BeginDisabledGroup(true);
                }
                {
                    GUI.Box(rect, "");
                    bo.Object = EditorGUI.ObjectField(rect, bo.Object, typeof(Object), true);
                }
                if (bo.IsOwnGameObjectOnly)
                {
                    EditorGUI.EndDisabledGroup();
                }

                rect.x    += rect.width + Object2MemberSpace;
                rect.width = baseRect.width * MemberPopupWidthRate - Object2MemberSpace;

                var memeberIdx = Array.IndexOf(bo.MemberPaths, bo.MemberPath);
                memeberIdx = Mathf.Max(memeberIdx, 0);
                memeberIdx = EditorGUI.Popup(rect, memeberIdx, bo.MemberPaths);
                if (!Application.isPlaying)
                {
                    bo.MemberPath   = bo.MemberPaths[memeberIdx];
                    bo.SelectMember = bo.Members.Find(m => m.MemberPath == bo.MemberPath);
                }
            }

            EditorGUILayout.EndHorizontal();
        }
예제 #3
0
        void InitializeDynamicMember(M4uBindingObject bo, M4uBindingMember bm)
        {
            if (bm.BindObject == null)
            {
                return;
            }

            var memberNames = bm.MemberPath.Replace('.', '/').Split('/');
            var @object     = bm.BindObject;

            for (var i = 1; i < memberNames.Length; i++)
            {
                var isLast     = (i == memberNames.Length - 1);
                var memberName = memberNames[i];
                var objectType = @object.GetType();

                if (isLast)
                {
                    var memberInfos = objectType.GetMember(memberName, bo.BindingFlags);
                    if (memberInfos != null && memberInfos.Length >= 1)
                    {
                        var memberType = memberInfos[0].MemberType;
                        if (memberType == MemberTypes.Field)
                        {
                            bm.SetDynamicObject(M4uMemberType.Field, memberName, @object);
                        }
                        else if (memberType == MemberTypes.Property)
                        {
                            bm.SetDynamicObject(M4uMemberType.Property, memberName, @object);
                        }
                    }
                }
                else
                {
                    var nowObject = default(object);
                    if (bo.IsGetProperty)
                    {
                        var propertyInfo = objectType.GetProperty(memberName, bo.BindingFlags);
                        nowObject = propertyInfo?.GetValue(@object);
                    }

                    if (bo.IsGetField && nowObject == null)
                    {
                        var fieldInfo = objectType.GetField(memberName, bo.BindingFlags);
                        nowObject = fieldInfo?.GetValue(@object);
                    }

                    if (nowObject == null)
                    {
                        break;
                    }
                    @object = nowObject;
                }
            }
        }
예제 #4
0
        void LoadMembers(M4uBindingObject bo, Object @object)
        {
            if (bo.IsNotifierOnly && !(@object is IM4uNotifier))
            {
                return;
            }
            if (bo.IsDynamicBinding)
            {
                return;
            }

            var objectType  = @object.GetType();
            var objectName  = objectType.Name;
            var memberInfos = objectType.GetMembers(bo.BindingFlags);

            foreach (var memberInfo in memberInfos)
            {
                var memberType = M4uMemberType.None;
                if (memberInfo.MemberType == MemberTypes.Field)
                {
                    if (!bo.IsGetField)
                    {
                        continue;
                    }
                    memberType = M4uMemberType.Field;
                }
                else if (memberInfo.MemberType == MemberTypes.Property)
                {
                    if (!bo.IsGetProperty)
                    {
                        continue;
                    }
                    memberType = M4uMemberType.Property;
                }
                else
                {
                    continue;
                }

                var memberName = memberInfo.Name;
                var memberPath = $"{objectName}/{memberName}";
                var member     = new M4uBindingMember(memberPath, memberType, @object, memberName);
                bo.Members.Add(member);
            }
        }
예제 #5
0
        void InitializeDynamicObject(M4uBindingObject bo, M4uBindingMember bm)
        {
            var memberNames   = bm.MemberPath.Replace('.', '/').Split('/');
            var componentName = memberNames[0];
            var transform     = this.transform;
            var @object       = default(object);

            do
            {
                var component = transform.GetComponent(componentName);
                if (component != null && (!bo.IsNotifierOnly || component is IM4uNotifier))
                {
                    @object = component;
                    break;
                }
                transform = transform.parent;
            }while(transform != null && !bo.IsOwnGameObjectOnly);

            bm.BindObject = @object;
            bm.MemberName = memberNames.Last();
        }