-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added log unit, and tweaks to the Defined events so the api names match
- Loading branch information
1 parent
eca37de
commit 24210ee
Showing
11 changed files
with
194 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Bolt.Addons.Community.Fundamentals.Units.logic; | ||
using Ludiq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Bolt.Addons.Community.Fundamentals.Editor.Editor.Descriptors | ||
{ | ||
[Descriptor(typeof(LogUnit))] | ||
public class LogUnitDescriptor : UnitDescriptor<LogUnit> | ||
{ | ||
public LogUnitDescriptor(LogUnit target) : base(target) | ||
{ | ||
} | ||
|
||
protected override EditorTexture DefinedIcon() | ||
{ | ||
return EditorTexture.Load(new AssemblyResourceProvider(Assembly.GetExecutingAssembly(), "Bolt.Addons.Community.Fundamentals.Editor", "Resources"), "debug.png", CreateTextureOptions.PixelPerfect, true); | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Ludiq; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using UnityEngine; | ||
|
||
namespace Bolt.Addons.Community.Fundamentals.Units.logic | ||
{ | ||
[UnitTitle("Log")] | ||
[UnitCategory("Community\\Logic")] | ||
public class LogUnit : Unit | ||
{ | ||
public const int ArgumentLimit = 10; | ||
|
||
public LogUnit() : base() { } | ||
|
||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ValueInput format { get; private set; } | ||
|
||
|
||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ControlInput input { get; private set; } | ||
|
||
|
||
[DoNotSerialize] | ||
[PortLabelHidden] | ||
public ControlOutput output { get; private set; } | ||
|
||
|
||
[SerializeAs(nameof(argumentCount))] | ||
private int _argumentCount; | ||
|
||
|
||
[DoNotSerialize] | ||
public List<ValueInput> arguments { get; protected set; } | ||
|
||
[DoNotSerialize] | ||
[Inspectable, UnitHeaderInspectable("Arguments")] | ||
public int argumentCount | ||
{ | ||
get | ||
{ | ||
return Mathf.Max(0, _argumentCount); | ||
} | ||
set | ||
{ | ||
_argumentCount = Mathf.Clamp(value, 0, ArgumentLimit); | ||
} | ||
} | ||
|
||
protected override void Definition() | ||
{ | ||
format = ValueInput<string>(nameof(format), ""); | ||
|
||
input = ControlInput(nameof(input), (flow) => Log(flow)); | ||
output = ControlOutput(nameof(output)); | ||
|
||
arguments = new List<ValueInput>(); | ||
for (var i = 0; i < Math.Min(argumentCount, ArgumentLimit); i++) | ||
{ | ||
var argument = ValueInput<object>("Arg_" + i); | ||
arguments.Add(argument); | ||
Requirement(argument, input); | ||
} | ||
|
||
Succession(input, output); | ||
Requirement(format, input); | ||
} | ||
|
||
private ControlOutput Log(Flow flow) | ||
{ | ||
string formatstr = flow.GetValue<string>(format); | ||
|
||
//Optimized check for 1 arg and no format. | ||
if (argumentCount == 1 && string.IsNullOrEmpty(formatstr)) | ||
{ | ||
Debug.Log(flow.GetValue(arguments[0]).ToString()); | ||
return output; | ||
} | ||
|
||
|
||
var stringArgs = arguments.Select<ValueInput, string>(x => | ||
{ | ||
|
||
var val = flow.GetValue(x); | ||
if (val is string) | ||
return val as string; | ||
return val.ToString(); | ||
}); | ||
|
||
Debug.Log(string.Format(flow.GetValue<string>(format), stringArgs.ToArray())); | ||
return output; | ||
} | ||
} | ||
} |