From 5f9e8f979deb94e9219113ed09b49142c040cb57 Mon Sep 17 00:00:00 2001 From: Simon O'Shea Date: Mon, 31 Jul 2023 18:45:01 -0400 Subject: import successful, grid has visuals cell values and grid lines are displayed. no interaction available yet. --- .../MonoBehaviours/PositionRendererSorter.cs | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs (limited to 'Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs') diff --git a/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs b/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs new file mode 100644 index 0000000..46f2058 --- /dev/null +++ b/Pathfinding Visualizer/Assets/CodeMonkey/MonoBehaviours/PositionRendererSorter.cs @@ -0,0 +1,51 @@ +/* + ------------------- Code Monkey ------------------- + + Thank you for downloading the Code Monkey Utilities + I hope you find them useful in your projects + If you have any questions use the contact form + Cheers! + + unitycodemonkey.com + -------------------------------------------------- + */ + +using UnityEngine; + +namespace CodeMonkey.MonoBehaviours { + + /* + * Automatically sort a Renderer (SpriteRenderer, MeshRenderer) based on his Y position + * */ + public class PositionRendererSorter : MonoBehaviour { + + [SerializeField] private int sortingOrderBase = 5000; // This number should be higher than what any of your sprites will be on the position.y + [SerializeField] private int offset = 0; + [SerializeField] private bool runOnlyOnce = false; + + private float timer; + private float timerMax = .1f; + private Renderer myRenderer; + + private void Awake() { + myRenderer = gameObject.GetComponent(); + } + + private void LateUpdate() { + timer -= Time.deltaTime; + if (timer <= 0f) { + timer = timerMax; + myRenderer.sortingOrder = (int)(sortingOrderBase - transform.position.y - offset); + if (runOnlyOnce) { + Destroy(this); + } + } + } + + public void SetOffset(int offset) { + this.offset = offset; + } + + } + +} \ No newline at end of file -- cgit v1.3.1-4-g156e