From 1c37ac070ec6756d70d6b1c27947a07702c15114 Mon Sep 17 00:00:00 2001 From: Andrew Van Buren Date: Mon, 22 Feb 2021 21:33:24 -0500 Subject: [PATCH 1/3] Ignore .vsconfig --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 311251e..c38d5d7 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ ExportedObj/ *.pdb *.opendb *.VC.db +*.vsconfig # Unity3D generated meta files *.pidb.meta @@ -41,4 +42,4 @@ sysinfo.txt *.unitypackage # Crashlytics generated file -Assets/StreamingAssets/crashlytics-build.properties \ No newline at end of file +Assets/StreamingAssets/crashlytics-build.properties From fddd11d43c32f0bfe4117fc45c25c946577af429 Mon Sep 17 00:00:00 2001 From: Andrew Van Buren Date: Mon, 22 Feb 2021 21:46:04 -0500 Subject: [PATCH 2/3] Make SplineExtrusionEditor OnEnable protected and add properties for extrusion layer/visibility/collisionEnabled. --- .../Scripts/Editor/SplineExtrusionEditor.cs | 13 +++++++++++-- .../Scripts/MeshProcessing/SplineExtrusion.cs | 18 +++++++++++++++--- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Assets/SplineMesh/Scripts/Editor/SplineExtrusionEditor.cs b/Assets/SplineMesh/Scripts/Editor/SplineExtrusionEditor.cs index 7237354..b7355a3 100644 --- a/Assets/SplineMesh/Scripts/Editor/SplineExtrusionEditor.cs +++ b/Assets/SplineMesh/Scripts/Editor/SplineExtrusionEditor.cs @@ -1,4 +1,4 @@ -using UnityEngine; +using UnityEngine; using System.Collections; using UnityEditor; @@ -12,16 +12,22 @@ public class SplineExtrusionEditor : Editor { private SerializedProperty sampleSpacing; private SerializedProperty material; private SerializedProperty vertices; + private SerializedProperty layer; + private SerializedProperty visible; + private SerializedProperty collisionEnabled; private SplineExtrusion se; private ExtrusionSegment.Vertex selection = null; - private void OnEnable() { + protected void OnEnable() { se = (SplineExtrusion)target; textureScale = serializedObject.FindProperty("textureScale"); sampleSpacing = serializedObject.FindProperty("sampleSpacing"); material = serializedObject.FindProperty("material"); vertices = serializedObject.FindProperty("shapeVertices"); + layer = serializedObject.FindProperty("layer"); + visible = serializedObject.FindProperty("visible"); + collisionEnabled = serializedObject.FindProperty("collisionEnabled"); } void OnSceneGUI() { @@ -156,6 +162,9 @@ public override void OnInspectorGUI() { } } EditorGUI.indentLevel -= 1; + EditorGUILayout.PropertyField(layer, true); + EditorGUILayout.PropertyField(visible, true); + EditorGUILayout.PropertyField(collisionEnabled, true); serializedObject.ApplyModifiedProperties(); } diff --git a/Assets/SplineMesh/Scripts/MeshProcessing/SplineExtrusion.cs b/Assets/SplineMesh/Scripts/MeshProcessing/SplineExtrusion.cs index 71f19ff..ddb199f 100644 --- a/Assets/SplineMesh/Scripts/MeshProcessing/SplineExtrusion.cs +++ b/Assets/SplineMesh/Scripts/MeshProcessing/SplineExtrusion.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -32,6 +32,9 @@ public class SplineExtrusion : MonoBehaviour { public Material material; public float textureScale = 1; public float sampleSpacing = 0.1f; + public string layer; + public bool visible = true; + public bool collisionEnabled = true; /// /// Clear shape vertices, then create three vertices with three normals for the extrusion to be visible @@ -65,7 +68,7 @@ private void Update() { } } - private void GenerateMesh() { + protected void GenerateMesh() { UOUtility.DestroyChildren(generated); int i = 0; @@ -77,13 +80,22 @@ private void GenerateMesh() { typeof(MeshRenderer), typeof(ExtrusionSegment), typeof(MeshCollider)); - go.GetComponent().material = material; + MeshRenderer goRenderer = go.GetComponent(); + goRenderer.material = material; ExtrusionSegment seg = go.GetComponent(); seg.ShapeVertices = shapeVertices; seg.TextureScale = textureScale; seg.TextureOffset = textureOffset; seg.SampleSpacing = sampleSpacing; seg.SetInterval(curve); + goRenderer.enabled = visible; + if (go.TryGetComponent(out MeshCollider meshCollider)) { + meshCollider.enabled = collisionEnabled; + } + int layerNum = LayerMask.NameToLayer(layer); + if (layerNum > -1) { + go.gameObject.layer = layerNum; + } textureOffset += curve.Length; } From e60d6d56f85c2446957e77e5a1542618ae099e0f Mon Sep 17 00:00:00 2001 From: Andrew Van Buren Date: Mon, 22 Feb 2021 21:49:34 -0500 Subject: [PATCH 3/3] Expose index on Spline for lookup. --- Assets/SplineMesh/Scripts/Bezier/CurveSample.cs | 4 +++- Assets/SplineMesh/Scripts/Bezier/Spline.cs | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Assets/SplineMesh/Scripts/Bezier/CurveSample.cs b/Assets/SplineMesh/Scripts/Bezier/CurveSample.cs index 0ca5d8c..88c9a04 100644 --- a/Assets/SplineMesh/Scripts/Bezier/CurveSample.cs +++ b/Assets/SplineMesh/Scripts/Bezier/CurveSample.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -18,6 +18,7 @@ public struct CurveSample public readonly float distanceInCurve; public readonly float timeInCurve; public readonly CubicBezierCurve curve; + public int index; private Quaternion rotation; @@ -43,6 +44,7 @@ public CurveSample(Vector3 location, Vector3 tangent, Vector3 up, Vector2 scale, this.distanceInCurve = distanceInCurve; this.timeInCurve = timeInCurve; this.curve = curve; + index = -1; rotation = Quaternion.identity; } diff --git a/Assets/SplineMesh/Scripts/Bezier/Spline.cs b/Assets/SplineMesh/Scripts/Bezier/Spline.cs index f9991e8..0d1a93e 100644 --- a/Assets/SplineMesh/Scripts/Bezier/Spline.cs +++ b/Assets/SplineMesh/Scripts/Bezier/Spline.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -286,10 +286,12 @@ private void EndNodeChanged(object sender, EventArgs e) { public CurveSample GetProjectionSample(Vector3 pointToProject) { CurveSample closest = default(CurveSample); float minSqrDistance = float.MaxValue; - foreach (var curve in curves) { + for (int i = 0; i < curves.Count; i++) { + var curve = curves[i]; var projection = curve.GetProjectionSample(pointToProject); if (curve == curves[0]) { closest = projection; + closest.index = i; minSqrDistance = (projection.location - pointToProject).sqrMagnitude; continue; } @@ -297,6 +299,7 @@ public CurveSample GetProjectionSample(Vector3 pointToProject) { if (sqrDist < minSqrDistance) { minSqrDistance = sqrDist; closest = projection; + closest.index = i; } } return closest;