public void OnPresetClick(BaseEventData data)
        {
            PointerEventData pointerData = (PointerEventData)data;
            AnchorPreset     preset      = pointerData.pointerPress.GetComponent <AnchorPreset>();

            m_preview.CopyFrom(preset);

            if (Selected != null)
            {
                Selected(preset);
            }

            UpdateCaptions();

            m_dropDown.Hide();
        }
Пример #2
0
 public void CopyFrom(AnchorPreset from)
 {
     CopyFrom(from.m_template);
     UpdateVisuals();
 }
Пример #3
0
        private void OnAnchorPresetSelected(AnchorPreset preset)
        {
            Editor.Undo.BeginRecord();

            for (int i = 0; i < Components.Length; ++i)
            {
                RectTransform rt = Components[i] as RectTransform;
                if (rt == null)
                {
                    continue;
                }

                int index = i;

                Vector3 anchorMinOld        = rt.anchorMin;
                Vector3 anchorMaxOld        = rt.anchorMax;
                Vector3 anchoredPositionOld = rt.anchoredPosition;
                Vector3 pivotOld            = rt.pivot;
                Vector3 sizeDeltaOld        = rt.sizeDelta;
                Vector3 offsetMinOld        = rt.offsetMin;
                Vector3 offsetMaxOld        = rt.offsetMax;

                preset.CopyTo(rt, preset.IsPivotVisible, preset.IsPositionVisible);

                Vector3 anchorMinNew        = rt.anchorMin;
                Vector3 anchorMaxNew        = rt.anchorMax;
                Vector3 anchoredPositionNew = rt.anchoredPosition;
                Vector3 pivotNew            = rt.pivot;
                Vector3 sizeDeltaNew        = rt.sizeDelta;
                Vector3 offsetMinNew        = rt.offsetMin;
                Vector3 offsetMaxNew        = rt.offsetMax;

                Editor.Undo.CreateRecord(redo =>
                {
                    RectTransform rectTransform    = Components[index] as RectTransform;
                    rectTransform.anchorMin        = anchorMinNew;
                    rectTransform.anchorMax        = anchorMaxNew;
                    rectTransform.anchoredPosition = anchoredPositionNew;
                    rectTransform.pivot            = pivotNew;
                    rectTransform.sizeDelta        = sizeDeltaNew;
                    rectTransform.offsetMin        = offsetMinNew;
                    rectTransform.offsetMax        = offsetMaxNew;

                    return(true);
                }, undo =>
                {
                    RectTransform rectTransform    = Components[index] as RectTransform;
                    rectTransform.anchorMin        = anchorMinOld;
                    rectTransform.anchorMax        = anchorMaxOld;
                    rectTransform.anchoredPosition = anchoredPositionOld;
                    rectTransform.pivot            = pivotOld;
                    rectTransform.sizeDelta        = sizeDeltaOld;
                    rectTransform.offsetMin        = offsetMinOld;
                    rectTransform.offsetMax        = offsetMaxOld;
                    return(true);
                });
            }

            Editor.Undo.EndRecord();

            RefreshTransformHandles();
        }