From a4911b74af751da33f0e17a3034850cc829ec156 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Wed, 15 Jun 2022 17:45:30 -0400 Subject: [PATCH 1/4] switchlamp: add support for compare type matching --- Editor/Inspectors/CompareTypeInspector.cs | 108 ++++++++++++++++++ .../Inspectors/CompareTypeInspector.cs.meta | 11 ++ Runtime/Nodes/Lamps/SwitchLampUnit.cs | 36 +++++- Runtime/Nodes/Logic.meta | 8 ++ Runtime/Nodes/Logic/CompareType.cs | 41 +++++++ Runtime/Nodes/Logic/CompareType.cs.meta | 11 ++ 6 files changed, 213 insertions(+), 2 deletions(-) create mode 100644 Editor/Inspectors/CompareTypeInspector.cs create mode 100644 Editor/Inspectors/CompareTypeInspector.cs.meta create mode 100644 Runtime/Nodes/Logic.meta create mode 100644 Runtime/Nodes/Logic/CompareType.cs create mode 100644 Runtime/Nodes/Logic/CompareType.cs.meta diff --git a/Editor/Inspectors/CompareTypeInspector.cs b/Editor/Inspectors/CompareTypeInspector.cs new file mode 100644 index 0000000..0a8a443 --- /dev/null +++ b/Editor/Inspectors/CompareTypeInspector.cs @@ -0,0 +1,108 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using Unity.VisualScripting; +using UnityEditor; +using UnityEngine; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Inspector(typeof(CompareType))] + public class CompareTypeInspector : Inspector + { + private List CompareTypes = Enum.GetValues(typeof(CompareType)).Cast().ToList(); + private string[] CompareTypeDescriptions = Enum.GetValues(typeof(CompareType)).Cast().Select(x => GetEnumDescription(x)).ToArray(); + + public CompareTypeInspector(Metadata metadata) : base(metadata) { + } + + public override void Initialize() + { + metadata.instantiate = true; + + base.Initialize(); + } + + protected override float GetHeight(float width, GUIContent label) + { + return HeightWithLabel(metadata, width, EditorGUIUtility.singleLineHeight, label); + } + + protected override void OnGUI(Rect position, GUIContent label) + { + position = BeginLabeledBlock(metadata, position, label); + + var fieldPosition = new Rect + ( + position.x, + position.y, + position.width, + EditorGUIUtility.singleLineHeight + ); + + var index = CompareTypes.FindIndex(c => c == (CompareType)metadata.value); + var newIndex = EditorGUI.Popup(fieldPosition, index, CompareTypeDescriptions); + + if (EndBlock(metadata)) + { + metadata.RecordUndo(); + metadata.value = CompareTypes[newIndex]; + } + } + + public override float GetAdaptiveWidth() + { + return Mathf.Max(18, EditorStyles.popup.CalcSize(new GUIContent(GetEnumDescription((CompareType)metadata.value))).x + Styles.popup.fixedWidth); + } + + private static string GetEnumDescription(Enum value) + { + FieldInfo field = value.GetType().GetField(value.ToString()); + + DescriptionAttribute attribute + = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) + as DescriptionAttribute; + + return (attribute == null ? value.ToString() : attribute.Description).Replace('/', '\u2215'); + } + } + + public static class Styles + { + static Styles() + { + popup = new GUIStyle("TextFieldDropDown"); + popup.fixedWidth = 10; + popup.clipping = TextClipping.Clip; + popup.normal.textColor = ColorPalette.transparent; + popup.active.textColor = ColorPalette.transparent; + popup.hover.textColor = ColorPalette.transparent; + popup.focused.textColor = ColorPalette.transparent; + popup.onNormal.textColor = ColorPalette.transparent; + popup.onActive.textColor = ColorPalette.transparent; + popup.onHover.textColor = ColorPalette.transparent; + popup.onFocused.textColor = ColorPalette.transparent; + } + + public static readonly GUIStyle textField; + public static readonly GUIStyle popup; + } +} diff --git a/Editor/Inspectors/CompareTypeInspector.cs.meta b/Editor/Inspectors/CompareTypeInspector.cs.meta new file mode 100644 index 0000000..995e733 --- /dev/null +++ b/Editor/Inspectors/CompareTypeInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac7985d65cfa449d389e96d71b1ac8da +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Lamps/SwitchLampUnit.cs b/Runtime/Nodes/Lamps/SwitchLampUnit.cs index 3a24a60..b153fb1 100644 --- a/Runtime/Nodes/Lamps/SwitchLampUnit.cs +++ b/Runtime/Nodes/Lamps/SwitchLampUnit.cs @@ -37,6 +37,9 @@ public class SwitchLampUnit : GleUnit, IMultiInputUnit [Serialize, Inspectable, UnitHeaderInspectable("Non Match")] public LampDataType NonMatchDataType { get; set; } + [Serialize, Inspectable, UnitHeaderInspectable("Value Compare")] + public CompareType ValueCompareType { get; set; } + [DoNotSerialize] [Inspectable, UnitHeaderInspectable("Lamp IDs")] public int inputCount @@ -134,8 +137,37 @@ private ControlOutput Process(Flow flow) var lampIdValue = _lampIdValueCache[json.GetHashCode()]; - var dataType = lampIdValue.value == sourceValue ? MatchDataType : NonMatchDataType; - var value = lampIdValue.value == sourceValue ? Match : NonMatch; + var match = false; + + switch(ValueCompareType) + { + case CompareType.NotEqual: + match = lampIdValue.value != sourceValue; + break; + + case CompareType.GreaterThan: + match = lampIdValue.value > sourceValue; + break; + + case CompareType.GreaterThanEqual: + match = lampIdValue.value >= sourceValue; + break; + + case CompareType.LessThan: + match = lampIdValue.value < sourceValue; + break; + + case CompareType.LessThanEqual: + match = lampIdValue.value < sourceValue; + break; + + default: + match = lampIdValue.value == sourceValue; + break; + } + + var dataType = match ? MatchDataType : NonMatchDataType; + var value = match ? Match : NonMatch; switch (dataType) { case LampDataType.OnOff: diff --git a/Runtime/Nodes/Logic.meta b/Runtime/Nodes/Logic.meta new file mode 100644 index 0000000..621cc6d --- /dev/null +++ b/Runtime/Nodes/Logic.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 73192e7aa6c1d4d6fb9f28787a6dc0df +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Logic/CompareType.cs b/Runtime/Nodes/Logic/CompareType.cs new file mode 100644 index 0000000..605b2d3 --- /dev/null +++ b/Runtime/Nodes/Logic/CompareType.cs @@ -0,0 +1,41 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.ComponentModel; + +namespace VisualPinball.Unity.VisualScripting +{ + public enum CompareType + { + [Description("=")] + Equal, + + [Description("\u2260")] + NotEqual, + + [Description("<")] + LessThan, + + [Description("\u2264")] + LessThanEqual, + + [Description(">")] + GreaterThan, + + [Description("\u2265")] + GreaterThanEqual + } +} diff --git a/Runtime/Nodes/Logic/CompareType.cs.meta b/Runtime/Nodes/Logic/CompareType.cs.meta new file mode 100644 index 0000000..34dd3df --- /dev/null +++ b/Runtime/Nodes/Logic/CompareType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: db84bb9bc867b4f5ba03a14e54abc2ad +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: From 2c6f1ff58813b2354c9c54afaa157305763acbd1 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Wed, 15 Jun 2022 22:01:00 -0400 Subject: [PATCH 2/4] switchlamp: fix Less Than Equal compare --- Runtime/Nodes/Lamps/SwitchLampUnit.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Runtime/Nodes/Lamps/SwitchLampUnit.cs b/Runtime/Nodes/Lamps/SwitchLampUnit.cs index b153fb1..740b6f6 100644 --- a/Runtime/Nodes/Lamps/SwitchLampUnit.cs +++ b/Runtime/Nodes/Lamps/SwitchLampUnit.cs @@ -158,7 +158,7 @@ private ControlOutput Process(Flow flow) break; case CompareType.LessThanEqual: - match = lampIdValue.value < sourceValue; + match = lampIdValue.value <= sourceValue; break; default: From 0213cc815a6a3f7b188cebdfa60fc1e936d9af4e Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Thu, 16 Jun 2022 08:08:21 -0400 Subject: [PATCH 3/4] misc: added generic AttributedEnumInspector --- Editor/Inspectors/AttributedEnumInspector.cs | 89 +++++++++++++++++++ .../AttributedEnumInspector.cs.meta | 11 +++ Editor/Inspectors/CompareTypeInspector.cs | 86 +----------------- Editor/Inspectors/LampDataTypeInspector.cs | 28 ++++++ .../Inspectors/LampDataTypeInspector.cs.meta | 11 +++ Runtime/Nodes/Lamps/LampDataType.cs | 43 +++++---- 6 files changed, 167 insertions(+), 101 deletions(-) create mode 100644 Editor/Inspectors/AttributedEnumInspector.cs create mode 100644 Editor/Inspectors/AttributedEnumInspector.cs.meta create mode 100644 Editor/Inspectors/LampDataTypeInspector.cs create mode 100644 Editor/Inspectors/LampDataTypeInspector.cs.meta diff --git a/Editor/Inspectors/AttributedEnumInspector.cs b/Editor/Inspectors/AttributedEnumInspector.cs new file mode 100644 index 0000000..8463bb7 --- /dev/null +++ b/Editor/Inspectors/AttributedEnumInspector.cs @@ -0,0 +1,89 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using Unity.VisualScripting; +using UnityEditor; +using UnityEngine; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + public abstract class AttributedEnumInspector : Inspector + { + private List Enums; + private string[] EnumDescriptions; + + public AttributedEnumInspector(Metadata metadata) : base(metadata) { + } + + public override void Initialize() + { + Enums = Enum.GetValues(typeof(TEnum)).Cast().ToList(); + EnumDescriptions = Enum.GetValues(typeof(TEnum)).Cast().Select(x => GetEnumDescription(x)).ToArray(); + + metadata.instantiate = true; + + base.Initialize(); + } + + protected override float GetHeight(float width, GUIContent label) + { + return HeightWithLabel(metadata, width, EditorGUIUtility.singleLineHeight, label); + } + + protected override void OnGUI(Rect position, GUIContent label) + { + position = BeginLabeledBlock(metadata, position, label); + + var fieldPosition = new Rect + ( + position.x, + position.y, + position.width, + EditorGUIUtility.singleLineHeight + ); + + var index = Enums.FindIndex(c => c.Equals(metadata.value)); + var newIndex = EditorGUI.Popup(fieldPosition, index, EnumDescriptions); + + if (EndBlock(metadata)) + { + metadata.RecordUndo(); + metadata.value = Enums[newIndex]; + } + } + + public override float GetAdaptiveWidth() + { + return Mathf.Max(18, EditorStyles.popup.CalcSize(new GUIContent(GetEnumDescription((TEnum)metadata.value))).x); + } + + private string GetEnumDescription(TEnum value) + { + FieldInfo field = value.GetType().GetField(value.ToString()); + + DescriptionAttribute attribute + = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) + as DescriptionAttribute; + + return (attribute == null ? value.ToString() : attribute.Description).Replace('/', '\u2215'); + } + } +} \ No newline at end of file diff --git a/Editor/Inspectors/AttributedEnumInspector.cs.meta b/Editor/Inspectors/AttributedEnumInspector.cs.meta new file mode 100644 index 0000000..7e911e0 --- /dev/null +++ b/Editor/Inspectors/AttributedEnumInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c60df3d32f18d4d3e9019e2592b52ba9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Inspectors/CompareTypeInspector.cs b/Editor/Inspectors/CompareTypeInspector.cs index 0a8a443..8ed9e76 100644 --- a/Editor/Inspectors/CompareTypeInspector.cs +++ b/Editor/Inspectors/CompareTypeInspector.cs @@ -14,95 +14,15 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Reflection; using Unity.VisualScripting; -using UnityEditor; -using UnityEngine; namespace VisualPinball.Unity.VisualScripting.Editor { [Inspector(typeof(CompareType))] - public class CompareTypeInspector : Inspector + public class CompareTypeInspector : AttributedEnumInspector { - private List CompareTypes = Enum.GetValues(typeof(CompareType)).Cast().ToList(); - private string[] CompareTypeDescriptions = Enum.GetValues(typeof(CompareType)).Cast().Select(x => GetEnumDescription(x)).ToArray(); - - public CompareTypeInspector(Metadata metadata) : base(metadata) { - } - - public override void Initialize() - { - metadata.instantiate = true; - - base.Initialize(); - } - - protected override float GetHeight(float width, GUIContent label) - { - return HeightWithLabel(metadata, width, EditorGUIUtility.singleLineHeight, label); - } - - protected override void OnGUI(Rect position, GUIContent label) - { - position = BeginLabeledBlock(metadata, position, label); - - var fieldPosition = new Rect - ( - position.x, - position.y, - position.width, - EditorGUIUtility.singleLineHeight - ); - - var index = CompareTypes.FindIndex(c => c == (CompareType)metadata.value); - var newIndex = EditorGUI.Popup(fieldPosition, index, CompareTypeDescriptions); - - if (EndBlock(metadata)) - { - metadata.RecordUndo(); - metadata.value = CompareTypes[newIndex]; - } - } - - public override float GetAdaptiveWidth() + public CompareTypeInspector(Metadata metadata) : base(metadata) { - return Mathf.Max(18, EditorStyles.popup.CalcSize(new GUIContent(GetEnumDescription((CompareType)metadata.value))).x + Styles.popup.fixedWidth); - } - - private static string GetEnumDescription(Enum value) - { - FieldInfo field = value.GetType().GetField(value.ToString()); - - DescriptionAttribute attribute - = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) - as DescriptionAttribute; - - return (attribute == null ? value.ToString() : attribute.Description).Replace('/', '\u2215'); } } - - public static class Styles - { - static Styles() - { - popup = new GUIStyle("TextFieldDropDown"); - popup.fixedWidth = 10; - popup.clipping = TextClipping.Clip; - popup.normal.textColor = ColorPalette.transparent; - popup.active.textColor = ColorPalette.transparent; - popup.hover.textColor = ColorPalette.transparent; - popup.focused.textColor = ColorPalette.transparent; - popup.onNormal.textColor = ColorPalette.transparent; - popup.onActive.textColor = ColorPalette.transparent; - popup.onHover.textColor = ColorPalette.transparent; - popup.onFocused.textColor = ColorPalette.transparent; - } - - public static readonly GUIStyle textField; - public static readonly GUIStyle popup; - } -} +} \ No newline at end of file diff --git a/Editor/Inspectors/LampDataTypeInspector.cs b/Editor/Inspectors/LampDataTypeInspector.cs new file mode 100644 index 0000000..cb8eb6d --- /dev/null +++ b/Editor/Inspectors/LampDataTypeInspector.cs @@ -0,0 +1,28 @@ +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using Unity.VisualScripting; + +namespace VisualPinball.Unity.VisualScripting.Editor +{ + [Inspector(typeof(LampDataType))] + public class LampDataTypeInspector : AttributedEnumInspector + { + public LampDataTypeInspector(Metadata metadata) : base(metadata) + { + } + } +} \ No newline at end of file diff --git a/Editor/Inspectors/LampDataTypeInspector.cs.meta b/Editor/Inspectors/LampDataTypeInspector.cs.meta new file mode 100644 index 0000000..e905d54 --- /dev/null +++ b/Editor/Inspectors/LampDataTypeInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3c891d4e51ab4d26aec2424438cc7d8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Nodes/Lamps/LampDataType.cs b/Runtime/Nodes/Lamps/LampDataType.cs index b58a93a..7bdf6cf 100644 --- a/Runtime/Nodes/Lamps/LampDataType.cs +++ b/Runtime/Nodes/Lamps/LampDataType.cs @@ -1,23 +1,30 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.ComponentModel; + namespace VisualPinball.Unity.VisualScripting { public enum LampDataType - { - OnOff, Status, Intensity, Color, + { + [Description("On/Off")] + OnOff, + + Status, + Intensity, + Color, } } From 2ea4adf650a4022564fb3062de9e9e8d35d5d8e8 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Thu, 7 Jul 2022 06:54:29 -0400 Subject: [PATCH 4/4] cleanup: fix spacing --- Editor/Inspectors/AttributedEnumInspector.cs | 93 +++++++++----------- Editor/Inspectors/CompareTypeInspector.cs | 16 ++-- Editor/Inspectors/LampDataTypeInspector.cs | 16 ++-- Runtime/Nodes/Lamps/LampDataType.cs | 38 ++++---- Runtime/Nodes/Lamps/SwitchLampUnit.cs | 3 +- Runtime/Nodes/Logic/CompareType.cs | 62 ++++++------- 6 files changed, 111 insertions(+), 117 deletions(-) diff --git a/Editor/Inspectors/AttributedEnumInspector.cs b/Editor/Inspectors/AttributedEnumInspector.cs index 8463bb7..0f095b4 100644 --- a/Editor/Inspectors/AttributedEnumInspector.cs +++ b/Editor/Inspectors/AttributedEnumInspector.cs @@ -25,65 +25,60 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - public abstract class AttributedEnumInspector : Inspector - { - private List Enums; - private string[] EnumDescriptions; + public abstract class AttributedEnumInspector : Inspector + { + private List Enums; + private string[] EnumDescriptions; - public AttributedEnumInspector(Metadata metadata) : base(metadata) { - } + public AttributedEnumInspector(Metadata metadata) : base(metadata) { + } - public override void Initialize() - { - Enums = Enum.GetValues(typeof(TEnum)).Cast().ToList(); - EnumDescriptions = Enum.GetValues(typeof(TEnum)).Cast().Select(x => GetEnumDescription(x)).ToArray(); + public override void Initialize() + { + Enums = Enum.GetValues(typeof(TEnum)).Cast().ToList(); + EnumDescriptions = Enum.GetValues(typeof(TEnum)).Cast().Select(x => GetEnumDescription(x)).ToArray(); - metadata.instantiate = true; + metadata.instantiate = true; - base.Initialize(); - } + base.Initialize(); + } - protected override float GetHeight(float width, GUIContent label) - { - return HeightWithLabel(metadata, width, EditorGUIUtility.singleLineHeight, label); - } + protected override float GetHeight(float width, GUIContent label) + { + return HeightWithLabel(metadata, width, EditorGUIUtility.singleLineHeight, label); + } - protected override void OnGUI(Rect position, GUIContent label) - { - position = BeginLabeledBlock(metadata, position, label); + protected override void OnGUI(Rect position, GUIContent label) + { + position = BeginLabeledBlock(metadata, position, label); - var fieldPosition = new Rect - ( - position.x, - position.y, - position.width, - EditorGUIUtility.singleLineHeight - ); + var fieldPosition = new Rect( + position.x, + position.y, + position.width, + EditorGUIUtility.singleLineHeight); - var index = Enums.FindIndex(c => c.Equals(metadata.value)); - var newIndex = EditorGUI.Popup(fieldPosition, index, EnumDescriptions); + var index = Enums.FindIndex(c => c.Equals(metadata.value)); + var newIndex = EditorGUI.Popup(fieldPosition, index, EnumDescriptions); - if (EndBlock(metadata)) - { - metadata.RecordUndo(); - metadata.value = Enums[newIndex]; - } - } + if (EndBlock(metadata)) { + metadata.RecordUndo(); + metadata.value = Enums[newIndex]; + } + } - public override float GetAdaptiveWidth() - { - return Mathf.Max(18, EditorStyles.popup.CalcSize(new GUIContent(GetEnumDescription((TEnum)metadata.value))).x); - } + public override float GetAdaptiveWidth() + { + return Mathf.Max(18, EditorStyles.popup.CalcSize(new GUIContent(GetEnumDescription((TEnum)metadata.value))).x); + } - private string GetEnumDescription(TEnum value) - { - FieldInfo field = value.GetType().GetField(value.ToString()); + private string GetEnumDescription(TEnum value) + { + FieldInfo field = value.GetType().GetField(value.ToString()); - DescriptionAttribute attribute - = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) - as DescriptionAttribute; + DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute; - return (attribute == null ? value.ToString() : attribute.Description).Replace('/', '\u2215'); - } - } -} \ No newline at end of file + return (attribute == null ? value.ToString() : attribute.Description).Replace('/', '\u2215'); + } + } +} diff --git a/Editor/Inspectors/CompareTypeInspector.cs b/Editor/Inspectors/CompareTypeInspector.cs index 8ed9e76..0c51dba 100644 --- a/Editor/Inspectors/CompareTypeInspector.cs +++ b/Editor/Inspectors/CompareTypeInspector.cs @@ -18,11 +18,11 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - [Inspector(typeof(CompareType))] - public class CompareTypeInspector : AttributedEnumInspector - { - public CompareTypeInspector(Metadata metadata) : base(metadata) - { - } - } -} \ No newline at end of file + [Inspector(typeof(CompareType))] + public class CompareTypeInspector : AttributedEnumInspector + { + public CompareTypeInspector(Metadata metadata) : base(metadata) + { + } + } +} diff --git a/Editor/Inspectors/LampDataTypeInspector.cs b/Editor/Inspectors/LampDataTypeInspector.cs index cb8eb6d..0a7354f 100644 --- a/Editor/Inspectors/LampDataTypeInspector.cs +++ b/Editor/Inspectors/LampDataTypeInspector.cs @@ -18,11 +18,11 @@ namespace VisualPinball.Unity.VisualScripting.Editor { - [Inspector(typeof(LampDataType))] - public class LampDataTypeInspector : AttributedEnumInspector - { - public LampDataTypeInspector(Metadata metadata) : base(metadata) - { - } - } -} \ No newline at end of file + [Inspector(typeof(LampDataType))] + public class LampDataTypeInspector : AttributedEnumInspector + { + public LampDataTypeInspector(Metadata metadata) : base(metadata) + { + } + } +} diff --git a/Runtime/Nodes/Lamps/LampDataType.cs b/Runtime/Nodes/Lamps/LampDataType.cs index 7bdf6cf..2349f6e 100644 --- a/Runtime/Nodes/Lamps/LampDataType.cs +++ b/Runtime/Nodes/Lamps/LampDataType.cs @@ -1,25 +1,25 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System.ComponentModel; - +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.ComponentModel; + namespace VisualPinball.Unity.VisualScripting { public enum LampDataType - { + { [Description("On/Off")] OnOff, diff --git a/Runtime/Nodes/Lamps/SwitchLampUnit.cs b/Runtime/Nodes/Lamps/SwitchLampUnit.cs index 740b6f6..d00d49c 100644 --- a/Runtime/Nodes/Lamps/SwitchLampUnit.cs +++ b/Runtime/Nodes/Lamps/SwitchLampUnit.cs @@ -139,8 +139,7 @@ private ControlOutput Process(Flow flow) var match = false; - switch(ValueCompareType) - { + switch(ValueCompareType) { case CompareType.NotEqual: match = lampIdValue.value != sourceValue; break; diff --git a/Runtime/Nodes/Logic/CompareType.cs b/Runtime/Nodes/Logic/CompareType.cs index 605b2d3..3d74a33 100644 --- a/Runtime/Nodes/Logic/CompareType.cs +++ b/Runtime/Nodes/Logic/CompareType.cs @@ -1,41 +1,41 @@ -// Visual Pinball Engine -// Copyright (C) 2022 freezy and VPE Team -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -using System.ComponentModel; - +// Visual Pinball Engine +// Copyright (C) 2022 freezy and VPE Team +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.ComponentModel; + namespace VisualPinball.Unity.VisualScripting { public enum CompareType { - [Description("=")] - Equal, + [Description("=")] + Equal, - [Description("\u2260")] - NotEqual, + [Description("\u2260")] + NotEqual, - [Description("<")] - LessThan, + [Description("<")] + LessThan, - [Description("\u2264")] - LessThanEqual, + [Description("\u2264")] + LessThanEqual, - [Description(">")] - GreaterThan, + [Description(">")] + GreaterThan, - [Description("\u2265")] - GreaterThanEqual - } + [Description("\u2265")] + GreaterThanEqual + } }