A game about forced loneliness, made by TACStudios
1using System; 2using UnityEditor; 3using UnityEngine; 4 5namespace Unity.VisualScripting 6{ 7 [Widget(typeof(ValueConnection))] 8 public sealed class ValueConnectionWidget : UnitConnectionWidget<ValueConnection> 9 { 10 public ValueConnectionWidget(FlowCanvas canvas, ValueConnection connection) : base(canvas, connection) { } 11 12 private new ValueConnection.DebugData ConnectionDebugData => GetDebugData<ValueConnection.DebugData>(); 13 14 15 #region Drawing 16 17 public override Color color => DetermineColor(connection.source.type, connection.destination.type); 18 19 protected override bool colorIfActive => !BoltFlow.Configuration.animateControlConnections || !BoltFlow.Configuration.animateValueConnections; 20 21 public override void DrawForeground() 22 { 23 base.DrawForeground(); 24 25 if (BoltFlow.Configuration.showConnectionValues) 26 { 27 var showLastValue = EditorApplication.isPlaying && ConnectionDebugData.assignedLastValue; 28 var showPredictedvalue = BoltFlow.Configuration.predictConnectionValues && !EditorApplication.isPlaying && Flow.CanPredict(connection.source, reference); 29 30 if (showLastValue || showPredictedvalue) 31 { 32 var previousIconSize = EditorGUIUtility.GetIconSize(); 33 EditorGUIUtility.SetIconSize(new Vector2(IconSize.Small, IconSize.Small)); 34 35 object value; 36 37 if (showLastValue) 38 { 39 value = ConnectionDebugData.lastValue; 40 } 41 else // if (showPredictedvalue) 42 { 43 value = Flow.Predict(connection.source, reference); 44 } 45 46 var label = new GUIContent(value.ToShortString(), Icons.Type(value?.GetType())?[IconSize.Small]); 47 var labelSize = Styles.prediction.CalcSize(label); 48 var labelPosition = new Rect(position.position - labelSize / 2, labelSize); 49 50 BeginDim(); 51 52 GUI.Label(labelPosition, label, Styles.prediction); 53 54 EndDim(); 55 56 EditorGUIUtility.SetIconSize(previousIconSize); 57 } 58 } 59 } 60 61 public static Color DetermineColor(Type source, Type destination) 62 { 63 if (destination == typeof(object)) 64 { 65 return DetermineColor(source); 66 } 67 68 return DetermineColor(destination); 69 } 70 71 public static Color DetermineColor(Type type) 72 { 73 if (type == null) 74 { 75 return new Color(0.8f, 0.8f, 0.8f); 76 } 77 78 if (type == typeof(string)) 79 { 80 return new Color(1.0f, 0.62f, 0.35f); 81 } 82 83 if (type == typeof(bool)) 84 { 85 return new Color(0.86f, 0.55f, 0.92f); 86 } 87 88 if (type == typeof(char)) 89 { 90 return new Color(1.0f, 0.90f, 0.40f); 91 } 92 93 if (type.IsEnum) 94 { 95 return new Color(1.0f, 0.63f, 0.66f); 96 } 97 98 if (type.IsNumeric()) 99 { 100 return new Color(0.45f, 0.78f, 1f); 101 } 102 103 if (type.IsNumericConstruct()) 104 { 105 return new Color(0.45f, 1.00f, 0.82f); 106 } 107 108 return new Color(0.60f, 0.88f, 0.00f); 109 } 110 111 #endregion 112 113 114 #region Droplets 115 116 protected override bool showDroplets => BoltFlow.Configuration.animateValueConnections; 117 118 protected override Vector2 GetDropletSize() 119 { 120 return BoltFlow.Icons.valuePortConnected?[12].Size() ?? 12 * Vector3.one; 121 } 122 123 protected override void DrawDroplet(Rect position) 124 { 125 if (BoltFlow.Icons.valuePortConnected != null) 126 { 127 GUI.DrawTexture(position, BoltFlow.Icons.valuePortConnected?[12]); 128 } 129 } 130 131 #endregion 132 133 134 private static class Styles 135 { 136 static Styles() 137 { 138 prediction = new GUIStyle(EditorStyles.label); 139 prediction.normal.textColor = Color.white; 140 prediction.fontSize = 9; 141 prediction.normal.background = new Color(0, 0, 0, 0.25f).GetPixel(); 142 prediction.padding = new RectOffset(4, 6, 3, 3); 143 prediction.margin = new RectOffset(0, 0, 0, 0); 144 prediction.alignment = TextAnchor.MiddleCenter; 145 } 146 147 public static readonly GUIStyle prediction; 148 } 149 } 150}