public override void OnGUI() { var controlId = EditorGUIUtility.GetControlID(kCanvasHash, FocusType.Passive); var dropZoneId = EditorGUIUtility.GetControlID(kDropZoneHash, FocusType.Passive); var texture = GetValue(kPreviewTexture); var hasTexture = texture != null; var targetTexture = (Texture)texture ?? Texture2D.whiteTexture; Rect canvasRectViewport; if (hasTexture) { var width = texture != null ? texture.width : 256; var height = texture != null ? texture.height : 256; var cameraPosition = GetValue(kCameraPosition); var zoom = GetValue(kZoom); EditorGUIXLayout.Canvas(controlId, ref cameraPosition, ref zoom, null, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); canvasRectViewport = GUILayoutUtility.GetLastRect(); SetValue(kCameraPosition, cameraPosition); SetValue(kZoom, zoom); GUI.BeginClip(canvasRectViewport); DelightingHelpers.PushSRGBWrite(false); GUI.DrawTexture(EditorGUIX.GetCanvasDestinationRect(cameraPosition, zoom, width, height), targetTexture, ScaleMode.ScaleToFit); DelightingHelpers.PopSRGBWrite(); if (Event.current.type == EventType.Repaint) { m_Separator.OnGUI(); if (GetValue(kOverrideReferenceZone)) { m_Gizmo.OnGUI(); } } else { if (GetValue(kOverrideReferenceZone)) { m_Gizmo.OnGUI(); } m_Separator.OnGUI(); } GUI.EndClip(); var fitCanvasToWindow = GetValue(kFitCanvasToWindow); if (fitCanvasToWindow && Event.current.type == EventType.Repaint) { EditorGUIX.CancelCanvasZoom(controlId); var widthRatio = canvasRectViewport.width / (float)width; var heightRatio = canvasRectViewport.height / (float)height; var widthOffset = 0f; var heightOffset = 0f; if (widthRatio < heightRatio) { zoom = widthRatio; heightOffset = (canvasRectViewport.height - zoom * height) * 0.5f; } else { zoom = heightRatio; widthOffset = (canvasRectViewport.width - zoom * width) * 0.5f; } SetValue(kZoom, zoom); SetValue(kCameraPosition, new Vector2(widthOffset, heightOffset)); SetValue(kFitCanvasToWindow, false); } } else { EditorGUIXLayout.DropZoneHint(Content.dropZoneLabel); canvasRectViewport = GUILayoutUtility.GetLastRect(); } if (EditorGUIX.DropZone(dropZoneId, canvasRectViewport, CanAcceptCallback)) { var objs = DragAndDrop.objectReferences; if (objs.Length > 0) { var path = AssetDatabase.GetAssetPath(objs[0]); if (AssetDatabase.IsValidFolder(path)) { SetValue(kInputFolderPath, path); ExecuteCommand(kCmdLoadInputFolder); } } } }