using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Unity.VisualScripting; using BITKit.Entities; namespace BITKit.VisualScript { public abstract class EntityUnit : Unit { [DoNotSerialize] // No need to serialize ports public ValueInput entity; // Adding the ValueInput variable for myValueA [DoNotSerialize] // No need to serialize ports public ValueInput key; // Adding the ValueInput variable for myValueA [DoNotSerialize] // No need to serialize ports public ValueInput tempValue; // Adding the ValueInput variable for myValueA protected override void Definition() { key = ValueInput("Key"); entity = ValueInput("Entity"); tempValue = ValueInput("TempValue"); } } public class GetVariableFromEntity : EntityUnit { [DoNotSerialize] public ValueOutput value; protected override void Definition() { base.Definition(); value = ValueOutput("Value", GetValue); } string GetValue(Flow flow) { var entity = flow.GetValue(this.entity); var key = flow.GetValue(this.key); var value = entity.Get(key); if (tempValue.hasValidConnection) { var _value = flow.GetValue(tempValue); if (String.IsNullOrEmpty(_value) is false) { value = _value; } } return value; } } public class SetVariableForEntity : EntityUnit { [DoNotSerialize] public ControlInput inputTrigger; [DoNotSerialize] public ControlOutput outputTrigger; [DoNotSerialize] public ValueInput value; protected override void Definition() { base.Definition(); value = ValueInput("Value"); inputTrigger = ControlInput("Input", Input); outputTrigger = ControlOutput("Output"); } ControlOutput Input(Flow flow) { var entity = flow.GetValue(this.entity); var key = flow.GetValue(this.key); var value = flow.GetValue(this.value); entity.Set(key, value); if (int.TryParse(value, out var _int)) { entity.Set(key, _int); } else if (float.TryParse(value, out var _float)) { entity.Set(key, _float); } return outputTrigger; } } }