Skip to content

Commit

Permalink
Merge branch '2.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
RealityStop committed Oct 5, 2019
2 parents 4032d9c + cb48767 commit 1f98da1
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Bolt.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BoltVersion>1.4.1</BoltVersion>
<BoltVersion>1.4.7</BoltVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release4.6'">
<TargetFrameworkVersionNumber>4.6</TargetFrameworkVersionNumber>
Expand Down
8 changes: 6 additions & 2 deletions src/Events/Bolt.Addons.Community.Events.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,19 @@
<Compile Include="Support\Internal\IDefinedEventUnit.cs" />
<Compile Include="Units\TriggerGlobalDefinedEvent.cs" />
<Compile Include="Units\TriggerDefinedEvent.cs" />
<Compile Include="Units\GlobalDefinedEvent.cs" />
<Compile Include="Units\GlobalDefinedEventUnit.cs" />
<Compile Include="Support\DefinedEventArgs.cs" />
<Compile Include="Units\DefinedEvent.cs" />
<Compile Include="Units\DefinedEventUnit.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fundamentals\Bolt.Addons.Community.Fundamentals.csproj">
<Project>{c7fa2fb0-acd3-4957-a653-979afadc3145}</Project>
<Name>Bolt.Addons.Community.Fundamentals</Name>
</ProjectReference>
<ProjectReference Include="..\Utility\Bolt.Addons.Community.Utility.csproj">
<Project>{A2FDB1FB-E259-45C0-B46A-4E416110BBB3}</Project>
<Name>Bolt.Addons.Community.Utility</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
39 changes: 35 additions & 4 deletions src/Events/ScriptingProxy/DefinedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Bolt.Addons.Community.DefinedEvents.Units;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -17,7 +18,7 @@ public static class DefinedEvent
/// <param name="eventData">This is a filled object of the type of event you want to trigger.</param>
public static void Trigger(GameObject target, object eventData)
{
Bolt.Addons.Community.DefinedEvents.Units.DefinedEvent.Trigger(target, eventData);
DefinedEventUnit.Trigger(target, eventData);
}

/// <summary>
Expand All @@ -28,7 +29,37 @@ public static void Trigger(GameObject target, object eventData)
/// <param name="eventData">This is a filled object of the type of event you want to trigger.</param>
public static void TriggerGlobal(object eventData)
{
Bolt.Addons.Community.DefinedEvents.Units.GlobalDefinedEvent.Trigger(eventData);
GlobalDefinedEventUnit.Trigger(eventData);
}

/// <summary>
/// Registers a C# listener for an event on the target object. This is the scripting
/// equivalent to the Defined Event unit. Notice the IDisposable return value, which allows you
/// to end the subscription for the event (via calling the .Dispose() method).
/// </summary>
/// <typeparam name="T">The type to listen for.</typeparam>
/// <param name="target">The game object to listen on to receive the event.</param>
/// <param name="onEvent">The action or method to call when the event occurs</param>
/// <returns>A disposable that, when .Dispose is called, will unsubscribe from the
/// event, essentially cancelling the call to RegisterListener.</returns>
public static IDisposable RegisterListener<T>(GameObject target, Action<T> onEvent)
{
return DefinedEventUnit.RegisterListener<T>(target, onEvent);
}

/// <summary>
/// Registers a C# listener for an event globally. This is the scripting
/// equivalent to the Global Defined Event unit. Notice the IDisposable return
/// value, which allows you to end the subscription for the event (via calling
/// the .Dispose() method).
/// </summary>
/// <typeparam name="T">The type to listen for.</typeparam>
/// <param name="onEvent">The action or method to call when the event occurs</param>
/// <returns>A disposable that, when .Dispose is called, will unsubscribe from the
/// event, essentially cancelling the call to RegisterListener.</returns>
public static IDisposable RegisterGlobalListener<T>(Action<T> onEvent)
{
return GlobalDefinedEventUnit.RegisterListener<T>(onEvent);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bolt.Addons.Community.DefinedEvents.Support;
using Bolt.Addons.Community.DefinedEvents.Support.Internal;
using Bolt.Addons.Community.Utility;
using Ludiq;
using System;
using System.Collections.Generic;
Expand All @@ -15,7 +16,8 @@ namespace Bolt.Addons.Community.DefinedEvents.Units
/// </summary>
[UnitCategory("Events")]
[UnitTitle("Defined Event")]
public class DefinedEvent : GameObjectEventUnit<DefinedEventArgs>, IDefinedEventUnit
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.DefinedEvent")]
public class DefinedEventUnit : GameObjectEventUnit<DefinedEventArgs>, IDefinedEventUnit
{
const string EventName = "OnDefinedEvent";

Expand Down Expand Up @@ -148,5 +150,16 @@ public static void Trigger(GameObject target,object eventData)
var eventHook = ConstructHook(target, eventData.GetType());
EventBus.Trigger(eventHook, new DefinedEventArgs(eventData));
}



public static IDisposable RegisterListener<T>(GameObject target, Action<T> onEvent)
{
var eventHook = ConstructHook(target, typeof(T));
Action<DefinedEventArgs> action = (x) => { onEvent((T)x.eventData); };
EventBus.Register<DefinedEventArgs>(eventHook, action);

return Disposable.Create(() => { EventBus.Unregister(eventHook, action); });
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bolt.Addons.Community.DefinedEvents.Support;
using Bolt.Addons.Community.DefinedEvents.Support.Internal;
using Bolt.Addons.Community.Utility;
using Ludiq;
using System;
using System.Collections.Generic;
Expand All @@ -16,7 +17,8 @@ namespace Bolt.Addons.Community.DefinedEvents.Units
/// </summary>
[UnitCategory("Events")]
[UnitTitle("Global Defined Event")]
public class GlobalDefinedEvent : EventUnit<DefinedEventArgs>, IDefinedEventUnit
[RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.GlobalDefinedEvent")]
public class GlobalDefinedEventUnit : EventUnit<DefinedEventArgs>, IDefinedEventUnit
{
const string EventName = "OnGlobalDefinedEvent";

Expand Down Expand Up @@ -138,6 +140,16 @@ protected override void AssignArguments(Flow flow, DefinedEventArgs args)
}
}

private static EventHook ConstructHook(Type eventType)
{
EventHook hook;
if (DefinedEventSupport.IsOptimized())
hook = new EventHook(EventName, tag: eventType.GetTypeInfo().FullName);
else
hook = new EventHook(EventName);
return hook;
}

public static void Trigger(object eventData)
{
//var tag = eventData.GetType().GetTypeInfo().FullName;
Expand All @@ -146,14 +158,14 @@ public static void Trigger(object eventData)
EventBus.Trigger(hook, new DefinedEventArgs(eventData));
}

private static EventHook ConstructHook(Type eventType)

public static IDisposable RegisterListener<T>(Action<T> onEvent)
{
EventHook hook;
if (DefinedEventSupport.IsOptimized())
hook = new EventHook(EventName, tag: eventType.GetTypeInfo().FullName);
else
hook = new EventHook(EventName);
return hook;
var eventHook = ConstructHook(typeof(T));
Action<DefinedEventArgs> action = (x) => { onEvent((T)x.eventData); };
EventBus.Register<DefinedEventArgs>(eventHook, action);

return Disposable.Create(() => { EventBus.Unregister(eventHook, action); });
}
}
}
2 changes: 1 addition & 1 deletion src/Events/Units/TriggerDefinedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private ControlOutput Trigger(Flow flow)
}
}

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

return exit;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Events/Units/TriggerGlobalDefinedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private ControlOutput Trigger(Flow flow)
}
}

GlobalDefinedEvent.Trigger(eventInstance);
GlobalDefinedEventUnit.Trigger(eventInstance);

return exit;
}
Expand Down
7 changes: 4 additions & 3 deletions src/Utility/Bolt.Addons.Community.Utility.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
Expand All @@ -13,13 +13,13 @@
</PropertyGroup>
<Import Project="$(SolutionDir)\Bolt.targets" />
<ItemGroup>
<Reference Include="UnityEngine">
<Reference Include="UnityEngine">
<HintPath>$(SolutionDir)..\Dependencies\UnityBinaries\UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(SolutionDir)..\Dependencies\UnityBinaries\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="Bolt.Core.Runtime">
<Reference Include="Bolt.Core.Runtime">
<HintPath>$(SolutionDir)\..\Dependencies\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Core.Runtime.dll</HintPath>
</Reference>
<Reference Include="Bolt.Flow.Runtime">
Expand All @@ -35,6 +35,7 @@
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<Compile Include="Disposable.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UnitButton.cs" />
<Compile Include="UnitButtonAttribute.cs" />
Expand Down
34 changes: 34 additions & 0 deletions src/Utility/Disposable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Bolt.Addons.Community.Utility
{
public class Disposable : IDisposable
{
public static IDisposable Create(Action action)
{
return new Disposable(action);
}

public static IDisposable Empty = new Disposable(null);

Disposable(Action action)
{
_action = action;
}

void IDisposable.Dispose()
{
if (_action != null)
{
_action();
_action = null;
}
}

private Action _action;
}
}

0 comments on commit 1f98da1

Please sign in to comment.