From 63ac2dfbd9aec591c3eec84b4f65666507468a84 Mon Sep 17 00:00:00 2001 From: originalnicodr Date: Sun, 10 Mar 2024 19:11:39 -0300 Subject: [PATCH] Added fallback arrows in case we cannot build the cone for the ones we build (was happening on Metall: Hellsinger and Road 96). --- src/Cinematic/ArrowGenerator.cs | 62 ++++++++++++++++++++++++++------- src/UI/Panels/CamPaths.cs | 9 ++--- src/UI/Panels/LightsManger.cs | 9 ++--- 3 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/Cinematic/ArrowGenerator.cs b/src/Cinematic/ArrowGenerator.cs index c7263df..7b47493 100644 --- a/src/Cinematic/ArrowGenerator.cs +++ b/src/Cinematic/ArrowGenerator.cs @@ -13,29 +13,65 @@ namespace UnityExplorer public class ArrowGenerator { public static GameObject CreateArrow(Vector3 arrowPosition, Quaternion arrowRotation, Color color){ + try { + GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder); + cylinder.GetComponent().enabled = false; + cylinder.GetComponent().mesh = CreateCylinderMesh(0.01f, 20, 2); + cylinder.transform.rotation = Quaternion.LookRotation(Vector3.down, Vector3.up); + Renderer rendCylinder = cylinder.GetComponent (); + rendCylinder.material = new Material(Shader.Find("Sprites/Default")); + rendCylinder.material.color = color; + + GameObject cone = GameObject.CreatePrimitive(PrimitiveType.Sphere); + cone.GetComponent().enabled = false; + cone.GetComponent().mesh = CreateConeMesh(10, 0.05f, 0.1f); + cone.transform.SetParent(cylinder.transform, true); + Renderer rendCone = cone.GetComponent(); + rendCone.material = new Material(Shader.Find("Sprites/Default")); + rendCone.material.color = color; + + cylinder.transform.rotation = Quaternion.LookRotation(Vector3.back, Vector3.up); + + GameObject arrow = new GameObject("CUE-Arrow"); + cylinder.transform.SetParent(arrow.transform, true); + arrow.transform.position = arrowPosition; + arrow.transform.rotation = arrowRotation; + arrow.transform.position += 0.5f * arrow.transform.forward; // Move the arrow forward so the cylinder starts on the wanted position + + return arrow; + } + catch { + return FallbackArrow(arrowPosition, arrowRotation, color); + } + } + + private static GameObject FallbackArrow(Vector3 arrowPosition, Quaternion arrowRotation, Color color){ GameObject cylinder = GameObject.CreatePrimitive(PrimitiveType.Cylinder); cylinder.GetComponent().enabled = false; - cylinder.GetComponent().mesh = CreateCylinderMesh(0.01f, 20, 2); - cylinder.transform.rotation = Quaternion.LookRotation(Vector3.down, Vector3.up); Renderer rendCylinder = cylinder.GetComponent (); rendCylinder.material = new Material(Shader.Find("Sprites/Default")); rendCylinder.material.color = color; + cylinder.transform.localScale = new Vector3(0.025f, 0.15f, 0.025f); - GameObject cone = GameObject.CreatePrimitive(PrimitiveType.Sphere); - cone.GetComponent().enabled = false; - cone.GetComponent().mesh = CreateConeMesh(10, 0.05f, 0.1f); - cone.transform.SetParent(cylinder.transform, true); - Renderer rendCone = cone.GetComponent(); - rendCone.material = new Material(Shader.Find("Sprites/Default")); - rendCone.material.color = color; - - cylinder.transform.rotation = Quaternion.LookRotation(Vector3.back, Vector3.up); + GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere); + sphere.GetComponent().enabled = false; + + sphere.transform.localScale = new Vector3(0.05f, 0.05f, 0.05f); + sphere.transform.position = new Vector3(0, 0.15f, 0); + sphere.transform.SetParent(cylinder.transform, true); + Renderer rendSphere = sphere.GetComponent(); + rendSphere.material = new Material(Shader.Find("Sprites/Default")); + rendSphere.material.color = color; GameObject arrow = new GameObject("CUE-Arrow"); cylinder.transform.SetParent(arrow.transform, true); arrow.transform.position = arrowPosition; - arrow.transform.rotation = arrowRotation; - arrow.transform.position += 0.5f * arrow.transform.forward; // Move the arrow forward so the cylinder starts on the wanted position + + Vector3 arrowRotEulerAngles = arrowRotation.eulerAngles; + arrowRotEulerAngles.x += 90f; + arrow.transform.rotation = Quaternion.Euler(arrowRotEulerAngles); + + arrow.transform.position += 0.15f * arrow.transform.up; // Move the arrow forward so the cylinder starts on the wanted position return arrow; } diff --git a/src/UI/Panels/CamPaths.cs b/src/UI/Panels/CamPaths.cs index e4e6f6f..66974f5 100644 --- a/src/UI/Panels/CamPaths.cs +++ b/src/UI/Panels/CamPaths.cs @@ -276,12 +276,9 @@ namespace UnityExplorer.UI.Panels Quaternion arrowRot = lookaheadPoints[i].rotation; if (followObject != null && FreeCamPanel.followRotationToggle.isOn) arrowRot = followObject.transform.rotation * arrowRot; - try { - // We could expose the color of the arrow to a setting - GameObject arrow = ArrowGenerator.CreateArrow(arrowPos, arrowRot, Color.green); - arrow.transform.SetParent(pathVisualizer.transform, true); - } - catch { ExplorerCore.LogWarning("Couldn't create campath visualizer."); } + // We could expose the color of the arrow to a setting + GameObject arrow = ArrowGenerator.CreateArrow(arrowPos, arrowRot, Color.green); + arrow.transform.SetParent(pathVisualizer.transform, true); n = 0; } } diff --git a/src/UI/Panels/LightsManger.cs b/src/UI/Panels/LightsManger.cs index 3ff136f..522360c 100644 --- a/src/UI/Panels/LightsManger.cs +++ b/src/UI/Panels/LightsManger.cs @@ -158,12 +158,9 @@ namespace UnityExplorer.UI.Panels switch(requestedType){ case LightType.Spot: lightComponent.range = 10; - try { - GameObject arrow = ArrowGenerator.CreateArrow(Vector3.zero, Quaternion.identity, lightComponent.color); - arrow.SetActive(false); - arrow.transform.SetParent(obj.transform, true); - } - catch { ExplorerCore.LogWarning("Couldn't create spotlight visualizer."); } + GameObject arrow = ArrowGenerator.CreateArrow(Vector3.zero, Quaternion.identity, lightComponent.color); + arrow.SetActive(false); + arrow.transform.SetParent(obj.transform, true); break; case LightType.Point: GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);