A game about forced loneliness, made by TACStudios
1/* 2using System; 3using System.Collections.Generic; 4using System.Linq; 5using Unity.VisualScripting; 6using UnityEditor; 7using UnityEngine; 8 9namespace Unity.VisualScripting 10{ 11 public abstract class InvocationInspector : Inspector 12 { 13 protected InvocationInspector(Metadata metadata) : base(metadata) { } 14 15 protected Metadata argumentsMetadata => metadata["_" + nameof(MemberInvocation.arguments)]; 16 17 protected IList<Metadata> parameters => argumentsMetadata.children; 18 19 public virtual Type expectedType { get; set; } 20 21 protected virtual IEnumerable<GUIContent> compactLabels => parameters.Select(p => p.label); 22 23 protected void PrepareParameterLabel(Metadata parameter, string label, string tooltip) 24 { 25 if (StringUtility.IsNullOrWhiteSpace(label)) 26 { 27 label = "(?)"; 28 } 29 30 parameter.label.text = label; 31 parameter.label.tooltip = tooltip; 32 } 33 34 protected void PrepareParameterInspector(Metadata parameter, Type expectedType) 35 { 36 parameter.Inspector<IExpressionInspector>().expectedType = expectedType; 37 } 38 39 protected float GetParametersHeight(float width) 40 { 41 var height = 0f; 42 43 using (LudiqGUIUtility.labelWidth.Override(GetCompactLabelsWidth(width))) 44 { 45 for (var i = 0; i < parameters.Count; i++) 46 { 47 var parameter = parameters[i]; 48 49 height += GetParameterHeight(parameter, width); 50 51 if (i < parameters.Count - 1) 52 { 53 height += Styles.spaceBetweenParameters; 54 } 55 } 56 } 57 58 return height; 59 } 60 61 protected float GetCompactLabelsWidth(float width) 62 { 63 var compactLabelsWidth = 0f; 64 65 foreach (var compactLabel in compactLabels) 66 { 67 compactLabelsWidth = Mathf.Max(compactLabelsWidth, Styles.compactLabel.CalcSize(compactLabel).x); 68 } 69 70 compactLabelsWidth = Mathf.Min(compactLabelsWidth, width / 3); 71 72 return compactLabelsWidth; 73 } 74 75 protected virtual float GetParameterHeight(Metadata parameter, float width) 76 { 77 return InspectorGUI.GetHeight(parameter, width, parameter.label, this); 78 } 79 80 protected virtual void OnParameterGUI(Rect parameterPosition, Metadata parameter) 81 { 82 InspectorGUI.Field(parameter, parameterPosition, parameter.label); 83 } 84 85 protected void OnParametersGUI(Rect position) 86 { 87 if (parameters.Any()) 88 { 89 using (LudiqGUIUtility.labelWidth.Override(GetCompactLabelsWidth(position.width))) 90 { 91 for (var i = 0; i < parameters.Count; i++) 92 { 93 var parameter = parameters[i]; 94 95 var parameterPosition = position.VerticalSection(ref y, GetParameterHeight(parameter, position.width)); 96 97 OnParameterGUI(parameterPosition, parameter); 98 99 if (i < parameters.Count - 1) 100 { 101 y += Styles.spaceBetweenParameters; 102 } 103 } 104 } 105 } 106 } 107 108 public static class Styles 109 { 110 static Styles() 111 { 112 compactLabel = new GUIStyle(EditorStyles.label); 113 var padding = compactLabel.padding; 114 padding.right += labelPadding; 115 compactLabel.padding = padding; 116 } 117 118 public static readonly float spaceBetweenParameters = EditorGUIUtility.standardVerticalSpacing; 119 public static readonly float spaceAfterLabel = 0; 120 public static readonly int labelPadding = 3; 121 public static readonly GUIStyle compactLabel; 122 } 123 } 124} 125*/