Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEditor;
- using UnityEngine;
- [CustomPropertyDrawer(typeof(RTlerp))]
- public class RTlerp_drawer : PropertyDrawer {
- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
- EditorGUI.BeginProperty(position, label, property);
- var h = EditorGUIUtility.singleLineHeight; // высота = 1 строка
- var w = position.width;
- var rect = position;
- rect.height = h;
- rect.width = 100f;
- GUI.Label(rect, label);
- rect.x += 100f;
- rect.width = (w - 100f) * 0.5f;
- if (GUI.Button(rect, "Set FROM")) {
- EditorGUIUtility.ShowObjectPicker<RectTransform>(null, true, "", 9998887);
- }
- rect.x += rect.width;
- if (GUI.Button(rect, "Set TO")) {
- EditorGUIUtility.ShowObjectPicker<RectTransform>(null, true, "", 9998886);
- }
- if (Event.current.commandName != "ObjectSelectorClosed") return;
- if (EditorGUIUtility.GetObjectPickerControlID() == 9998887) {
- var rt = (RectTransform) EditorGUIUtility.GetObjectPickerObject();
- if (rt == null) return;
- property.FindPropertyRelative("sizeDelta_from").vector2Value = rt.sizeDelta;
- property.FindPropertyRelative("anchoredPosition_from").vector2Value = rt.anchoredPosition;
- }
- else if (EditorGUIUtility.GetObjectPickerControlID() == 9998886) {
- var rt = (RectTransform) EditorGUIUtility.GetObjectPickerObject();
- if (rt == null) return;
- property.FindPropertyRelative("sizeDelta_to").vector2Value = rt.sizeDelta;
- property.FindPropertyRelative("anchoredPosition_to").vector2Value = rt.anchoredPosition;
- }
- EditorGUI.EndProperty();
- }
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
- return EditorGUIUtility.singleLineHeight;
- }
- }
Add Comment
Please, Sign In to add comment