Skip to content

Commit

Permalink
Added log unit, and tweaks to the Defined events so the api names match
Browse files Browse the repository at this point in the history
  • Loading branch information
RealityStop committed Jan 25, 2019
1 parent eca37de commit 24210ee
Show file tree
Hide file tree
Showing 11 changed files with 194 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Events/Bolt.Addons.Community.Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@
<Compile Include="Support\Internal\IDefinedEventTriggerUnit.cs" />
<Compile Include="Support\ReflectedInfo.cs" />
<Compile Include="Support\Internal\IDefinedEventUnit.cs" />
<Compile Include="Units\TriggerUniversalDefinedEvent.cs" />
<Compile Include="Units\TriggerGlobalDefinedEvent.cs" />
<Compile Include="Units\TriggerDefinedEvent.cs" />
<Compile Include="Units\UniversalDefinedEvent.cs" />
<Compile Include="Units\GlobalDefinedEvent.cs" />
<Compile Include="Support\DefinedEventArgs.cs" />
<Compile Include="Units\TargettedDefinedEvent.cs" />
<Compile Include="Units\DefinedEvent.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fundamentals\Bolt.Addons.Community.Fundamentals.csproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
namespace Bolt.Addons.Community.DefinedEvents.Units
{
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.TargettedDefinedEvent")]
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.TargettedDefinedEvent")]
[UnitCategory("Events")]
[UnitTitle("Defined Event")]
public class TargettedDefinedEvent : GameObjectEventUnit<DefinedEventArgs>, IDefinedEventUnit
public class DefinedEvent : GameObjectEventUnit<DefinedEventArgs>, IDefinedEventUnit
{
const string EventName = "OnDefinedEvent";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ namespace Bolt.Addons.Community.DefinedEvents.Units
[UnitCategory("Events")]
[UnitTitle("Global Defined Event")]
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.UniversalDefinedEvent")]
public class UniversalDefinedEvent : EventUnit<DefinedEventArgs>, IDefinedEventUnit
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.UniversalDefinedEvent")]
public class GlobalDefinedEvent : EventUnit<DefinedEventArgs>, IDefinedEventUnit
{
const string EventName = "OnUniversalDefinedEvent";
const string EventName = "OnGlobalDefinedEvent";

#region Event Type Handling

Expand Down
35 changes: 29 additions & 6 deletions src/Events/Units/TriggerDefinedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace Bolt.Addons.Community.DefinedEvents.Units
{
[UnitCategory("Events")]
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.TriggerDefinedEvent")]
[UnitCategory("Community/Events")]
[UnitTitle("Trigger Defined Event")]
[TypeIcon(typeof(BoltUnityEvent))]
public class TriggerDefinedEvent : Unit
Expand Down Expand Up @@ -71,7 +71,8 @@ public bool IsNotRestricted


[DoNotSerialize]
[PortLabel("Event Target")]
[PortLabelHidden]
[NullMeansSelf]
public ValueInput zzzEventTarget { get; private set; }


Expand Down Expand Up @@ -121,13 +122,35 @@ private void BuildFromInfo()
Info = ReflectedInfo.For(_eventType);
foreach (var field in Info.reflectedFields)
{
inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name));
if (field.Value.FieldType == typeof(bool))
inputPorts.Add(ValueInput<bool>(field.Value.Name, false));
else if (field.Value.FieldType == typeof(int))
inputPorts.Add(ValueInput<int>(field.Value.Name, 0));
else if(field.Value.FieldType == typeof(float))
inputPorts.Add(ValueInput<float>(field.Value.Name, 0.0f));
else if (field.Value.FieldType == typeof(string))
inputPorts.Add(ValueInput<string>(field.Value.Name, ""));
else if (field.Value.FieldType == typeof(GameObject))
inputPorts.Add(ValueInput<GameObject>(field.Value.Name, null).NullMeansSelf());
else
inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name));
}


foreach (var property in Info.reflectedProperties)
foreach (var property in Info.reflectedProperties)
{
inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name));
if (property.Value.PropertyType == typeof(bool))
inputPorts.Add(ValueInput<bool>(property.Value.Name, false));
else if (property.Value.PropertyType == typeof(int))
inputPorts.Add(ValueInput<int>(property.Value.Name, 0));
else if (property.Value.PropertyType == typeof(float))
inputPorts.Add(ValueInput<float>(property.Value.Name, 0.0f));
else if (property.Value.PropertyType == typeof(string))
inputPorts.Add(ValueInput<string>(property.Value.Name, ""));
else if (property.Value.PropertyType == typeof(GameObject))
inputPorts.Add(ValueInput<GameObject>(property.Value.Name, null).NullMeansSelf());
else
inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name));
}
}

Expand Down Expand Up @@ -155,7 +178,7 @@ private ControlOutput Trigger(Flow flow)
}
}

TargettedDefinedEvent.Trigger(flow.GetValue<GameObject>(zzzEventTarget), eventInstance);
DefinedEvent.Trigger(flow.GetValue<GameObject>(zzzEventTarget), eventInstance);

return exit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

namespace Bolt.Addons.Community.DefinedEvents.Units
{
[UnitCategory("Community/Events")]
[UnitCategory("Events")]
[UnitTitle("Trigger Global Defined Event")]
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.TriggerUniversalDefinedEvent")]
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.TriggerUniversalDefinedEvent")]
[TypeIcon(typeof(BoltUnityEvent))]
public class TriggerUniversalDefinedEvent : Unit
public class TriggerGlobalDefinedEvent : Unit
{
#region Event Type Handling

Expand Down Expand Up @@ -100,13 +101,35 @@ private void BuildFromInfo()
Info = ReflectedInfo.For(eventType);
foreach (var field in Info.reflectedFields)
{
inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name));
if (field.Value.FieldType == typeof(bool))
inputPorts.Add(ValueInput<bool>(field.Value.Name, false));
else if (field.Value.FieldType == typeof(int))
inputPorts.Add(ValueInput<int>(field.Value.Name, 0));
else if (field.Value.FieldType == typeof(float))
inputPorts.Add(ValueInput<float>(field.Value.Name, 0.0f));
else if (field.Value.FieldType == typeof(string))
inputPorts.Add(ValueInput<string>(field.Value.Name, ""));
else if (field.Value.FieldType == typeof(GameObject))
inputPorts.Add(ValueInput<GameObject>(field.Value.Name, null).NullMeansSelf());
else
inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name));
}


foreach (var property in Info.reflectedProperties)
{
inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name));
if (property.Value.PropertyType == typeof(bool))
inputPorts.Add(ValueInput<bool>(property.Value.Name, false));
else if (property.Value.PropertyType == typeof(int))
inputPorts.Add(ValueInput<int>(property.Value.Name, 0));
else if (property.Value.PropertyType == typeof(float))
inputPorts.Add(ValueInput<float>(property.Value.Name, 0.0f));
else if (property.Value.PropertyType == typeof(string))
inputPorts.Add(ValueInput<string>(property.Value.Name, ""));
else if (property.Value.PropertyType == typeof(GameObject))
inputPorts.Add(ValueInput<GameObject>(property.Value.Name, null).NullMeansSelf());
else
inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name));
}
}

Expand Down Expand Up @@ -134,7 +157,7 @@ private ControlOutput Trigger(Flow flow)
}
}

UniversalDefinedEvent.Trigger(eventInstance);
GlobalDefinedEvent.Trigger(eventInstance);

return exit;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Editor\Descriptors\LogUnitDescriptor.cs" />
<Compile Include="Editor\Descriptors\MathParamsDescriptor.cs" />
<Compile Include="Editor\Descriptors\BranchParamsDescriptor.cs" />
<Compile Include="Editor\Descriptors\StuffHappensDescriptor.cs" />
Expand Down Expand Up @@ -122,7 +123,9 @@
<ItemGroup>
<EmbeddedResource Include="Resources\Branch_Equal.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="Resources\debug.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\Bolt.PostBuild.targets" />
</Project>
3 changes: 2 additions & 1 deletion src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CommunityOptionFetcher.cs" />
<Compile Include="ICommunityOptions.cs" />
<Compile Include="CommunityOptions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Units\Deprecated\RandomNumbers.cs" />
<Compile Include="Units\Documenting\CommentUnit.cs" />
Expand All @@ -63,6 +63,7 @@
<Compile Include="Units\logic\Control\Gate.cs" />
<Compile Include="Units\logic\IsNullValue.cs" />
<Compile Include="Units\logic\LogicParamNode.cs" />
<Compile Include="Units\logic\LogUnit.cs" />
<Compile Include="Units\logic\Time\EveryXSeconds.cs" />
<Compile Include="Units\math\Functions\DecayFunction.cs" />
<Compile Include="Units\math\Functions\DecayFunctionOfRange.cs" />
Expand Down
File renamed without changes.
24 changes: 24 additions & 0 deletions src/Fundamentals/Editor/Descriptors/LogUnitDescriptor.cs
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);
}
}
}
Binary file added src/Fundamentals/Resources/debug.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 99 additions & 0 deletions src/Fundamentals/Units/Logic/LogUnit.cs
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;
}
}
}

0 comments on commit 24210ee

Please sign in to comment.