void PropSelection()
        {
            if (Target.Context == null)
            {
                EditorGUILayout.LabelField("Parent BindingContext not found.");

                var p = EditorGUILayout.TextField("Property", Target.PropertyName);

                if (p != Target.PropertyName)
                {
                    Target.PropertyName = p;
                    EditorUtility.SetDirty(target);
                }
            }
            else if (Target.Context.DataType == null)
            {
                EditorGUILayout.LabelField("Parent BindingContext.DataType not found.");

                var p = EditorGUILayout.TextField("Property", Target.PropertyName);

                if (p != Target.PropertyName)
                {
                    Target.PropertyName = p;
                    EditorUtility.SetDirty(target);
                }
            }
            else
            {
                var type = Target.Context.DataType;

                var members = EditorMembersHelper.GetProperties(type);

                if (members.Length == 0)
                {
                    EditorGUILayout.LabelField("This type has no fields or properties.");
                    return;
                }

                var choices = members.Where(o => !o.Module.Assembly.FullName.Contains("UnityEngine")).OrderBy(o => o.Name);

                var labels = choices.Select(o =>
                                            string.Format("{0} : {1}",
                                                          o.Name,
                                                          o.GetMemberType().Name
                                                          )).ToArray();

                var names = choices.Select(o => o.Name).ToArray();

                var index = Array.IndexOf(names, Target.PropertyName);

                var i = EditorGUILayout.Popup("Property / Field", index, labels.ToArray());

                if (i != index)
                {
                    Target.PropertyName = names[i];
                    EditorUtility.SetDirty(target);
                }
            }
        }
Esempio n. 2
0
        void PropertyDropDown(BindingBase.BindingInfo info)
        {
            var type = Target.Context.DataType;

            var members = new MemberInfo[0];

            // filter
            switch (info.Filters)
            {
            case BindingBase.BindingFilter.Commands:
                members = EditorMembersHelper.GetMethods(type);
                break;

            case BindingBase.BindingFilter.Properties:
                members = EditorMembersHelper.GetProperties(type);
                break;
            }

            //filter
            if (info.FilterTypes != null)
            {
                members = members.Where(o => info.FilterTypes.Any(t => ValidType(t, o.GetParamaterType()))).ToArray();
            }

            if (members.Length == 0)
            {
                EditorGUILayout.LabelField(string.Format("{0}->{1} has no valid members.", info.BindingName, type.Name));
                return;
            }

            var labels = members.Select(o => string.Format("{0} : {1}", o.Name, o.GetParamaterType())).ToList();

            var names = members.Select(o => o.Name).ToList();

            labels.Insert(0, "Null");
            names.Insert(0, "");

            var index = Array.IndexOf(names.ToArray(), info.MemberName);

            var i = EditorGUILayout.Popup(info.BindingName, index, labels.ToArray());

            if (i != index)
            {
                info.MemberName = names[i];
                EditorUtility.SetDirty(target);
            }
        }