A game about forced loneliness, made by TACStudios
1using System; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Returns a constant value defined from the editor. 7 /// </summary> 8 [SpecialUnit] 9 public sealed class Literal : Unit 10 { 11 [Obsolete(Serialization.ConstructorWarning)] 12 public Literal() : base() { } 13 14 public Literal(Type type) : this(type, type.PseudoDefault()) { } 15 16 public Literal(Type type, object value) : base() 17 { 18 Ensure.That(nameof(type)).IsNotNull(type); 19 Ensure.That(nameof(value)).IsOfType(value, type); 20 21 this.type = type; 22 this.value = value; 23 } 24 25 // Shouldn't happen through normal use, but can happen 26 // if deserialization fails to find the type 27 // https://support.ludiq.io/communities/5/topics/1661-x 28 public override bool canDefine => type != null; 29 30 [SerializeAs(nameof(value))] 31 private object _value; 32 33 [Serialize] 34 public Type type { get; internal set; } 35 36 [DoNotSerialize] 37 public object value 38 { 39 get => _value; 40 set 41 { 42 Ensure.That(nameof(value)).IsOfType(value, type); 43 44 _value = value; 45 } 46 } 47 48 [DoNotSerialize] 49 [PortLabelHidden] 50 public ValueOutput output { get; private set; } 51 52 protected override void Definition() 53 { 54 output = ValueOutput(type, nameof(output), (flow) => value).Predictable(); 55 } 56 57 #region Analytics 58 59 public override AnalyticsIdentifier GetAnalyticsIdentifier() 60 { 61 var aid = new AnalyticsIdentifier 62 { 63 Identifier = $"{GetType().FullName}({type.Name})", 64 Namespace = type.Namespace, 65 }; 66 aid.Hashcode = aid.Identifier.GetHashCode(); 67 return aid; 68 } 69 70 #endregion 71 } 72}