Ejemplo n.º 1
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        var tc = GUI.color;

        if (Attr.Const && EditorApplication.isPlaying)
        {
            // 常量在播放时只在Repaint绘制并上灰色
            if (Event.current.type == EventType.Repaint)
            {
                GUI.color = Color.gray;
            }
            else
            {
                return;
            }
        }

        // 开始绘制
        label = new GUIContent(string.IsNullOrEmpty(Attr.Label) ? property.displayName : Attr.Label);

        Rect windowRect = new Rect(position.x, position.y + 2, position.width, position.height - 4);

        GUI.Box(windowRect, GUIContent.none, "button");

        Rect propRect = new Rect(position.x + 4, position.y + 6, position.width - 8, position.height - 12);

        EditorGUI.Slider(propRect, property, Attr.Left, Attr.Right, label);

        GUI.color = tc;

        LabelClipBoard.PopupMenu(position, property);
    }
Ejemplo n.º 2
0
    // static API
    public static void DrawLabel(Rect position, SerializedProperty property, string label, bool isConst = false, PropertyDrawer drawerOverride = null)
    {
        var tc = GUI.color;

        if (isConst && EditorApplication.isPlaying)
        {
            // 常量在播放时只在Repaint绘制并上灰色
            if (Event.current.type == EventType.Repaint)
            {
                GUI.color = Color.gray;
            }
            else
            {
                return;
            }
        }

        // 开始绘制
        label = string.IsNullOrEmpty(label) ? property.displayName : (property.displayName.StartsWith("Element") ? label + property.displayName.Substring(8) : label);

        if (drawerOverride == null)
        {
            var ic = GUI.color * (1 - EditorGUI.indentLevel * 0.15f);
            ic.a      = 1;
            GUI.color = ic;

            float indentWidth = EditorGUI.indentLevel * 16;

            Rect windowRect = new Rect(position.x + indentWidth, position.y + margin, position.width - indentWidth, position.height - margin);
            GUI.Box(windowRect, GUIContent.none, property.propertyType == SerializedPropertyType.Generic ? "FrameBox" : "button");

            Rect propRect = new Rect(position.x + paddingX, position.y + paddingY + margin, position.width - paddingX * 2, position.height - paddingY * 2 - margin);
            EditorGUI.PropertyField(propRect, property, new GUIContent(label), true);
        }
        else
        {
            drawerOverride.OnGUI(position, property, new GUIContent(label));
        }

        GUI.color = tc;

        if (!property.displayName.StartsWith("Element"))
        {
            LabelClipBoard.PopupMenu(position, property);
        }
    }
Ejemplo n.º 3
0
 public static void PopupMenu(Rect position, SerializedProperty property)
 {
     if (Event.current.isMouse && Event.current.button == 1 && position.Contains(Event.current.mousePosition))
     {
         EditorUtility.DisplayPopupMenu(new Rect(Event.current.mousePosition, Vector2.zero), "CONTEXT/LabelClipBoard/", LabelClipBoard.CreateMenuCommand(property));
     }
 }