示例#1
0
        /// <summary>
        /// Draws a objectpicker butter, in the given rect. This one is designed to look good on top of DrawDropZone().
        /// </summary>
        public static object ObjectPickerZone(Rect rect, object value, Type type, bool allowSceneObjects, int id)
        {
            var btnId        = GUIUtility.GetControlID(FocusType.Passive);
            var objectPicker = ObjectPicker.GetObjectPicker(type.FullName + "+" + btnId, type);
            var selectRect   = rect.AlignBottom(15).AlignCenter(45);
            var uObj         = value as UnityEngine.Object;

            selectRect.xMin = Mathf.Max(selectRect.xMin, rect.xMin);

            var hide = IsDragging || Event.current.type == EventType.Repaint && !rect.Contains(Event.current.mousePosition);

            if (hide)
            {
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
                GUIHelper.PushGUIEnabled(false);
            }

            bool hideInspectorBtn = !hide && !(uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PushGUIEnabled(false);
                GUIHelper.PushColor(new Color(0, 0, 0, 0));
            }

            var inspectBtn = rect.AlignRight(14);

            inspectBtn.height = 14;
            AllEditorGUI.BeginDrawOpenInspector(inspectBtn, uObj, rect);
            AllEditorGUI.EndDrawOpenInspector(inspectBtn, uObj);

            if (hideInspectorBtn)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (GUI.Button(selectRect, "select", SirenixGUIStyles.TagButton))
            {
                GUIHelper.RemoveFocusControl();
                objectPicker.ShowObjectPicker(allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                objectPicker.ShowObjectPicker(allowSceneObjects, rect, false);
                Event.current.Use();
            }

            if (hide)
            {
                GUIHelper.PopColor();
                GUIHelper.PopGUIEnabled();
            }

            if (objectPicker.IsReadyToClaim)
            {
                GUIHelper.RequestRepaint();
                GUI.changed = true;
                var newValue = objectPicker.ClaimObject();
                Event.current.Use();
                return(newValue);
            }

            if (Event.current.keyCode == KeyCode.Delete && Event.current.type == EventType.KeyDown && EditorGUIUtility.keyboardControl == id)
            {
                Event.current.Use();
                GUI.changed = true;
                return(null);
            }

            if (uObj && Event.current.type == EventType.MouseUp && rect.Contains(Event.current.mousePosition) && EditorGUIUtility.hotControl == id && Event.current.button == 0)
            {
                EditorGUIUtility.PingObject(uObj);
            }

            return(value);
        }