From f2b5c28c4b34463360201544d6336872a0ded7aa Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:26:20 +0200 Subject: [PATCH 1/4] No errors silhuette ting --- Assets/Scenes/TowerPlacement.unity | 2 +- Assets/Scripts/PlacementSystem/PlacementManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Scenes/TowerPlacement.unity b/Assets/Scenes/TowerPlacement.unity index 665651f..378c16f 100644 --- a/Assets/Scenes/TowerPlacement.unity +++ b/Assets/Scenes/TowerPlacement.unity @@ -169,7 +169,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: acef1d7c80f784543acd3e1571e99495, type: 3} m_Name: m_EditorClassIdentifier: - DebugTowerPrefab: {fileID: 1927189479841411320, guid: 60899c8a0efa6f74393d369a109d82c3, + DebugTowerPrefab: {fileID: 8488737342646939416, guid: 9415cb10a1bd579269301ca4f61a1554, type: 3} SilhouetteMaterial: {fileID: 2100000, guid: 0610eb89b05f0b546929db3664a351d8, type: 2} --- !u!4 &268589088 stripped diff --git a/Assets/Scripts/PlacementSystem/PlacementManager.cs b/Assets/Scripts/PlacementSystem/PlacementManager.cs index 54b38f3..a6f3688 100644 --- a/Assets/Scripts/PlacementSystem/PlacementManager.cs +++ b/Assets/Scripts/PlacementSystem/PlacementManager.cs @@ -89,7 +89,7 @@ public class TowerPlacementManager : MonoBehaviour else if (typeof(Renderer).IsAssignableFrom(comp)) { var renderer = comp as Renderer; - renderer.material = SilhouetteMaterial; + renderer.materials = new Material[] { SilhouetteMaterial , SilhouetteMaterial , SilhouetteMaterial , SilhouetteMaterial , SilhouetteMaterial }; } } From d6c8946e4e8af7807fc9302daa435411a020b883 Mon Sep 17 00:00:00 2001 From: BOT Alex <44818698+MagicBOTAlex@users.noreply.github.com> Date: Sat, 20 Apr 2024 17:28:45 +0200 Subject: [PATCH 2/4] Added do not render layer --- ProjectSettings/TagManager.asset | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 65d15ac..81d9ad5 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -36,7 +36,7 @@ TagManager: - - - - - + - DoNotRender m_SortingLayers: - name: Default uniqueID: 0 From 8c36235d361c90ab8501085d829eadcdf482976a Mon Sep 17 00:00:00 2001 From: kimrdd Date: Sat, 20 Apr 2024 17:29:39 +0200 Subject: [PATCH 3/4] Camera pretty much finished --- Assets/Scenes/CameraTestScene.unity | 23 ++++++++-- Assets/Scripts/Camera/HideWall.cs | 67 +++++++++++++++++------------ 2 files changed, 59 insertions(+), 31 deletions(-) diff --git a/Assets/Scenes/CameraTestScene.unity b/Assets/Scenes/CameraTestScene.unity index 1537e32..4cdc06e 100644 --- a/Assets/Scenes/CameraTestScene.unity +++ b/Assets/Scenes/CameraTestScene.unity @@ -222,8 +222,8 @@ Transform: m_GameObject: {fileID: 163929259} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 2.8726685, y: 0.40448904, z: -1.4757066} - m_LocalScale: {x: 10, y: 5.455344, z: 0.5} + m_LocalPosition: {x: 2.8726685, y: 0.897, z: -1.4757066} + m_LocalScale: {x: 10, y: 4.470458, z: 0.5} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1696531492} @@ -550,8 +550,8 @@ Transform: m_GameObject: {fileID: 1425080745} serializedVersion: 2 m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 2.8726685, y: 0.40448904, z: -11.059507} - m_LocalScale: {x: 10, y: 5.455344, z: 0.5} + m_LocalPosition: {x: 2.8726685, y: 0.9099, z: -11.059507} + m_LocalScale: {x: 10, y: 4.444636, z: 0.5} m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 1696531492} @@ -941,6 +941,21 @@ PrefabInstance: propertyPath: m_LocalRotation.z value: -0.1103237 objectReference: {fileID: 0} + - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, + type: 3} + propertyPath: sphereRayOffset.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, + type: 3} + propertyPath: maxSphereRayDistanceOffset + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, + type: 3} + propertyPath: maxSphereRayDistanceOffset.y + value: 3 + objectReference: {fileID: 0} - target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalRotation.w diff --git a/Assets/Scripts/Camera/HideWall.cs b/Assets/Scripts/Camera/HideWall.cs index a02ad4b..8e9bc68 100644 --- a/Assets/Scripts/Camera/HideWall.cs +++ b/Assets/Scripts/Camera/HideWall.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using UnityEngine; public class HideWall : MonoBehaviour @@ -11,49 +12,61 @@ public class HideWall : MonoBehaviour public Material hitMaterial; // Material when hitting "Wall" public float sphereRadius; - float maxRayDistance; + float maxSphereRayDistance; + public Vector3 maxSphereRayDistanceOffset; + + private List prevHitObjects = new List(); private void Start() { - maxRayDistance = Vector3.Distance(target.transform.position, origin.transform.position) - sphereRadius * 2; + maxSphereRayDistance = Vector3.Distance(origin.transform.position, target.transform.position) - (sphereRadius * 2 + 1); } void Update() { - Vector3 direction = (target.transform.position - origin.transform.position).normalized; + Vector3 direction = ((target.transform.position + maxSphereRayDistanceOffset) - origin.transform.position).normalized; + RaycastHit[] hits = Physics.SphereCastAll(origin.transform.position, sphereRadius, direction, maxSphereRayDistance); - RaycastHit[] hit; + List hitObjectsThisFrame = new List(); - hit = Physics.SphereCastAll(origin.transform.position, sphereRadius, direction, maxRayDistance); - - for (int i = 0; i < hit.Length; i++) + // Change material of currently hit objects + for (int i = 0; i < hits.Length; i++) { - if (hit[i].collider.CompareTag("Wall")) + if (hits[i].collider.CompareTag("Wall")) { - if (prevObject != null) - if (prevObject == hit[i].collider.gameObject) - { - var renderer = hit[i].collider.GetComponent(); - var originalMat = renderer.material; - var originalColor = originalMat.color; - originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 0f); - renderer.material = originalMat; - } - else - { - var renderer = prevObject.GetComponent().GetComponent(); - var originalMat = renderer.material; - var originalColor = originalMat.color; - originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1f); - renderer.material = originalMat; - } + var hitGameObject = hits[i].collider.gameObject; + hitObjectsThisFrame.Add(hitGameObject); - prevObject = hit[i].collider.gameObject; + // Change material only if this object wasn't hit last frame + if (!prevHitObjects.Contains(hitGameObject)) + { + Renderer renderer = hits[i].collider.GetComponent(); + if (renderer != null) + { + renderer.material = hitMaterial; + } + } } - print(hit[i].collider.gameObject.name); } + + // Restore the material of objects that are not hit this frame but were hit in the previous frame + for (int i = 0; i < prevHitObjects.Count; i++) + { + if (!hitObjectsThisFrame.Contains(prevHitObjects[i])) + { + Renderer renderer = prevHitObjects[i].GetComponent(); + if (renderer != null) + { + renderer.material = defaultMaterial; + } + } + } + + // Update the list of previously hit objects + prevHitObjects = hitObjectsThisFrame; } + private void OnDrawGizmos() { Gizmos.color = Color.red; From 2c2036c2c9a65d8aef7936ef478bc763add3a0f5 Mon Sep 17 00:00:00 2001 From: kimrdd Date: Sat, 20 Apr 2024 17:30:53 +0200 Subject: [PATCH 4/4] prefab apply --- Assets/Prefabs/Cinemachine.prefab | 9 ++--- Assets/Scenes/CameraTestScene.unity | 55 ----------------------------- 2 files changed, 5 insertions(+), 59 deletions(-) diff --git a/Assets/Prefabs/Cinemachine.prefab b/Assets/Prefabs/Cinemachine.prefab index 529ac0a..5089669 100644 --- a/Assets/Prefabs/Cinemachine.prefab +++ b/Assets/Prefabs/Cinemachine.prefab @@ -186,7 +186,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1400473914611959530} serializedVersion: 2 - m_LocalRotation: {x: -0.011396199, y: 0.98857015, z: -0.11032369, w: -0.102117166} + m_LocalRotation: {x: -0.011396202, y: 0.98857015, z: -0.11032369, w: -0.10211719} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -265,7 +265,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2383950784329503899} serializedVersion: 2 - m_LocalRotation: {x: -0.008466786, y: 0.99132437, z: -0.08196477, w: -0.10240167} + m_LocalRotation: {x: -0.008466786, y: 0.99132437, z: -0.08196477, w: -0.10240169} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -344,7 +344,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 3339643807228368672} serializedVersion: 2 - m_LocalRotation: {x: -0.014335657, y: 0.9849784, z: -0.13877982, w: -0.101746134} + m_LocalRotation: {x: -0.014335659, y: 0.9849784, z: -0.13877982, w: -0.10174616} m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -585,7 +585,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 6163557566655415017} serializedVersion: 2 - m_LocalRotation: {x: -0.0113961985, y: 0.98857015, z: -0.11032369, w: -0.10211714} + m_LocalRotation: {x: -0.011396202, y: 0.98857015, z: -0.1103237, w: -0.10211718} m_LocalPosition: {x: 8.5044365, y: 3.5927956, z: 10.26652} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -1031,6 +1031,7 @@ MonoBehaviour: defaultMaterial: {fileID: 2100000, guid: 1fb12e769af8dfc4b9c47b291e1da192, type: 2} hitMaterial: {fileID: 2100000, guid: 487f1aaeb1fd5674a8842eab66d03872, type: 2} sphereRadius: 2 + maxSphereRayDistanceOffset: {x: 0, y: 3, z: 0} --- !u!114 &7757173428948913319 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/CameraTestScene.unity b/Assets/Scenes/CameraTestScene.unity index 4cdc06e..f23bd0a 100644 --- a/Assets/Scenes/CameraTestScene.unity +++ b/Assets/Scenes/CameraTestScene.unity @@ -921,61 +921,6 @@ PrefabInstance: propertyPath: m_Name value: Cinemachine objectReference: {fileID: 0} - - target: {fileID: 2465233980315321778, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.w - value: -0.10240169 - objectReference: {fileID: 0} - - target: {fileID: 2981308973353539976, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.w - value: -0.10211718 - objectReference: {fileID: 0} - - target: {fileID: 2981308973353539976, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.x - value: -0.011396202 - objectReference: {fileID: 0} - - target: {fileID: 2981308973353539976, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.z - value: -0.1103237 - objectReference: {fileID: 0} - - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: sphereRayOffset.y - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: maxSphereRayDistanceOffset - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: maxSphereRayDistanceOffset.y - value: 3 - objectReference: {fileID: 0} - - target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.w - value: -0.10211719 - objectReference: {fileID: 0} - - target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.x - value: -0.011396202 - objectReference: {fileID: 0} - - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.w - value: -0.10174616 - objectReference: {fileID: 0} - - target: {fileID: 7348612162646443967, guid: fd9f9b61c0ebb324ebc9f929e26706bc, - type: 3} - propertyPath: m_LocalRotation.x - value: -0.014335659 - objectReference: {fileID: 0} - target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc, type: 3} propertyPath: m_LocalPosition.x