Exemplo n.º 1
0
 string GetCheersTitle(See attr, MemberInfo member)
 {
     if (attr.Title == null || string.IsNullOrEmpty(attr.Title.Trim()))
     {
         return(ObjectNames.NicifyVariableName(member.Name));
     }
     return(attr.Title);
 }
Exemplo n.º 2
0
        void DrawProperty(PropertyInfo prop, See attr, Obj[] targets)
        {
            Undo.RecordObjects(targets, "PropertyChange-" + prop.Name);

            var propType = prop.PropertyType;
            var getter   = prop.GetGetMethod(true);
            var setter   = prop.GetSetMethod(true);

            var label = GetCheersTitle(attr, prop);

            bool hasMultiValues;
            bool isReadOnly = setter == null;
            // 获取所有选中项的属性值的最小集合
            var values = targets.Select(t => GetPropValue(propType, getter, t)).Distinct();
            // 用于绘制编辑器的回调
            var editorFunc = GetValuesAndEditor(propType, getter, values, label, out hasMultiValues);

            if (editorFunc == null)
            {
                return;
            }

            // 选中项的属性值是否各不相同,如果有则在编辑器中画 "-"
            EditorGUI.showMixedValue = hasMultiValues;
            // 如果为只读属性则置灰
            if (isReadOnly)
            {
                EditorGUI.BeginDisabledGroup(true);
            }
            EditorGUI.BeginChangeCheck();
            var commonValue = editorFunc();

            if (EditorGUI.EndChangeCheck())
            { // 有改动才为属性赋值
                targets.ForEach(t => setter.Invoke(t, new[] { commonValue }));
            }
            if (isReadOnly)
            {
                EditorGUI.EndDisabledGroup();
            }
            EditorGUI.showMixedValue = false;
        }
Exemplo n.º 3
0
        void DrawMethod(MethodInfo method, See attr, Obj[] targets)
        {
            var @params  = method.GetParameters();
            var btnText  = new GUIContent(GetCheersTitle(attr, method));
            var canPress = true;

            if (@params.Length > 0)
            {
                btnText.text += "\n(Parameters are not supported yet)";
                btnText.image = EditorHelper.icons.warning;
                canPress      = false;
            }
            EditorGUI.BeginDisabledGroup(!canPress);

            var bgColor    = attr.BackgroundColor == Color.clear ? GUI.backgroundColor : attr.BackgroundColor;
            var oldBgColor = GUI.backgroundColor;

            GUI.backgroundColor = bgColor;
            var btnStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).button);

            if (attr.TextColor != Color.clear)
            {
                btnStyle.normal.textColor  = attr.TextColor;
                btnStyle.hover.textColor   = attr.TextColor;
                btnStyle.focused.textColor = attr.TextColor;
                btnStyle.active.textColor  = attr.TextColor;
            }
            if (GUILayout.Button(btnText, btnStyle))
            {
                StringBuilder retSb = new StringBuilder("=== Call Returns ===\n");
                foreach (var t in targets)
                {
                    var ret = method.Invoke(t, null);
                    retSb.AppendLine(string.Format(" - {0} >> {1}", t.name, ret ?? "(null)"));
                }
                //PrettyLog.Log(retSb.ToString());
            }
            GUI.backgroundColor = oldBgColor;

            EditorGUI.EndDisabledGroup();
        }