From 74402a8a2a36ea3efe6f29d9b4559774b7b6835b Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sat, 20 Apr 2024 01:47:17 +0200 Subject: [PATCH] Support vertical min max linerenderer sample --- Assets/Prefabs/Towers/Turret.prefab | 12 +++++++++- Assets/Scripts/Utilities/EditableArc.cs | 29 +++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Assets/Prefabs/Towers/Turret.prefab b/Assets/Prefabs/Towers/Turret.prefab index 4b0af3e..3e4c832 100644 --- a/Assets/Prefabs/Towers/Turret.prefab +++ b/Assets/Prefabs/Towers/Turret.prefab @@ -13,6 +13,16 @@ PrefabInstance: propertyPath: m_Positions.Array.size value: 0 objectReference: {fileID: 0} + - target: {fileID: 639897978325975064, guid: c309e2ab8a7e17f049cee02d2d5e1af3, + type: 3} + propertyPath: m_Parameters.widthCurve.m_Curve.Array.data[0].value + value: 0.14800072 + objectReference: {fileID: 0} + - target: {fileID: 1425401315373935596, guid: c309e2ab8a7e17f049cee02d2d5e1af3, + type: 3} + propertyPath: orientation + value: 1 + objectReference: {fileID: 0} - target: {fileID: 4241178655744724118, guid: c309e2ab8a7e17f049cee02d2d5e1af3, type: 3} propertyPath: m_Name @@ -71,7 +81,7 @@ PrefabInstance: - target: {fileID: 7730797280345979287, guid: c309e2ab8a7e17f049cee02d2d5e1af3, type: 3} propertyPath: m_IsActive - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 8501533562697966838, guid: c309e2ab8a7e17f049cee02d2d5e1af3, type: 3} diff --git a/Assets/Scripts/Utilities/EditableArc.cs b/Assets/Scripts/Utilities/EditableArc.cs index 36e4742..5abcbc2 100644 --- a/Assets/Scripts/Utilities/EditableArc.cs +++ b/Assets/Scripts/Utilities/EditableArc.cs @@ -1,8 +1,15 @@ using UnityEngine; +public enum ArcOrientation +{ + HORIZONTAL, + VERTICAL, +} + [RequireComponent(typeof(LineRenderer))] public class EditableArc : MonoBehaviour { + [SerializeField] private ArcOrientation orientation = ArcOrientation.HORIZONTAL; [SerializeField, Range(5, 50)] private int samples = 15; [SerializeField] private float visualRadius = 1f; @@ -28,10 +35,28 @@ public class EditableArc : MonoBehaviour private void UpdateArc(float rotation) { + Vector3 normal; + Vector3 tangent; + + if (orientation == ArcOrientation.HORIZONTAL) + { + normal = transform.up; + tangent = transform.right; + } + else if (orientation == ArcOrientation.VERTICAL) + { + normal = transform.right; + tangent = transform.up; + } + else + { + throw new System.Exception("WTFFFFF HAVE YOU DONE YOU MF!!?"); + } + float angle = rotationMinMax.y - rotationMinMax.x; float v = (Mathf.PI - Value * Mathf.Deg2Rad) / 2f; - Vector3 start = Quaternion.AngleAxis(rotationMinMax.x, transform.up) * transform.right; - Vector3 end = Quaternion.AngleAxis(rotationMinMax.y, transform.up) * transform.right; + Vector3 start = Quaternion.AngleAxis(rotationMinMax.x, normal) * tangent; + Vector3 end = Quaternion.AngleAxis(rotationMinMax.y, normal) * tangent; // Sample LineRenderer points lineRenderer.positionCount = samples + 1;