/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var objectToPaint = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && hoveringAcceptedDropZone == id && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, SirenixEditorGUI.MixedValueDashChar, SirenixGUIStyles.LabelCentered); } else if (objectToPaint) { Texture image = null; var rt = objectToPaint as RenderTexture; if (rt) { image = rt; } var img = objectToPaint as UnityEngine.UI.Image; if (img) { objectToPaint = img.sprite; } var rawImg = objectToPaint as UnityEngine.UI.RawImage; if (rawImg) { image = rawImg.texture; } if (image == null) { image = GUIHelper.GetAssetThumbnail(objectToPaint, objectToPaint.GetType(), true); } rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }
/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var unityObject = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && isHoveringAcceptedDropZone && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, "—", SirenixGUIStyles.LabelCentered); } else if (unityObject) { //if (unityObject is Component) //{ // unityObject = (unityObject as Component).gameObject; //} Texture image = GUIHelper.GetAssetThumbnail(unityObject, unityObject.GetType(), true); //image = AssetPreview.GetAssetPreview(unityObject); //if (image == null) //{ // image = AssetPreview.GetMiniThumbnail(unityObject); //} rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }
/// <summary> /// Draws the graphics for a DropZone. /// </summary> public static void DrawDropZone(Rect rect, object value, GUIContent label, int id) { bool isDragging = IsDragging; if (Event.current.type == EventType.Repaint) { var objectToPaint = value as UnityEngine.Object; var objectFieldThumb = EditorStyles.objectFieldThumb; var on = GUI.enabled && hoveringAcceptedDropZone == id && rect.Contains(Event.current.mousePosition) && isDragging; objectFieldThumb.Draw(rect, GUIContent.none, id, on); if (EditorGUI.showMixedValue) { GUI.Label(rect, SirenixEditorGUI.MixedValueDashChar, SirenixGUIStyles.LabelCentered); } else if (objectToPaint) { Texture image = null; var rt = objectToPaint as RenderTexture; if (rt) { image = rt; } // Weakly typed, check if it's a UnityEngine.UI.Image instance and paint its sprite, if so. // This is weakly typed because we can no longer safely reference the UnityEngine.UI assembly. { if (Type_UnityEngine_UI_Image != null && Property_UnityEngine_UI_Image_Sprite != null && Type_UnityEngine_UI_Image.IsAssignableFrom(objectToPaint.GetType())) { objectToPaint = (UnityEngine.Object)Property_UnityEngine_UI_Image_Sprite.GetValue(objectToPaint, null); } // This was the old code for the above section: //var img = objectToPaint as UnityEngine.UI.Image; //if (img) //{ // objectToPaint = img.sprite; //} } // Weakly typed, check if it's a UnityEngine.UI.RawImage instance and paint its texture, if so. // This is weakly typed because we can no longer safely reference the UnityEngine.UI assembly. { if (Type_UnityEngine_UI_RawImage != null && Property_UnityEngine_UI_RawImage_Texture != null && Type_UnityEngine_UI_RawImage.IsAssignableFrom(objectToPaint.GetType())) { image = (Texture)Property_UnityEngine_UI_RawImage_Texture.GetValue(objectToPaint, null); } // This was the old code for the above section: //var rawImg = objectToPaint as UnityEngine.UI.RawImage; //if (rawImg) //{ // image = rawImg.texture; //} } if (image == null) { image = GUIHelper.GetAssetThumbnail(objectToPaint, objectToPaint.GetType(), true); } rect = rect.Padding(2); float size = Mathf.Min(rect.width, rect.height); EditorGUI.DrawTextureTransparent(rect.AlignCenter(size, size), image, ScaleMode.ScaleToFit); if (label != null) { rect = rect.AlignBottom(16); GUI.Label(rect, label, EditorStyles.label); } } } }