//using UnityEngine;
//using UnityEditor;

//[InitializeOnLoad]
//public class AnchorCenterTool : EditorWindow
//{
//    static AnchorCenterTool()
//    {
//        SceneView.onSceneGUIDelegate += OnScene;
//    }

//    private static void OnScene(SceneView sceneview)
//    {
//        if (Event.current.type == EventType.MouseUp && Event.current.button == 0 && Event.current.shift)
//        {
//            UpdateAnchors();
//        }
//    }

//    public void OnDestroy()
//    {
//        SceneView.onSceneGUIDelegate -= OnScene;
//    }
    
//    private static RectTransform currentRectTransform;
//    private static RectTransform parentRectTransform;

//    public static void UpdateAnchors()
//    {
//        TryToGetRectTransform();
//        if (currentRectTransform != null && parentRectTransform != null)
//        {
//            Stick();
//        }
//    }
    
//    private static void Stick()
//    {
//        Undo.RecordObject(currentRectTransform, "CenterAnchor");

//        var min = currentRectTransform.anchorMin;
//        var max = currentRectTransform.anchorMax;
//        var center = min + (max - min) / 2;

//        var size = currentRectTransform.rect.size;
//        currentRectTransform.anchorMin = center;
//        currentRectTransform.anchorMax = center;
//        currentRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, size.x);
//        currentRectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
//    }

//    private static void TryToGetRectTransform()
//    {
//        if (Selection.activeGameObject == null)
//            return;
//        currentRectTransform = Selection.activeGameObject.GetComponent<RectTransform>();
//        if (currentRectTransform != null)
//            parentRectTransform = currentRectTransform.parent.gameObject.GetComponent<RectTransform>();
//    }
//}