diff --git a/src/Bolt.Addons.Community.sln b/src/Bolt.Addons.Community.sln index 7ecf5bed..c6bc32e7 100644 --- a/src/Bolt.Addons.Community.sln +++ b/src/Bolt.Addons.Community.sln @@ -1,4 +1,3 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27130.2027 @@ -7,11 +6,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Downloader", "Downloader", EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Legacy", "Legacy", "{0F6B5AB0-D090-41AF-9266-29998CC557E7}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bolt.Addons.Community.Events.Editor", "Events\Editor\Bolt.Addons.Community.Events.Editor.csproj", "{A48FB4F2-A962-4628-8F1E-35191B078F43}" - ProjectSection(ProjectDependencies) = postProject - {33411767-CA47-4D3B-A82C-D77AB4C5FA97} = {33411767-CA47-4D3B-A82C-D77AB4C5FA97} - EndProjectSection -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Fundamentals", "Fundamentals", "{F1756C9F-2895-479E-811A-6E7AA3086E57}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bolt.Addons.Community.Logic", "Legacy\Bolt.Addons.Community.Logic.csproj", "{63E0BE87-2979-4275-A37E-B7F8CBD365F9}" @@ -41,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bolt.Addons.Community.Utili EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bolt.Addons.Community.Utility.Editor", "Utility\Bolt.Addons.Community.Utility.Editor.csproj", "{FCADD801-FF9E-46E5-A573-E06FA0C8661B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bolt.Addons.Community.Events.Editor", "Events\Bolt.Addons.Community.Events.Editor.csproj", "{358C5D0B-573F-4DE3-A00A-1429C9D5ED00}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,10 +45,6 @@ Global Release4.6|Any CPU = Release4.6|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A48FB4F2-A962-4628-8F1E-35191B078F43}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {A48FB4F2-A962-4628-8F1E-35191B078F43}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A48FB4F2-A962-4628-8F1E-35191B078F43}.Release3.5|Any CPU.ActiveCfg = Release|Any CPU - {A48FB4F2-A962-4628-8F1E-35191B078F43}.Release4.6|Any CPU.ActiveCfg = Release|Any CPU {63E0BE87-2979-4275-A37E-B7F8CBD365F9}.Debug|Any CPU.ActiveCfg = Release4.6|Any CPU {63E0BE87-2979-4275-A37E-B7F8CBD365F9}.Debug|Any CPU.Build.0 = Release4.6|Any CPU {63E0BE87-2979-4275-A37E-B7F8CBD365F9}.Release|Any CPU.ActiveCfg = Release4.6|Any CPU @@ -101,10 +93,14 @@ Global {3CE813EF-2925-41C5-B8BA-D8F2BE90058B}.Release3.5|Any CPU.Build.0 = Release3.5|Any CPU {3CE813EF-2925-41C5-B8BA-D8F2BE90058B}.Release4.6|Any CPU.ActiveCfg = Release4.6|Any CPU {3CE813EF-2925-41C5-B8BA-D8F2BE90058B}.Release4.6|Any CPU.Build.0 = Release4.6|Any CPU - {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Debug|Any CPU.ActiveCfg = Release|Any CPU - {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release|Any CPU.ActiveCfg = Release|Any CPU - {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release3.5|Any CPU.ActiveCfg = Release|Any CPU - {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release4.6|Any CPU.ActiveCfg = Release|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Debug|Any CPU.ActiveCfg = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Debug|Any CPU.Build.0 = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release|Any CPU.ActiveCfg = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release|Any CPU.Build.0 = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release3.5|Any CPU.ActiveCfg = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release3.5|Any CPU.Build.0 = Release3.5|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release4.6|Any CPU.ActiveCfg = Release4.6|Any CPU + {33411767-CA47-4D3B-A82C-D77AB4C5FA97}.Release4.6|Any CPU.Build.0 = Release4.6|Any CPU {A2FDB1FB-E259-45C0-B46A-4E416110BBB3}.Debug|Any CPU.ActiveCfg = Release3.5|Any CPU {A2FDB1FB-E259-45C0-B46A-4E416110BBB3}.Debug|Any CPU.Build.0 = Release3.5|Any CPU {A2FDB1FB-E259-45C0-B46A-4E416110BBB3}.Release|Any CPU.ActiveCfg = Release3.5|Any CPU @@ -121,12 +117,19 @@ Global {FCADD801-FF9E-46E5-A573-E06FA0C8661B}.Release3.5|Any CPU.Build.0 = Release3.5|Any CPU {FCADD801-FF9E-46E5-A573-E06FA0C8661B}.Release4.6|Any CPU.ActiveCfg = Release4.6|Any CPU {FCADD801-FF9E-46E5-A573-E06FA0C8661B}.Release4.6|Any CPU.Build.0 = Release4.6|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Debug|Any CPU.ActiveCfg = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Debug|Any CPU.Build.0 = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release|Any CPU.ActiveCfg = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release|Any CPU.Build.0 = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release3.5|Any CPU.ActiveCfg = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release3.5|Any CPU.Build.0 = Release3.5|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release4.6|Any CPU.ActiveCfg = Release4.6|Any CPU + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00}.Release4.6|Any CPU.Build.0 = Release4.6|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {A48FB4F2-A962-4628-8F1E-35191B078F43} = {7D856461-F36E-4843-AA41-C908A2FA7E2C} {63E0BE87-2979-4275-A37E-B7F8CBD365F9} = {0F6B5AB0-D090-41AF-9266-29998CC557E7} {A92A0A22-56D4-4B8A-9623-913B6846A106} = {0F6B5AB0-D090-41AF-9266-29998CC557E7} {5E5C0512-81BC-4C47-878C-89F723D1A589} = {0F6B5AB0-D090-41AF-9266-29998CC557E7} @@ -136,6 +139,7 @@ Global {33411767-CA47-4D3B-A82C-D77AB4C5FA97} = {7D856461-F36E-4843-AA41-C908A2FA7E2C} {A2FDB1FB-E259-45C0-B46A-4E416110BBB3} = {4C7742BC-F6EB-463D-BB44-2783BEC16520} {FCADD801-FF9E-46E5-A573-E06FA0C8661B} = {4C7742BC-F6EB-463D-BB44-2783BEC16520} + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00} = {7D856461-F36E-4843-AA41-C908A2FA7E2C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FBD3EB6F-0BDA-4218-8D0C-0756C8AFE605} diff --git a/src/Bolt.targets b/src/Bolt.targets index 12068a38..57f9c428 100644 --- a/src/Bolt.targets +++ b/src/Bolt.targets @@ -1,6 +1,6 @@ - 1.4.0 + 1.4.1 4.6 diff --git a/src/Events/Editor/Bolt.Addons.Community.Events.Editor.csproj b/src/Events/Bolt.Addons.Community.Events.Editor.csproj similarity index 79% rename from src/Events/Editor/Bolt.Addons.Community.Events.Editor.csproj rename to src/Events/Bolt.Addons.Community.Events.Editor.csproj index 1f4deb91..aa5caa39 100644 --- a/src/Events/Editor/Bolt.Addons.Community.Events.Editor.csproj +++ b/src/Events/Bolt.Addons.Community.Events.Editor.csproj @@ -4,67 +4,66 @@ Debug AnyCPU - {A48FB4F2-A962-4628-8F1E-35191B078F43} + {358C5D0B-573F-4DE3-A00A-1429C9D5ED00} Library Properties - Bolt.Addons.Community.Events.Editor - Bolt.Addons.Community.Events.Editor + Bolt.Addons.Community.DefinedEvents.Editor + Bolt.Addons.Community.DefinedEvents.Editor 512 - - $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Core.Editor.dll - False - $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Core.Runtime.dll - False + + + $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Flow.Runtime.dll + + + $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Core.Runtime.dll + + + $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Graphs.Runtime.dll + + + $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Core.Editor.dll $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Flow.Editor.dll - False - - $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.Flow.Runtime.dll - False + + $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Bolt.State.Editor.dll $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Core.Editor.dll - False - - - $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Core.Runtime.dll - False $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Graphs.Editor.dll - False - - - $(SolutionDir)\..\Dependencies\\BoltBinaries\$(BoltVersion)\.NET$(TargetFrameworkVersionNumber)\Ludiq.Graphs.Runtime.dll - False - - $(SolutionDir)\..\Dependencies\\UnityBinaries\UnityEditor.dll - False - + $(SolutionDir)\..\Dependencies\\UnityBinaries\UnityEngine.dll + + $(SolutionDir)\..\Dependencies\\UnityBinaries\UnityEngine.UI.dll + + + $(SolutionDir)\..\Dependencies\\UnityBinaries\UnityEditor.dll + + - - + - + {33411767-ca47-4d3b-a82c-d77ab4c5fa97} Bolt.Addons.Community.Events + \ No newline at end of file diff --git a/src/Events/Bolt.Addons.Community.Events.csproj b/src/Events/Bolt.Addons.Community.Events.csproj index d7b7e804..f4f64e36 100644 --- a/src/Events/Bolt.Addons.Community.Events.csproj +++ b/src/Events/Bolt.Addons.Community.Events.csproj @@ -7,8 +7,8 @@ {33411767-CA47-4D3B-A82C-D77AB4C5FA97} Library Properties - Bolt.Addons.Community.Events - Bolt.Addons.Community.Events + Bolt.Addons.Community.DefinedEvents + Bolt.Addons.Community.DefinedEvents 512 @@ -40,10 +40,23 @@ + - - - + + + + + + + + + + + + + {c7fa2fb0-acd3-4957-a653-979afadc3145} + Bolt.Addons.Community.Fundamentals + diff --git a/src/Events/Editor/Properties/AssemblyInfo.cs b/src/Events/Editor/Properties/AssemblyInfo.cs deleted file mode 100644 index 7741d753..00000000 --- a/src/Events/Editor/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Bolt.Addons.Community.Events.Editor")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Bolt.Addons.Community.Events.Editor")] -[assembly: AssemblyCopyright("Copyright © 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("a48fb4f2-a962-4628-8f1e-35191b078f43")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Events/Editor/TriggerReturnEventDescriptor.cs b/src/Events/Editor/TriggerReturnEventDescriptor.cs deleted file mode 100644 index 287f1cc8..00000000 --- a/src/Events/Editor/TriggerReturnEventDescriptor.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Ludiq; -using Bolt; - -namespace Bolt.Addons.Community.Events -{ - [Descriptor(typeof(TriggerReturnEvent))] - class TriggerReturnEventDescriptor : UnitDescriptor - { - public TriggerReturnEventDescriptor(TriggerReturnEvent unit) : base(unit) - { - - } - } -} diff --git a/src/Events/Editor/TriggerReturnEventWidget.cs b/src/Events/Editor/TriggerReturnEventWidget.cs deleted file mode 100644 index f000e487..00000000 --- a/src/Events/Editor/TriggerReturnEventWidget.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Ludiq; -using Bolt; - -namespace Bolt.Addons.Community.Events { - [Widget(typeof(TriggerReturnEvent))] - public class TriggerReturnEventWidget : UnitWidget - { - public TriggerReturnEventWidget(TriggerReturnEvent unit) : base(unit) - { - - } - - protected override NodeColorMix baseColor - { - get - { - return NodeColor.Gray; - } - } - - } - -} diff --git a/src/Events/IDefinedEvent.cs b/src/Events/IDefinedEvent.cs new file mode 100644 index 00000000..8c029c1e --- /dev/null +++ b/src/Events/IDefinedEvent.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bolt.Addons.Community.DefinedEvents +{ + public interface IDefinedEvent + { + } +} diff --git a/src/Events/Inspectors/DefinedEventInspector.cs b/src/Events/Inspectors/DefinedEventInspector.cs new file mode 100644 index 00000000..aeec1402 --- /dev/null +++ b/src/Events/Inspectors/DefinedEventInspector.cs @@ -0,0 +1,40 @@ +using Bolt.Addons.Community.DefinedEvents.Units; +using Ludiq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using UnityEngine; + + +namespace Ludiq +{ + //[Inspector(typeof(TargettedDefinedEvent))] + //public class DefinedEventInspector : ReflectedInspector + //{ + // public DefinedEventInspector(Metadata metadata) : base(metadata) + // { + // Debug.Log($"hi"); + // } + + // protected override bool Include(MemberInfo m) + // { + + // if (m.Name == "eventType") + // { + // return true; + // //return (bool)metadata["IsNotRestricted"].value; + // } + + + // if (m.Name == "restrictedEventType") + // { + // return true; + // //return (bool)metadata["IsRestricted"].value; + // } + + // return base.Include(m); + // } + //} +} \ No newline at end of file diff --git a/src/Events/Return.cs b/src/Events/Return.cs deleted file mode 100644 index b646c501..00000000 --- a/src/Events/Return.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Ludiq; -using Bolt; -using System; -using System.Collections.ObjectModel; - -namespace Bolt.Addons.Community.Events -{ - [UnitCategory("Events/Return")] - public class Return : Unit - { - [DoNotSerialize][PortLabelHidden] - public ControlInput enter; - [DoNotSerialize] - public ValueInput returnUnit; - [DoNotSerialize] - public ValueInput returnValue; - - protected override void Definition() - { - enter = ControlInput("enter", new Action(Enter)); - - returnUnit = ValueInput("returnUnit"); - - returnValue = ValueInput("return"); - } - - private void Enter(Flow flow) - { - returnUnit.GetValue().returnValue = returnValue.GetValue(); - returnUnit.GetValue().InvokeReturn(); - } - } -} diff --git a/src/Events/ReturnEvent.cs b/src/Events/ReturnEvent.cs deleted file mode 100644 index 4fdbd836..00000000 --- a/src/Events/ReturnEvent.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEditor; -using Ludiq; -using Bolt; -using System; -using System.Collections.ObjectModel; - -namespace Bolt.Addons.Community.Events -{ - [UnitCategory("Events/Return")] - public class ReturnEvent : GameObjectEventUnit - { - [SerializeAs("count")] - private int _count; - [Inspectable] - [UnitHeaderInspectable("Arguments")] - public int count - { - get { return _count; } - set { _count = Mathf.Clamp(value, 0, 10); } - } - - [DoNotSerialize] [PortLabelHidden] - public ValueInput name; - - [DoNotSerialize] - public List argumentPorts = new List(); - - public List returnValues = new List(); - - public ValueOutput returnUnit; - - protected override bool ShouldTrigger() - { - throw InvalidArgumentCount(0); - } - - protected override bool ShouldTrigger(object argument) - { - throw InvalidArgumentCount(1); - } - - protected override bool ShouldTrigger(object[] arguments) - { - if (arguments.Length == 2) { throw InvalidArgumentCount(2); } - else { return CompareNames(name, (string)arguments[1]); } - } - - protected override void Definition() - { - base.Definition(); - - ArgumentCount(count + 3); - - name = ValueInput("name", string.Empty); - - argumentPorts.Clear(); - - returnUnit = ValueOutput("returnUnit", retUnit => ReturnUnit()); - - for (int i = 0; i < count; i++) - { - var _i = i; - - // 0-2 are reserved for 0) return GameObject 1) return name 2) return identifier - // These are hidden from the visual eye, and combined into an AotDictionary - argumentPorts.Add(ValueOutput(i.ToString(), returnVal => arguments[_i + 3])); - } - } - - private TriggerReturnEvent ReturnUnit() - { - return (TriggerReturnEvent)arguments[2]; - } - - - } -} diff --git a/src/Events/Support/DefinedEventArgs.cs b/src/Events/Support/DefinedEventArgs.cs new file mode 100644 index 00000000..d68721d5 --- /dev/null +++ b/src/Events/Support/DefinedEventArgs.cs @@ -0,0 +1,15 @@ +using System; +using UnityEngine; + +namespace Bolt.Addons.Community.DefinedEvents.Support +{ + public struct DefinedEventArgs + { + public object eventData; + + public DefinedEventArgs(object eventData) + { + this.eventData = eventData; + } + } +} \ No newline at end of file diff --git a/src/Events/Support/DefinedEventSupport.cs b/src/Events/Support/DefinedEventSupport.cs new file mode 100644 index 00000000..3a0b8a29 --- /dev/null +++ b/src/Events/Support/DefinedEventSupport.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace Bolt.Addons.Community.DefinedEvents.Support +{ + static class DefinedEventSupport + { + internal static bool IsOptimized() + { + if (Application.isEditor && !CommunityOptionFetcher.DefinedEvent_ForceOptimizedInEditor) + return false; + return true; + } + } +} \ No newline at end of file diff --git a/src/Events/Support/Internal/IDefinedEventTriggerUnit.cs b/src/Events/Support/Internal/IDefinedEventTriggerUnit.cs new file mode 100644 index 00000000..19c93cd1 --- /dev/null +++ b/src/Events/Support/Internal/IDefinedEventTriggerUnit.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Bolt.Addons.Community.DefinedEvents.Support.Internal +{ + interface IDefinedEventTriggerUnit + { + List inputPorts { get; } + } +} \ No newline at end of file diff --git a/src/Events/Support/Internal/IDefinedEventUnit.cs b/src/Events/Support/Internal/IDefinedEventUnit.cs new file mode 100644 index 00000000..daf11825 --- /dev/null +++ b/src/Events/Support/Internal/IDefinedEventUnit.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Bolt.Addons.Community.DefinedEvents.Support.Internal +{ + interface IDefinedEventUnit + { + List outputPorts { get; } + } +} \ No newline at end of file diff --git a/src/Events/Support/ReflectedInfo.cs b/src/Events/Support/ReflectedInfo.cs new file mode 100644 index 00000000..5f45cea2 --- /dev/null +++ b/src/Events/Support/ReflectedInfo.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace Bolt.Addons.Community.DefinedEvents.Support +{ + class ReflectedInfo + { + public static ReflectedInfo For() + { + return For(typeof(T)); + } + + public static ReflectedInfo For(Type T) + { + lock (Reflections) + { + if (Reflections.ContainsKey(T)) + { + return Reflections[T]; + } + var newInfo = new ReflectedInfo(T); + Reflections.Add(T, newInfo); + return newInfo; + } + } + + private static Dictionary Reflections = new Dictionary(); + + + + + public Dictionary reflectedFields { get; } = new Dictionary(); + + public Dictionary reflectedProperties { get; } = new Dictionary(); + + private Type type; + + + public ReflectedInfo(Type t) + { + type = t; + DefineInputsForEventType(); + } + + private void DefineInputsForEventType() + { + reflectedFields.Clear(); + reflectedProperties.Clear(); + + foreach (var field in type.GetFields()) + { + if (field.IsPublic) + { + reflectedFields.Add(field.Name, field); + } + } + + foreach (var property in type.GetProperties()) + { + var setMethod = property.GetSetMethod(); + + if (setMethod != null) + { + if (setMethod.IsPublic) + { + reflectedProperties.Add(property.Name, property); + } + } + } + } + } +} \ No newline at end of file diff --git a/src/Events/TriggerReturnEvent.cs b/src/Events/TriggerReturnEvent.cs deleted file mode 100644 index 8654de2d..00000000 --- a/src/Events/TriggerReturnEvent.cs +++ /dev/null @@ -1,122 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using Ludiq; -using Bolt; -using System; -using System.Collections.ObjectModel; - -namespace Bolt.Addons.Community.Events -{ - [UnitCategory("Events/Return")] - public class TriggerReturnEvent : GameObjectEventUnit - { - [SerializeAs("count")] - private int _count; - - [Inspectable] - [UnitHeaderInspectable("Arguments")] - public int count - { - get { return _count; } - set { _count = Mathf.Clamp(value, 0, 10); } - } - - [DoNotSerialize][PortLabelHidden] - public ControlInput enter; - - [DoNotSerialize] - public ControlOutput exit; - - [DoNotSerialize] - public ControlOutput returned; - - [DoNotSerialize][PortLabelHidden] - public ValueOutput @return; - - [DoNotSerialize][PortLabelHidden] - public ValueInput name; - - [DoNotSerialize] - public List argumentPorts = new List(); - - public int hashId; - - public bool createdHash; - - public object returnValue; - - protected override bool ShouldTrigger() - { - throw InvalidArgumentCount(0); - } - - protected override bool ShouldTrigger(object argument) - { - throw InvalidArgumentCount(1); - } - - protected override bool ShouldTrigger(object[] arguments) - { - if (arguments.Length == 2) { throw InvalidArgumentCount(2); } - else { return CompareNames(name, (string)arguments[1]); } - } - - protected override void Definition() - { - enter = ControlInput("enter", new Action(Enter)) ; - - base.Definition(); - - ArgumentCount(count + 3); - - name = ValueInput("name", string.Empty); - - argumentPorts.Clear(); - - for (int i = 0; i < count; i++) - { - var _i = i; - argumentPorts.Add(ValueInput(_i.ToString())); - } - - returned = ControlOutput("returned"); - - @return = ValueOutput("return", returnVal => GetReturn()); - } - - private void Enter(Flow flow) - { - flow.Invoke(trigger); - - List args = new List(); - args.Add(targetPort.GetValue()); - args.Add(name.GetValue()); - - if (!createdHash) { - hashId = (new object()).GetHashCode(); - createdHash = true; - } - - args.Add(this); - - foreach (ValueInput input in argumentPorts) - { - args.Add(input.GetValue()); - } - - GameObjectEvent.Trigger((GameObject)args[0], args.ToArray()); - } - - public void InvokeReturn() - { - Flow flow = Flow.New(); - flow.Invoke(returned); - } - - private object GetReturn() - { - return returnValue; - } - } -} \ No newline at end of file diff --git a/src/Events/Units/DefinedEvent.cs b/src/Events/Units/DefinedEvent.cs new file mode 100644 index 00000000..83698f49 --- /dev/null +++ b/src/Events/Units/DefinedEvent.cs @@ -0,0 +1,151 @@ +using Bolt.Addons.Community.DefinedEvents.Support; +using Bolt.Addons.Community.DefinedEvents.Support.Internal; +using Ludiq; +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + + + +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 DefinedEvent : GameObjectEventUnit, IDefinedEventUnit + { + const string EventName = "OnDefinedEvent"; + + #region Event Type Handling + [SerializeAs(nameof(eventType))] + private System.Type _eventType; + + + [DoNotSerialize] + [InspectableIf(nameof(IsNotRestricted))] + public System.Type eventType + { + get { + return _eventType; } + set + { + _eventType = value; + } + } + + [DoNotSerialize] + [UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsRestricted))] + [Ludiq.TypeFilter(TypesMatching.AssignableToAll, typeof(IDefinedEvent))] + public System.Type restrictedEventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + public bool IsRestricted + { + get { return CommunityOptionFetcher.DefinedEvent_RestrictEventTypes; } + } + + public bool IsNotRestricted + { + get { return !IsRestricted; } + } + #endregion + + + [DoNotSerialize] + public List outputPorts { get; } = new List(); + + [DoNotSerialize] + private ReflectedInfo Info; + + protected override string hookName => EventName; + + + + protected override bool ShouldTrigger(Flow flow, DefinedEventArgs args) + { + return args.eventData.GetType() == _eventType; + } + + + protected override void Definition() + { + base.Definition(); + + BuildFromInfo(); + } + + + + private void BuildFromInfo() + { + outputPorts.Clear(); + if (_eventType == null) + return; + + Info = ReflectedInfo.For(_eventType); + foreach (var field in Info.reflectedFields) + { + outputPorts.Add(ValueOutput(field.Value.FieldType, field.Value.Name)); + } + + + foreach (var property in Info.reflectedProperties) + { + outputPorts.Add(ValueOutput(property.Value.PropertyType, property.Value.Name)); + } + } + + protected override void AssignArguments(Flow flow, DefinedEventArgs args) + { + for (var i = 0; i < outputPorts.Count; i++) + { + var outputPort = outputPorts[i]; + var key = outputPort.key; + if (Info.reflectedFields.ContainsKey(key)) + { + var reflectedField = Info.reflectedFields[key]; + flow.SetValue(outputPort, reflectedField.GetValue(args.eventData)); + } + else if (Info.reflectedProperties.ContainsKey(key)) + { + var reflectedProperty = Info.reflectedProperties[key]; + flow.SetValue(outputPort, reflectedProperty.GetValue(args.eventData)); + } + } + } + public override EventHook GetHook(GraphReference reference) + { + var refData = reference.GetElementData(this); + return ConstructHook(refData.target, _eventType); + } + + private static EventHook ConstructHook(GameObject target, Type eventType) + { + EventHook hook; + if (DefinedEventSupport.IsOptimized()) + hook = new EventHook(EventName, target, eventType.GetTypeInfo().FullName); + else + hook = new EventHook(EventName); + return hook; + } + + + public static void Trigger(GameObject target,object eventData) + { + var eventHook = ConstructHook(target, eventData.GetType()); + EventBus.Trigger(eventHook, new DefinedEventArgs(eventData)); + } + } +} \ No newline at end of file diff --git a/src/Events/Units/GlobalDefinedEvent.cs b/src/Events/Units/GlobalDefinedEvent.cs new file mode 100644 index 00000000..4d9d9fb9 --- /dev/null +++ b/src/Events/Units/GlobalDefinedEvent.cs @@ -0,0 +1,156 @@ +using Bolt.Addons.Community.DefinedEvents.Support; +using Bolt.Addons.Community.DefinedEvents.Support.Internal; +using Ludiq; +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + + +namespace Bolt.Addons.Community.DefinedEvents.Units +{ + [UnitCategory("Events")] + [UnitTitle("Global Defined Event")] + [RenamedFrom("Bolt.Addons.Community.DefinedEvents.UniversalDefinedEvent")] + [RenamedFrom("Bolt.Addons.Community.DefinedEvents.Units.UniversalDefinedEvent")] + public class GlobalDefinedEvent : EventUnit, IDefinedEventUnit + { + const string EventName = "OnGlobalDefinedEvent"; + + #region Event Type Handling + + [SerializeAs(nameof(eventType))] + private System.Type _eventType; + + + /// + /// The event type that will trigger this event. + /// + [DoNotSerialize] + //[UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsNotRestricted))] + public System.Type eventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + /// + /// The event type that will trigger this event. + /// + [DoNotSerialize] + [UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsRestricted))] + [Ludiq.TypeFilter(TypesMatching.AssignableToAll, typeof(IDefinedEvent))] + public System.Type restrictedEventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + public bool IsRestricted + { + get { return CommunityOptionFetcher.DefinedEvent_RestrictEventTypes; } + } + + public bool IsNotRestricted + { + get { return !IsRestricted; } + } + #endregion + + + [DoNotSerialize] + public List outputPorts { get; } = new List(); + + [DoNotSerialize] + private ReflectedInfo Info; + + protected override bool register => true; + + protected override bool ShouldTrigger(Flow flow, DefinedEventArgs args) + { + return args.eventData.GetType() == eventType; + } + + public override EventHook GetHook(GraphReference reference) + { + return ConstructHook(eventType); + } + + protected override void Definition() + { + base.Definition(); + + BuildFromInfo(); + } + + + private void BuildFromInfo() + { + outputPorts.Clear(); + if (eventType == null) + return; + + Info = ReflectedInfo.For(eventType); + foreach (var field in Info.reflectedFields) + { + outputPorts.Add(ValueOutput(field.Value.FieldType, field.Value.Name)); + } + + foreach (var property in Info.reflectedProperties) + { + outputPorts.Add(ValueOutput(property.Value.PropertyType, property.Value.Name)); + } + } + + protected override void AssignArguments(Flow flow, DefinedEventArgs args) + { + for (var i = 0; i < outputPorts.Count; i++) + { + var outputPort = outputPorts[i]; + var key = outputPort.key; + if (Info.reflectedFields.ContainsKey(key)) + { + var reflectedField = Info.reflectedFields[key]; + flow.SetValue(outputPort, reflectedField.GetValue(args.eventData)); + } + else if (Info.reflectedProperties.ContainsKey(key)) + { + var reflectedProperty = Info.reflectedProperties[key]; + flow.SetValue(outputPort, reflectedProperty.GetValue(args.eventData)); + } + } + } + + public static void Trigger(object eventData) + { + //var tag = eventData.GetType().GetTypeInfo().FullName; + //var eventHook = new EventHook(EventName, null, tag); + EventHook hook = ConstructHook(eventData.GetType()); + EventBus.Trigger(hook, new DefinedEventArgs(eventData)); + } + + 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; + } + } +} \ No newline at end of file diff --git a/src/Events/Units/TriggerDefinedEvent.cs b/src/Events/Units/TriggerDefinedEvent.cs new file mode 100644 index 00000000..4efb1d84 --- /dev/null +++ b/src/Events/Units/TriggerDefinedEvent.cs @@ -0,0 +1,186 @@ +using System.Reflection; +using System.Collections.Generic; +using Bolt; +using Ludiq; +using UnityEngine; +using Bolt.Addons.Community.DefinedEvents.Support; + +namespace Bolt.Addons.Community.DefinedEvents.Units +{ + [UnitCategory("Events")] + [RenamedFrom("Bolt.Addons.Community.DefinedEvents.TriggerDefinedEvent")] + [UnitTitle("Trigger Defined Event")] + [TypeIcon(typeof(BoltUnityEvent))] + public class TriggerDefinedEvent : Unit + { + #region Event Type Handling + + [SerializeAs(nameof(eventType))] + private System.Type _eventType; + + + /// + /// The event type that will trigger this event. + /// + [DoNotSerialize] + //[UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsNotRestricted))] + public System.Type eventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + /// + /// The event type that will trigger this event. + /// + [DoNotSerialize] + [UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsRestricted))] + [Ludiq.TypeFilter(TypesMatching.AssignableToAll, typeof(IDefinedEvent))] + public System.Type restrictedEventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + + public bool IsRestricted + { + get { return CommunityOptionFetcher.DefinedEvent_RestrictEventTypes; } + } + + public bool IsNotRestricted + { + get { return !IsRestricted; } + } + + #endregion + + + [DoNotSerialize] + [PortLabelHidden] + [NullMeansSelf] + public ValueInput zzzEventTarget { get; private set; } + + + [DoNotSerialize] + public List inputPorts { get; } = new List(); + + /// + /// The entry point to trigger the event. + /// + [DoNotSerialize] + [PortLabelHidden] + public ControlInput enter { get; private set; } + + /// + /// The action to do after the event has been triggered. + /// + [DoNotSerialize] + [PortLabelHidden] + public ControlOutput exit { get; private set; } + + + [DoNotSerialize] + private ReflectedInfo Info; + + + + protected override void Definition() + { + enter = ControlInput(nameof(enter), Trigger); + + exit = ControlOutput(nameof(exit)); + + zzzEventTarget = ValueInput(nameof(zzzEventTarget), null).NullMeansSelf(); + + BuildFromInfo(); + + Requirement(zzzEventTarget, enter); + Succession(enter, exit); + } + + private void BuildFromInfo() + { + inputPorts.Clear(); + if (_eventType == null) + return; + + Info = ReflectedInfo.For(_eventType); + foreach (var field in Info.reflectedFields) + { + if (field.Value.FieldType == typeof(bool)) + inputPorts.Add(ValueInput(field.Value.Name, false)); + else if (field.Value.FieldType == typeof(int)) + inputPorts.Add(ValueInput(field.Value.Name, 0)); + else if(field.Value.FieldType == typeof(float)) + inputPorts.Add(ValueInput(field.Value.Name, 0.0f)); + else if (field.Value.FieldType == typeof(string)) + inputPorts.Add(ValueInput(field.Value.Name, "")); + else if (field.Value.FieldType == typeof(GameObject)) + inputPorts.Add(ValueInput(field.Value.Name, null).NullMeansSelf()); + else + inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name)); + } + + + foreach (var property in Info.reflectedProperties) + { + if (property.Value.PropertyType == typeof(bool)) + inputPorts.Add(ValueInput(property.Value.Name, false)); + else if (property.Value.PropertyType == typeof(int)) + inputPorts.Add(ValueInput(property.Value.Name, 0)); + else if (property.Value.PropertyType == typeof(float)) + inputPorts.Add(ValueInput(property.Value.Name, 0.0f)); + else if (property.Value.PropertyType == typeof(string)) + inputPorts.Add(ValueInput(property.Value.Name, "")); + else if (property.Value.PropertyType == typeof(GameObject)) + inputPorts.Add(ValueInput(property.Value.Name, null).NullMeansSelf()); + else + inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name)); + } + } + + private ControlOutput Trigger(Flow flow) + { + + if (_eventType == null) return exit; + + var eventInstance = System.Activator.CreateInstance(_eventType); + + for (var i = 0; i < inputPorts.Count; i++) + { + var inputPort = inputPorts[i]; + var key = inputPort.key; + var value = flow.GetValue(inputPort); + if (Info.reflectedFields.ContainsKey(key)) + { + var reflectedField = Info.reflectedFields[key]; + reflectedField.SetValue(eventInstance, value); + } + else if (Info.reflectedProperties.ContainsKey(key)) + { + var reflectedProperty = Info.reflectedProperties[key]; + reflectedProperty.SetValue(eventInstance, value); + } + } + + DefinedEvent.Trigger(flow.GetValue(zzzEventTarget), eventInstance); + + return exit; + } + } +} \ No newline at end of file diff --git a/src/Events/Units/TriggerGlobalDefinedEvent.cs b/src/Events/Units/TriggerGlobalDefinedEvent.cs new file mode 100644 index 00000000..fcad953b --- /dev/null +++ b/src/Events/Units/TriggerGlobalDefinedEvent.cs @@ -0,0 +1,166 @@ +using System.Reflection; +using System.Collections.Generic; +using Bolt; +using Ludiq; +using UnityEngine; +using Bolt.Addons.Community.DefinedEvents.Support; + +namespace Bolt.Addons.Community.DefinedEvents.Units +{ + [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 TriggerGlobalDefinedEvent : Unit + { + #region Event Type Handling + + [SerializeAs(nameof(eventType))] + private System.Type _eventType; + + + [DoNotSerialize] + [InspectableIf(nameof(IsNotRestricted))] + public System.Type eventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + [DoNotSerialize] + [UnitHeaderInspectable("Event Type")] + [InspectableIf(nameof(IsRestricted))] + [Ludiq.TypeFilter(TypesMatching.AssignableToAll, typeof(IDefinedEvent))] + public System.Type restrictedEventType + { + get + { + return _eventType; + } + set + { + _eventType = value; + } + } + + + public bool IsRestricted + { + get { return CommunityOptionFetcher.DefinedEvent_RestrictEventTypes; } + } + + public bool IsNotRestricted + { + get { return !IsRestricted; } + } + + #endregion + + [DoNotSerialize] + public List inputPorts { get; } = new List(); + + [DoNotSerialize] + [PortLabelHidden] + public ControlInput enter { get; private set; } + + /// + /// The action to do after the event has been triggered. + /// + [DoNotSerialize] + [PortLabelHidden] + public ControlOutput exit { get; private set; } + + [DoNotSerialize] + private ReflectedInfo Info; + + protected override void Definition() + { + enter = ControlInput(nameof(enter), Trigger); + + exit = ControlOutput(nameof(exit)); + + + BuildFromInfo(); + + Succession(enter, exit); + } + + private void BuildFromInfo() + { + inputPorts.Clear(); + if (eventType == null) + return; + + Info = ReflectedInfo.For(eventType); + foreach (var field in Info.reflectedFields) + { + if (field.Value.FieldType == typeof(bool)) + inputPorts.Add(ValueInput(field.Value.Name, false)); + else if (field.Value.FieldType == typeof(int)) + inputPorts.Add(ValueInput(field.Value.Name, 0)); + else if (field.Value.FieldType == typeof(float)) + inputPorts.Add(ValueInput(field.Value.Name, 0.0f)); + else if (field.Value.FieldType == typeof(string)) + inputPorts.Add(ValueInput(field.Value.Name, "")); + else if (field.Value.FieldType == typeof(GameObject)) + inputPorts.Add(ValueInput(field.Value.Name, null).NullMeansSelf()); + else + inputPorts.Add(ValueInput(field.Value.FieldType, field.Value.Name)); + } + + + foreach (var property in Info.reflectedProperties) + { + if (property.Value.PropertyType == typeof(bool)) + inputPorts.Add(ValueInput(property.Value.Name, false)); + else if (property.Value.PropertyType == typeof(int)) + inputPorts.Add(ValueInput(property.Value.Name, 0)); + else if (property.Value.PropertyType == typeof(float)) + inputPorts.Add(ValueInput(property.Value.Name, 0.0f)); + else if (property.Value.PropertyType == typeof(string)) + inputPorts.Add(ValueInput(property.Value.Name, "")); + else if (property.Value.PropertyType == typeof(GameObject)) + inputPorts.Add(ValueInput(property.Value.Name, null).NullMeansSelf()); + else + inputPorts.Add(ValueInput(property.Value.PropertyType, property.Value.Name)); + } + } + + private ControlOutput Trigger(Flow flow) + { + + if (eventType == null) return exit; + + var eventInstance = System.Activator.CreateInstance(eventType); + + for (var i = 0; i < inputPorts.Count; i++) + { + var inputPort = inputPorts[i]; + var key = inputPort.key; + var value = flow.GetValue(inputPort); + if (Info.reflectedFields.ContainsKey(key)) + { + var reflectedField = Info.reflectedFields[key]; + reflectedField.SetValue(eventInstance, value); + } + else if (Info.reflectedProperties.ContainsKey(key)) + { + var reflectedProperty = Info.reflectedProperties[key]; + reflectedProperty.SetValue(eventInstance, value); + } + } + + GlobalDefinedEvent.Trigger(eventInstance); + + return exit; + } + } + +} \ No newline at end of file diff --git a/src/Events/Widgets/DefinedEventWidget.cs b/src/Events/Widgets/DefinedEventWidget.cs new file mode 100644 index 00000000..34502cf2 --- /dev/null +++ b/src/Events/Widgets/DefinedEventWidget.cs @@ -0,0 +1,56 @@ +using Bolt.Addons.Community.DefinedEvents.Units; +using Ludiq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using UnityEditor; +using UnityEngine; + +namespace Bolt.Addons.Community.DefinedEvents.Editor.Widgets +{ + //[Widget(typeof(TargettedDefinedEvent))] + //public sealed class DefinedEventWidget : UnitWidget + //{ + // public DefinedEventWidget(FlowCanvas canvas, TargettedDefinedEvent unit) : base(canvas, unit) + // { + // Debug.Log($"hi2"); + // } + + // protected override float GetHeaderAddonHeight(float width) + // { + // return EditorGUIUtility.singleLineHeight; + // } + + // public override void BeforeFrame() + // { + // base.BeforeFrame(); + + // if (GetHeaderAddonWidth() != headerAddonPosition.width || + // GetHeaderAddonHeight(headerAddonPosition.width) != headerAddonPosition.height) + // { + // Reposition(); + // } + // } + + // protected override void DrawHeaderAddon() + // { + // using (LudiqGUIUtility.labelWidth.Override(75)) // For reflected inspectors / custom property drawers + // using (Inspector.adaptiveWidth.Override(true)) + // { + // EditorGUI.BeginChangeCheck(); + + // if (unit.IsRestricted) + // LudiqGUI.Inspector(metadata["restrictedEventType"], headerAddonPosition, GUIContent.none); + // else + // LudiqGUI.Inspector(metadata["eventType"], headerAddonPosition, GUIContent.none); + + // if (EditorGUI.EndChangeCheck()) + // { + // unit.EnsureDefined(); + // Reposition(); + // } + // } + // } + //} +} \ No newline at end of file diff --git a/src/Fundamentals/Bolt.Addons.Community.Fundamentals.Editor.csproj b/src/Fundamentals/Bolt.Addons.Community.Fundamentals.Editor.csproj index 787f1bf3..6bf8de80 100644 --- a/src/Fundamentals/Bolt.Addons.Community.Fundamentals.Editor.csproj +++ b/src/Fundamentals/Bolt.Addons.Community.Fundamentals.Editor.csproj @@ -53,6 +53,7 @@ + @@ -73,6 +74,7 @@ + @@ -121,7 +123,9 @@ - + + + \ No newline at end of file diff --git a/src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj b/src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj index a8d0769a..0c01f041 100644 --- a/src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj +++ b/src/Fundamentals/Bolt.Addons.Community.Fundamentals.csproj @@ -35,10 +35,13 @@ + + + @@ -60,6 +63,7 @@ + diff --git a/src/Fundamentals/CommunityOptionFetcher.cs b/src/Fundamentals/CommunityOptionFetcher.cs new file mode 100644 index 00000000..daaf2e0b --- /dev/null +++ b/src/Fundamentals/CommunityOptionFetcher.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace Bolt.Addons.Community +{ + public static class CommunityOptionFetcher + { + static object lockObject = new object(); + static CommunityOptionFetcher() + { + lock (lockObject) + { + var type = typeof(CommunityOptions); + var types = AppDomain.CurrentDomain.GetAssemblies() + .SelectMany(s => s.GetTypes()) + .Where(p => + { + if (type.IsAssignableFrom(p)) + { + return p.Assembly != type.Assembly; + } + return false; + }).ToList(); + + if (types.Count() > 1) + { + Debug.LogError("Multiple Community Options scripts found."); + return; + } + + if (types.Count() == 1) + { + + CommunityOptions options = (CommunityOptions)Activator.CreateInstance(types.First()); + DefinedEvent_ForceOptimizedInEditor = options.DefinedEvent_ForceOptimizedInEditor; + DefinedEvent_RestrictEventTypes = options.DefinedEvent_RestrictEventTypes; + SilenceLogMessages = options.SilenceLogMessages; + + if (!SilenceLogMessages) + { + Debug.Log("Custom Community Options script found."); + LogOptionsSelected(); + } + + return; + } + Debug.Log("No Community Options script found; using defaults"); + } + } + + private static void LogOptionsSelected() + { + Debug.Log($"Defined Events optimized in editor: {FormatBool(DefinedEvent_ForceOptimizedInEditor)}"); + Debug.Log($"Defined Events restrict type to interface implementors: {FormatBool(DefinedEvent_RestrictEventTypes)}"); + } + + private static object FormatBool(bool input) + { + return input ? "True" : "False"; + } + + + + public static bool DefinedEvent_ForceOptimizedInEditor { get; } = false; + public static bool DefinedEvent_RestrictEventTypes { get; } = true; + public static bool SilenceLogMessages { get; } = false; + } +} diff --git a/src/Fundamentals/CommunityOptions.cs b/src/Fundamentals/CommunityOptions.cs new file mode 100644 index 00000000..7caeac73 --- /dev/null +++ b/src/Fundamentals/CommunityOptions.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Bolt.Addons.Community +{ + public class CommunityOptions + { + public virtual bool DefinedEvent_ForceOptimizedInEditor { get; } = false; + public virtual bool DefinedEvent_RestrictEventTypes { get; } = false; + + + public virtual bool SilenceLogMessages { get; } = true; + } +} diff --git a/src/Fundamentals/Editor/Descriptors/LogUnitDescriptor.cs b/src/Fundamentals/Editor/Descriptors/LogUnitDescriptor.cs new file mode 100644 index 00000000..abfb1570 --- /dev/null +++ b/src/Fundamentals/Editor/Descriptors/LogUnitDescriptor.cs @@ -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 + { + 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); + } + } +} diff --git a/src/Fundamentals/Editor/Widgets/SomeValueWidget.cs b/src/Fundamentals/Editor/Widgets/SomeValueWidget.cs new file mode 100644 index 00000000..296a7d65 --- /dev/null +++ b/src/Fundamentals/Editor/Widgets/SomeValueWidget.cs @@ -0,0 +1,26 @@ +using Bolt.Addons.Community.Fundamentals.Units.Documenting; +using Ludiq; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Bolt.Addons.Community.Fundamentals.Editor.Editor.Widgets +{ + [Widget(typeof(SomeValue))] + public sealed class SomeValueWidget : UnitWidget + { + + public SomeValueWidget(FlowCanvas canvas, SomeValue unit) : base(canvas, unit) + { + } + + protected override NodeColorMix baseColor + { + get + { + return new NodeColorMix() { red = 0.6578709f, green = 1f }; + } + } + } +} \ No newline at end of file diff --git a/src/Fundamentals/Resources/debug.png b/src/Fundamentals/Resources/debug.png new file mode 100644 index 00000000..e803eb1e Binary files /dev/null and b/src/Fundamentals/Resources/debug.png differ diff --git a/src/Fundamentals/Units/Documenting/SomeValue.cs b/src/Fundamentals/Units/Documenting/SomeValue.cs new file mode 100644 index 00000000..bd4b6f6c --- /dev/null +++ b/src/Fundamentals/Units/Documenting/SomeValue.cs @@ -0,0 +1,29 @@ +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.Documenting +{ + [UnitCategory("Community\\Documentation")] + public class SomeValue : Unit + { + [Inspectable] + public bool IsInteger; + + [DoNotSerialize] + [PortLabelHidden] + public ValueOutput output { get; private set; } + + protected override void Definition() + { + if (IsInteger) + output = ValueOutput(nameof(output), (flow)=> UnityEngine.Random.Range(0,1)); + else + output = ValueOutput(nameof(output), (flow) => UnityEngine.Random.Range(0.0f, 1.0f)); + } + } +} \ No newline at end of file diff --git a/src/Fundamentals/Units/Logic/Branching/BranchParams.cs b/src/Fundamentals/Units/Logic/Branching/BranchParams.cs index ecf8644c..80c59d1f 100644 --- a/src/Fundamentals/Units/Logic/Branching/BranchParams.cs +++ b/src/Fundamentals/Units/Logic/Branching/BranchParams.cs @@ -106,7 +106,6 @@ bool NumericComparison(float a, float b, bool allowEquals) for (int i = 1; i < arguments.Count; i++) { - Debug.Log(flow.GetValue(arguments[i])); if (!Mathf.Approximately(target, flow.GetValue(arguments[i]))) return false; } diff --git a/src/Fundamentals/Units/Logic/LogUnit.cs b/src/Fundamentals/Units/Logic/LogUnit.cs new file mode 100644 index 00000000..956b2120 --- /dev/null +++ b/src/Fundamentals/Units/Logic/LogUnit.cs @@ -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 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(nameof(format), ""); + + input = ControlInput(nameof(input), (flow) => Log(flow)); + output = ControlOutput(nameof(output)); + + arguments = new List(); + for (var i = 0; i < Math.Min(argumentCount, ArgumentLimit); i++) + { + var argument = ValueInput("Arg_" + i); + arguments.Add(argument); + Requirement(argument, input); + } + + Succession(input, output); + Requirement(format, input); + } + + private ControlOutput Log(Flow flow) + { + string formatstr = flow.GetValue(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(x => + { + + var val = flow.GetValue(x); + if (val is string) + return val as string; + return val.ToString(); + }); + + Debug.Log(string.Format(flow.GetValue(format), stringArgs.ToArray())); + return output; + } + } +} \ No newline at end of file