/// <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); }
/// <summary> /// Draws the proprety. /// </summary> protected override void DrawPropertyLayout(InspectorProperty property, TAttribute attribute, GUIContent label) { var entry = property.ValueEntry; if (SetAttribute == null || SetFieldInfo == null) { AllEditorGUI.ErrorMessageBox("Could not find the internal Unity fields 'PropertyDrawer.m_Attribute' or 'PropertyDrawer.m_FieldInfo'; UnityPropertyAttributeDrawer alias '" + typeof(UnityPropertyAttributeDrawer <TDrawer, TAttribute, TAttributeConstraint>).GetNiceName() + "' has been disabled."); return; } if (property.ValueEntry == null) { AllEditorGUI.ErrorMessageBox("Cannot put the attribute '" + typeof(TAttribute) + "' on a property of type '" + property.Info.PropertyType + "'."); return; } FieldInfo fieldInfo; SerializedProperty unityProperty = property.Tree.GetUnityPropertyForPath(property.Path, out fieldInfo); if (unityProperty == null) { if (UnityVersion.IsVersionOrGreater(2017, 1)) { this.CallNextDrawer(entry, label); } else { AllEditorGUI.ErrorMessageBox("Could not get a Unity SerializedProperty for the property '" + property.NiceName + "' of type '" + entry.TypeOfValue.GetNiceName() + "' at path '" + entry.Property.Path + "'."); } return; } SetFieldInfo(ref this.drawer, fieldInfo); SetAttribute(ref this.drawer, attribute); if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; target.SetWeakValue(entry.WeakValues[i]); } unityProperty.serializedObject.Update(); unityProperty = unityProperty.serializedObject.FindProperty(unityProperty.propertyPath); } float height = this.drawer.GetPropertyHeight(unityProperty, label); Rect position = EditorGUILayout.GetControlRect(false, height); if (this.propertyHandler != null) { UnityPropertyHandlerUtility.PropertyHandlerOnGUI(this.propertyHandler, position, unityProperty, label, false); } else { this.drawer.OnGUI(position, unityProperty, label); } if (unityProperty.serializedObject.targetObject is EmittedScriptableObject) { unityProperty.serializedObject.ApplyModifiedPropertiesWithoutUndo(); var targetObjects = unityProperty.serializedObject.targetObjects; for (int i = 0; i < targetObjects.Length; i++) { EmittedScriptableObject target = (EmittedScriptableObject)targetObjects[i]; entry.WeakValues[i] = target.GetWeakValue(); } } }