KpoKec

Untitled

May 8th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.95 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEngine;
  3.  
  4. [CustomPropertyDrawer(typeof(RTlerp))]
  5. public class RTlerp_drawer : PropertyDrawer {
  6.     public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
  7.         EditorGUI.BeginProperty(position, label, property);
  8.         var h    = EditorGUIUtility.singleLineHeight; // высота = 1 строка
  9.         var w    = position.width;
  10.         var rect = position;
  11.         rect.height = h;
  12.         rect.width  = 100f;
  13.         GUI.Label(rect, label);
  14.         rect.x     += 100f;
  15.         rect.width =  (w - 100f) * 0.5f;
  16.         if (GUI.Button(rect, "Set FROM")) {
  17.             EditorGUIUtility.ShowObjectPicker<RectTransform>(null, true, "", 9998887);
  18.         }
  19.  
  20.         rect.x += rect.width;
  21.         if (GUI.Button(rect, "Set TO")) {
  22.             EditorGUIUtility.ShowObjectPicker<RectTransform>(null, true, "", 9998886);
  23.         }
  24.  
  25.         if (Event.current.commandName != "ObjectSelectorClosed") return;
  26.         if (EditorGUIUtility.GetObjectPickerControlID() == 9998887) {
  27.             var rt = (RectTransform) EditorGUIUtility.GetObjectPickerObject();
  28.             if (rt == null) return;
  29.             property.FindPropertyRelative("sizeDelta_from").vector2Value        = rt.sizeDelta;
  30.             property.FindPropertyRelative("anchoredPosition_from").vector2Value = rt.anchoredPosition;
  31.         }
  32.         else if (EditorGUIUtility.GetObjectPickerControlID() == 9998886) {
  33.             var rt = (RectTransform) EditorGUIUtility.GetObjectPickerObject();
  34.             if (rt == null) return;
  35.             property.FindPropertyRelative("sizeDelta_to").vector2Value        = rt.sizeDelta;
  36.             property.FindPropertyRelative("anchoredPosition_to").vector2Value = rt.anchoredPosition;
  37.         }
  38.  
  39.         EditorGUI.EndProperty();
  40.     }
  41.  
  42.     public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
  43.         return EditorGUIUtility.singleLineHeight;
  44.     }
  45. }
Add Comment
Please, Sign In to add comment