1
This commit is contained in:
83
Unity/Extensions/VisualScripting/VisualEntity.cs
Normal file
83
Unity/Extensions/VisualScripting/VisualEntity.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
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<string>("Key");
|
||||
entity = ValueInput<Entity>("Entity");
|
||||
tempValue = ValueInput<string>("TempValue");
|
||||
}
|
||||
}
|
||||
public class GetVariableFromEntity : EntityUnit
|
||||
{
|
||||
|
||||
[DoNotSerialize]
|
||||
public ValueOutput value;
|
||||
protected override void Definition()
|
||||
{
|
||||
base.Definition();
|
||||
value = ValueOutput<string>("Value", GetValue);
|
||||
}
|
||||
string GetValue(Flow flow)
|
||||
{
|
||||
var entity = flow.GetValue<Entity>(this.entity);
|
||||
var key = flow.GetValue<string>(this.key);
|
||||
var value = entity.Get<string>(key);
|
||||
if (tempValue.hasValidConnection)
|
||||
{
|
||||
var _value = flow.GetValue<string>(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<string>("Value");
|
||||
inputTrigger = ControlInput("Input", Input);
|
||||
outputTrigger = ControlOutput("Output");
|
||||
}
|
||||
ControlOutput Input(Flow flow)
|
||||
{
|
||||
var entity = flow.GetValue<Entity>(this.entity);
|
||||
var key = flow.GetValue<string>(this.key);
|
||||
var value = flow.GetValue<string>(this.value);
|
||||
entity.Set<string>(key, value);
|
||||
if (int.TryParse(value, out var _int))
|
||||
{
|
||||
entity.Set<int>(key, _int);
|
||||
}
|
||||
else if (float.TryParse(value, out var _float))
|
||||
{
|
||||
entity.Set<float>(key, _float);
|
||||
}
|
||||
return outputTrigger;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user