diff --git a/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs b/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs new file mode 100644 index 00000000..723cdfa0 --- /dev/null +++ b/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs @@ -0,0 +1,22 @@ +using Unity.VisualScripting; +using Unity.VisualScripting.Community; +using UnityEditor; +using UnityEngine; + +[Descriptor(typeof(Arrow))] +public class ArrowDescriptor : UnitDescriptor +{ + public ArrowDescriptor(Arrow target) : base(target) + { + } + protected override EditorTexture DefinedIcon() + { + string iconFullPath = "Packages/dev.bolt.addons/Editor/Fundamentals/Resources/ArrowIcon.png"; + Texture2D icon = AssetDatabase.LoadAssetAtPath(iconFullPath); + return EditorTexture.Single(icon); + } + protected override string DefinedSummary() + { + return base.DefinedSummary(); + } +} diff --git a/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs.meta b/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs.meta new file mode 100644 index 00000000..74ed21a9 --- /dev/null +++ b/Editor/Fundamentals/Descriptors/ArrowDescriptor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c18fb52e291c3854f9eba6e4fbc4bd13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Fundamentals/Inspectors/ArrowInspector.cs b/Editor/Fundamentals/Inspectors/ArrowInspector.cs new file mode 100644 index 00000000..c4294d33 --- /dev/null +++ b/Editor/Fundamentals/Inspectors/ArrowInspector.cs @@ -0,0 +1,125 @@ +using UnityEditor; +using UnityEngine; + +namespace Unity.VisualScripting.Community +{ + [Inspector(typeof(Arrow))] + public class ArrowInspector : Inspector + { + private GUIStyle headerStyle; + private GUIStyle largeButtonStyle; + private Color backgroundColor = new Color(0.3f, 0.3f, 0.3f); + + public ArrowInspector(Metadata metadata) : base(metadata) + { + headerStyle = new GUIStyle(EditorStyles.boldLabel); + headerStyle.alignment = TextAnchor.MiddleCenter; + headerStyle.fontSize = 14; + + largeButtonStyle = new GUIStyle(GUI.skin.button); + largeButtonStyle.fontSize = 18; + largeButtonStyle.alignment = TextAnchor.MiddleCenter; + } + + protected override float GetHeight(float width, GUIContent label) + { + // Height for one line of properties (line color, length, rotationAngle, Text, ShowSquare, ShowBottomArrow, LineType) + return EditorGUIUtility.singleLineHeight * 18f; + } + + protected override void OnGUI(Rect position, GUIContent label) + { + // Draw the header + Rect headerRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight * 2); + GUI.Label(headerRect, "Arrow Inspector", headerStyle); + + position.y += headerRect.height; + position.height -= headerRect.height; + + position = BeginLabeledBlock(metadata, position, GUIContent.none); + + Arrow arrow = (Arrow)metadata.value; + + // Draw the Arrow Color property field + Rect arrowColorRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight); + arrow.ArrowColor = EditorGUI.ColorField(arrowColorRect, new GUIContent("Arrow Color"), arrow.ArrowColor); + + // Draw the Line Color property field + Rect lineColorRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 2.5f, position.width, EditorGUIUtility.singleLineHeight); + arrow.Color = EditorGUI.ColorField(lineColorRect, new GUIContent("Line Color"), arrow.Color); + + // Draw the Length property field + Rect lengthRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 4f, position.width, EditorGUIUtility.singleLineHeight); + arrow.Length = EditorGUI.FloatField(lengthRect, new GUIContent("Length"), arrow.Length); + + // Draw the Rotation Angle property field + Rect rotationRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 5.5f, position.width, EditorGUIUtility.singleLineHeight); + EditorGUI.BeginChangeCheck(); + float newRotationAngle = EditorGUI.FloatField(rotationRect, new GUIContent("Rotation Angle"), arrow.rotationAngle); + if (EditorGUI.EndChangeCheck()) + { + metadata.RecordUndo(); + arrow.rotationAngle = Mathf.Repeat(newRotationAngle, 360f); + } + + // Draw the Text property field + Rect textRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 7f, position.width, EditorGUIUtility.singleLineHeight); + arrow.Text = EditorGUI.TextField(textRect, new GUIContent("Text"), arrow.Text); + + // Draw the ShowSquare property field + Rect showSquareRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 8.5f, position.width, EditorGUIUtility.singleLineHeight); + arrow.ShowSquare = EditorGUI.Toggle(showSquareRect, new GUIContent("Show Point"), arrow.ShowSquare); + + // Draw the ShowBottomArrow property field + Rect showBottomArrowRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 10f, position.width, EditorGUIUtility.singleLineHeight); + arrow.ShowBottomArrow = EditorGUI.Toggle(showBottomArrowRect, new GUIContent("Show Bottom Arrow"), arrow.ShowBottomArrow); + + // Draw the ShowTopArrow property field + Rect showTopArrowRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 11.5f, position.width, EditorGUIUtility.singleLineHeight); + arrow.ShowTopArrow = EditorGUI.Toggle(showTopArrowRect, new GUIContent("Show Top Arrow"), arrow.ShowTopArrow); + + // Custom drawer for rotation angle buttons + Rect buttonsRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 13f, position.width, EditorGUIUtility.singleLineHeight); + DrawRotationButtons(buttonsRect, arrow); + + // Draw the LineType property field + Rect LineTypeRect = new Rect(position.x, position.y + EditorGUIUtility.singleLineHeight * 14.5f, position.width, EditorGUIUtility.singleLineHeight); + arrow.lineType = (LineType)EditorGUI.EnumPopup(LineTypeRect, new GUIContent("Line Type"), arrow.lineType); + + if (EndBlock(metadata)) + { + metadata.RecordUndo(); + } + } + + private void DrawRotationButtons(Rect position, Arrow arrow) + { + float buttonWidth = position.width / 3f; + Rect buttonRect = new Rect(position.x, position.y, buttonWidth, position.height); + + if (GUI.Button(buttonRect, "<--")) + { + metadata.RecordUndo(); + arrow.rotationAngle -= 15f; + arrow.rotationAngle = Mathf.Repeat(arrow.rotationAngle, 360f); + } + + buttonRect.x += buttonWidth; + + if (GUI.Button(buttonRect, "Reset")) + { + metadata.RecordUndo(); + arrow.rotationAngle = 0f; + } + + buttonRect.x += buttonWidth; + + if (GUI.Button(buttonRect, "-->")) + { + metadata.RecordUndo(); + arrow.rotationAngle += 15f; + arrow.rotationAngle = Mathf.Repeat(arrow.rotationAngle, 360f); + } + } + } +} diff --git a/Editor/Fundamentals/Inspectors/ArrowInspector.cs.meta b/Editor/Fundamentals/Inspectors/ArrowInspector.cs.meta new file mode 100644 index 00000000..004c9f33 --- /dev/null +++ b/Editor/Fundamentals/Inspectors/ArrowInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1f0dd58f1f0f9545a1ac50af0ffde58 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Fundamentals/Inspectors/HDRColorInspector.cs b/Editor/Fundamentals/Inspectors/HDRColorInspector.cs new file mode 100644 index 00000000..eb0f8bd8 --- /dev/null +++ b/Editor/Fundamentals/Inspectors/HDRColorInspector.cs @@ -0,0 +1,34 @@ +using UnityEditor; +using UnityEngine; + +namespace Unity.VisualScripting +{ + [Inspector(typeof(HDRColor))] // Update this to use HDRColor instead of Color + public class HDRColorInspector : Inspector + { + public HDRColorInspector(Metadata metadata) : base(metadata) { } + + protected override float GetHeight(float width, GUIContent label) + { + return EditorGUIUtility.singleLineHeight; + } + + protected override void OnGUI(Rect position, GUIContent label) + { + position = BeginLabeledBlock(metadata, position, label); + + // Retrieve the color value from the HDRColor struct + HDRColor hdrColor = (HDRColor)metadata.value; + var newValue = EditorGUI.ColorField(position, new(), hdrColor.color, true, true, true); + + if (EndBlock(metadata)) + { + metadata.RecordUndo(); + + // Update the color value in the HDRColor struct + hdrColor.color = newValue; + metadata.value = hdrColor; + } + } + } +} diff --git a/Editor/Fundamentals/Inspectors/HDRColorInspector.cs.meta b/Editor/Fundamentals/Inspectors/HDRColorInspector.cs.meta new file mode 100644 index 00000000..cd9e3992 --- /dev/null +++ b/Editor/Fundamentals/Inspectors/HDRColorInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d9cece0e822fdf941aae315c1fedff74 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Fundamentals/Resources/ArrowIcon.png b/Editor/Fundamentals/Resources/ArrowIcon.png new file mode 100644 index 00000000..8f02c16a Binary files /dev/null and b/Editor/Fundamentals/Resources/ArrowIcon.png differ diff --git a/Editor/Fundamentals/Resources/ArrowIcon.png.meta b/Editor/Fundamentals/Resources/ArrowIcon.png.meta new file mode 100644 index 00000000..17d3c8df --- /dev/null +++ b/Editor/Fundamentals/Resources/ArrowIcon.png.meta @@ -0,0 +1,124 @@ +fileFormatVersion: 2 +guid: 76c27eb048e23e540b85e1c91a2195d7 +TextureImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 1 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Server + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: 5e97eb03825dee720800000000000000 + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Fundamentals/Widgets/ArrowWidget.cs b/Editor/Fundamentals/Widgets/ArrowWidget.cs new file mode 100644 index 00000000..f47b1ce6 --- /dev/null +++ b/Editor/Fundamentals/Widgets/ArrowWidget.cs @@ -0,0 +1,140 @@ +using UnityEditor; +using UnityEngine; + +namespace Unity.VisualScripting.Community +{ + [Widget(typeof(Arrow))] + public class DividerNode : UnitWidget + { + private const float arrowWidth = 10f; + private const float arrowHeight = 10f; + private const float lineWidth = 5f; // Adjust this value to control the line width + private const float DottedLineWidths = 4f; + private const float unitSquareSize = 4f; // Adjust this value to control the size of the unit square + + public DividerNode(FlowCanvas canvas, Arrow unit) : base(canvas, unit) + { + } + + public override void DrawForeground() + { + + // Find the center of the unit + Vector3 unitCenter = new Vector3(position.x + position.width / 2f, position.y + position.height / 2f); + + // Calculate the line's start and end points based on the unit's center and size + float halfWidth = position.width / 2f; + float halfHeight = position.height / 2f; + float lineHalfWidth = halfWidth - unitSquareSize / 2f; + + // Get the line length from the unit's Length property + float lineLength = Mathf.Max(unit.Length, 0f); + + // Calculate the rotation angle in radians + float rotationAngleRad = unit.rotationAngle * Mathf.Deg2Rad; + + Vector3 lineStart = unitCenter + Quaternion.Euler(0f, 0f, unit.rotationAngle) * new Vector3(-lineHalfWidth, 0f, 0f); + Vector3 lineEnd = unitCenter + Quaternion.Euler(0f, 0f, unit.rotationAngle) * new Vector3(lineHalfWidth + lineLength, 0f, 0f); + + // Draw the line with rotation based on unit.rotationAngle + Handles.color = unit.Color; + + // Check the line type and draw the appropriate line + switch (unit.lineType) + { + case LineType.Normal: + Handles.DrawAAPolyLine(lineWidth, lineStart, lineEnd); + break; + case LineType.Dotted: + DrawDottedLine(lineStart, lineEnd, DottedLineWidths); + break; + } + + // Draw arrows at the start and end of the line + Vector3 arrowTipStart = lineStart - (lineEnd - lineStart).normalized * arrowHeight; + Vector3 arrowTipEnd = lineEnd + (lineEnd - lineStart).normalized * arrowHeight; + + if(unit.ShowTopArrow) DrawArrow(arrowTipStart, lineStart, unit.ArrowColor); + + if (unit.ShowBottomArrow) DrawArrow(arrowTipEnd, lineEnd, unit.ArrowColor); + + // Draw the square at the unit's position + if (unit.ShowSquare) + { + DrawUnitPosition(unitCenter); + } + + // Draw the text field in the middle of the line + DrawTextField((lineStart + lineEnd) / 2f, unit.Text); + + SendToBack(); + } + + private void DrawArrow(Vector3 arrowTip, Vector3 arrowBase, Color arrowColor) + { + Vector3 arrowDirection = (arrowBase - arrowTip).normalized; + Vector3 arrowSide = Quaternion.Euler(0f, 0f, 30f) * arrowDirection; + Vector3 arrowSide2 = Quaternion.Euler(0f, 0f, -30f) * arrowDirection; + + Vector3[] arrowPoints = new Vector3[] + { + arrowTip, + arrowTip + arrowSide * arrowWidth, + arrowTip + arrowSide2 * arrowWidth + }; + + Handles.color = arrowColor; + Handles.DrawAAConvexPolygon(arrowPoints); + } + + private void DrawUnitPosition(Vector3 unitCenter) + { + // Calculate the half-size of the unit square + float halfSize = unitSquareSize / 2f; + + // Draw the square at the unit's position + if (!isMouseOver) + { + Handles.color = Color.white; + } + else + { + Handles.color = Color.black; + } + Handles.DrawAAConvexPolygon( + unitCenter + new Vector3(-halfSize, -halfSize, 0f), + unitCenter + new Vector3(-halfSize, halfSize, 0f), + unitCenter + new Vector3(halfSize, halfSize, 0f), + unitCenter + new Vector3(halfSize, -halfSize, 0f) + ); + } + + private void DrawTextField(Vector3 position, string text) + { + // Define the style for the text label + GUIStyle style = new GUIStyle(GUI.skin.label); + style.alignment = TextAnchor.MiddleCenter; + + // Convert world position to screen space + Vector2 screenPos = HandleUtility.WorldToGUIPoint(position); + + // Calculate the size of the label based on the text length + GUIContent content = new GUIContent(text); + Vector2 textSize = style.CalcSize(content); + + // Calculate the position for the label in screen space + Rect labelRect = new Rect(screenPos.x - textSize.x / 2f, screenPos.y - textSize.y / 2f, textSize.x, textSize.y); + + // Draw the text label at the calculated position + Handles.BeginGUI(); + GUI.Label(labelRect, content, style); + Handles.EndGUI(); + } + + private void DrawDottedLine(Vector3 start, Vector3 end, float width) + { + // Draw the dotted line using Handles.DrawDottedLine + Handles.DrawDottedLine(start, end, width); + } + } +} diff --git a/Editor/Fundamentals/Widgets/ArrowWidget.cs.meta b/Editor/Fundamentals/Widgets/ArrowWidget.cs.meta new file mode 100644 index 00000000..bb254e56 --- /dev/null +++ b/Editor/Fundamentals/Widgets/ArrowWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c15b92eb34b271d46baa4ee876c584ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Fundamentals/Widgets/LogNodeWidget.cs b/Editor/Fundamentals/Widgets/LogNodeWidget.cs new file mode 100644 index 00000000..d6635a6f --- /dev/null +++ b/Editor/Fundamentals/Widgets/LogNodeWidget.cs @@ -0,0 +1,27 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using Unity.VisualScripting.Community; +using UnityEngine; + +[Widget(typeof(LogNode))] +public class LogNodeWidget : UnitWidget +{ + public LogNodeWidget(FlowCanvas canvas, LogNode unit) : base(canvas, unit) + { + } + + protected override NodeColorMix baseColor + { + get + { + switch (unit.type) + { + case Unity.VisualScripting.Community.LogType.Log: return NodeColor.Gray; + case Unity.VisualScripting.Community.LogType.Warning: return NodeColor.Orange; + case Unity.VisualScripting.Community.LogType.Error: return NodeColor.Red; + default: return NodeColor.Gray; + } + } + } +} diff --git a/Editor/Fundamentals/Widgets/LogNodeWidget.cs.meta b/Editor/Fundamentals/Widgets/LogNodeWidget.cs.meta new file mode 100644 index 00000000..28721a16 --- /dev/null +++ b/Editor/Fundamentals/Widgets/LogNodeWidget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f6e54f274ca779f4684a497f738637d1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Code/HDRColor.cs b/Runtime/Code/HDRColor.cs new file mode 100644 index 00000000..b40faafe --- /dev/null +++ b/Runtime/Code/HDRColor.cs @@ -0,0 +1,15 @@ +using System.Collections; +using System.Collections.Generic; +using Unity.VisualScripting; +using UnityEngine; + +[System.Serializable] +[TypeIcon(typeof(Color))] +[IncludeInSettings(true)] +[Inspectable] +public struct HDRColor +{ + [Inspectable] + [ColorUsage(true, true)] + public Color color; +} diff --git a/Runtime/Code/HDRColor.cs.meta b/Runtime/Code/HDRColor.cs.meta new file mode 100644 index 00000000..e5b64d3e --- /dev/null +++ b/Runtime/Code/HDRColor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1086b8ca6d95948479e73d9c5948d98f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Events/Nodes/OnRetrieved.cs b/Runtime/Events/Nodes/OnRetrieved.cs new file mode 100644 index 00000000..4398e1cf --- /dev/null +++ b/Runtime/Events/Nodes/OnRetrieved.cs @@ -0,0 +1,41 @@ +using Unity.VisualScripting; +using UnityEngine; + +namespace Bolt.Addons.Community.Fundamentals.ObjectPooling +{ + [UnitCategory("Events/Community/ObjectPooling")] + public class OnRetrieved : EventUnit + { + protected override bool register => true; + + [DoNotSerialize] + [PortLabelHidden] + public ValueInput Pool; + + [DoNotSerialize] + public ValueOutput Result; + + public override EventHook GetHook(GraphReference reference) + { + return ObjectPoolEvents.OnRetrieved; + } + + protected override void Definition() + { + base.Definition(); + + Pool = ValueInput(nameof(Pool), default); + Result = ValueOutput(nameof(Result)); + } + + protected override bool ShouldTrigger(Flow flow, PoolData args) + { + if (args.pool == flow.GetValue(Pool)) + { + flow.SetValue(Result, args.arg); + return true; + } + return false; + } + } +} diff --git a/Runtime/Events/Nodes/OnRetrieved.cs.meta b/Runtime/Events/Nodes/OnRetrieved.cs.meta new file mode 100644 index 00000000..9bbe882d --- /dev/null +++ b/Runtime/Events/Nodes/OnRetrieved.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e2b2a2f90cb279d48915ce5a0727a8d1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Events/Nodes/OnReturned.cs b/Runtime/Events/Nodes/OnReturned.cs new file mode 100644 index 00000000..9dbd3d67 --- /dev/null +++ b/Runtime/Events/Nodes/OnReturned.cs @@ -0,0 +1,43 @@ +using Unity.VisualScripting; +using Unity.VisualScripting.Community.Libraries.Humility; +using UnityEngine; + +namespace Bolt.Addons.Community.Fundamentals.ObjectPooling +{ + [UnitCategory("Events/Community/ObjectPooling")] + [UnitTitle("OnReturned")] + public class OnReturned : EventUnit + { + protected override bool register => true; + + [DoNotSerialize] + [PortLabelHidden] + public ValueInput Pool; + + [DoNotSerialize] + public ValueOutput Result; + + public override EventHook GetHook(GraphReference reference) + { + return ObjectPoolEvents.OnReturned; + } + + protected override void Definition() + { + base.Definition(); + + Pool = ValueInput(nameof(Pool), default); + Result = ValueOutput(nameof(Result)); + } + + protected override bool ShouldTrigger(Flow flow, PoolData args) + { + if (args.pool == flow.GetValue(Pool)) + { + flow.SetValue(Result, args.arg); + return true; + } + return false; + } + } +} \ No newline at end of file diff --git a/Runtime/Events/Nodes/OnReturned.cs.meta b/Runtime/Events/Nodes/OnReturned.cs.meta new file mode 100644 index 00000000..c464b338 --- /dev/null +++ b/Runtime/Events/Nodes/OnReturned.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 74596d8d70722f44b8d04d8f26c6abf4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs b/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs new file mode 100644 index 00000000..1a6bd3d6 --- /dev/null +++ b/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs @@ -0,0 +1,45 @@ +using UnityEngine; + +namespace Unity.VisualScripting.Community +{ + [UnitCategory("Community\\Documentation")] + [UnitTitle("Arrow")] + public class Arrow : Unit + { + // This node has no functionality; it's just a Arrow. + [Inspectable] + public float Length = 20f; + + [Inspectable] + public float rotationAngle = 0f; + + [Inspectable] + public Color Color = Color.red; + + [Inspectable] + public Color ArrowColor = Color.red; + + [Inspectable] + public string Text; + + public bool ShowSquare = true; + + public bool ShowBottomArrow = true; + + public bool ShowTopArrow = true; + + public LineType lineType = LineType.Normal; + + public override bool isControlRoot { get { return true; } } + protected override void Definition() + { + } + } +} + + +public enum LineType +{ + Normal, + Dotted +} diff --git a/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs.meta b/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs.meta new file mode 100644 index 00000000..d49928e6 --- /dev/null +++ b/Runtime/Fundamentals/Nodes/Documenting/Arrow.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2c4788bcdcfb4d4199cde0b10fb2ec9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Fundamentals/Nodes/Logic/LogNode.cs b/Runtime/Fundamentals/Nodes/Logic/LogNode.cs index 083e7c22..0d5f07dc 100644 --- a/Runtime/Fundamentals/Nodes/Logic/LogNode.cs +++ b/Runtime/Fundamentals/Nodes/Logic/LogNode.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -50,6 +50,9 @@ public int argumentCount } } + [UnitHeaderInspectable("LogType")] + public LogType type; + protected override void Definition() { format = ValueInput(nameof(format), ""); @@ -90,8 +93,23 @@ private ControlOutput Log(Flow flow) return val.ToString(); }); - Debug.Log(string.Format(flow.GetValue(format), stringArgs.ToArray())); + switch (type) + { + case LogType.Log: Debug.Log(string.Format(flow.GetValue(format), stringArgs.ToArray())); + break; + case LogType.Warning: Debug.LogWarning(string.Format(flow.GetValue(format), stringArgs.ToArray())); + break; + case LogType.Error: Debug.LogError(string.Format(flow.GetValue(format), stringArgs.ToArray())); + break; + } return output; } } -} \ No newline at end of file + + public enum LogType + { + Log, + Warning, + Error, + } +} diff --git a/Runtime/Fundamentals/Nodes/Object Pooling/C#/CustomObjectPool.cs b/Runtime/Fundamentals/Nodes/Object Pooling/C#/CustomObjectPool.cs index c389445f..14ba799c 100644 --- a/Runtime/Fundamentals/Nodes/Object Pooling/C#/CustomObjectPool.cs +++ b/Runtime/Fundamentals/Nodes/Object Pooling/C#/CustomObjectPool.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using UnityEngine; +using Unity.VisualScripting; public class CustomObjectPool : MonoBehaviour { @@ -39,6 +40,8 @@ public GameObject RetrieveObjectFromPool() // Keep track of active objects activeObjects.Add(obj); + EventBus.Trigger(ObjectPoolEvents.OnRetrieved, new(this, obj)); + return obj; } @@ -49,6 +52,8 @@ public void ReturnObjectToPool(GameObject obj) // Remove from active objects and add back to the queue activeObjects.Remove(obj); objectPoolQueue.Enqueue(obj); + + EventBus.Trigger(ObjectPoolEvents.OnReturned, new(this, obj)); } public List GetActiveObjects() @@ -56,3 +61,21 @@ public List GetActiveObjects() return activeObjects; } } + +public static class ObjectPoolEvents +{ + public static string OnRetrieved = "Retrieved"; + public static string OnReturned = "Returned"; +} + +public struct PoolData +{ + public CustomObjectPool pool; + public GameObject arg; + + public PoolData(CustomObjectPool Pool, GameObject args) + { + pool = Pool; + arg = args; + } +}