Browse Source

Fixed most of routing

Marcel Zickler 3 years ago
parent
commit
810f2bc5de

+ 5 - 0
Assets/Prefabs/Player/BikePlayer - RigidBody.prefab

@@ -291,6 +291,11 @@ PrefabInstance:
       propertyPath: m_IsKinematic
       value: 0
       objectReference: {fileID: 0}
+    - target: {fileID: 653210787133548223, guid: a065ef1d4c56ffa49bb0b821da25d91b,
+        type: 3}
+      propertyPath: m_TagString
+      value: bike
+      objectReference: {fileID: 0}
     - target: {fileID: 653210788318262019, guid: a065ef1d4c56ffa49bb0b821da25d91b,
         type: 3}
       propertyPath: m_Name

+ 2 - 4
Assets/Prefabs/Player/BikePlayer.prefab

@@ -95,7 +95,7 @@ GameObject:
   - component: {fileID: 653210787133548212}
   m_Layer: 9
   m_Name: bike
-  m_TagString: Untagged
+  m_TagString: bike
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
@@ -4711,7 +4711,7 @@ GameObject:
   - component: {fileID: 9132626276124788811}
   m_Layer: 0
   m_Name: BikePlayer
-  m_TagString: Untagged
+  m_TagString: bike
   m_Icon: {fileID: 0}
   m_NavMeshLayer: 0
   m_StaticEditorFlags: 0
@@ -4753,8 +4753,6 @@ MonoBehaviour:
   polarSensorConfig:
     port: 9099
     ipAddress: 0.0.0.0
-    plotAcc: 0
-    plotEcg: 0
     accSampleRate: 200
   frontWheelTrackerConfig:
     frontWheelTracker: {fileID: 0}

+ 16 - 2
Assets/Prefabs/Roads/Road_Crossing_With_Sidewalk.prefab

@@ -174,6 +174,7 @@ GameObject:
   m_Component:
   - component: {fileID: 1682435362963659099}
   - component: {fileID: 5908241662424435614}
+  - component: {fileID: 7137157540369938318}
   m_Layer: 11
   m_Name: Road_Crossing_With_Sidewalk
   m_TagString: Untagged
@@ -213,13 +214,26 @@ MonoBehaviour:
   m_Script: {fileID: 11500000, guid: 7bc613422f424ecbab70286630638b48, type: 3}
   m_Name: 
   m_EditorClassIdentifier: 
-  comingFrom: 0
-  goingTo: 2
+  comingFrom: 4
+  goingTo: 4
   crossingData:
     west: {fileID: 4825782920790351022}
     north: {fileID: 2526126444667350587}
     east: {fileID: 4744145252221914869}
     south: {fileID: 8085698666132697163}
+--- !u!65 &7137157540369938318
+BoxCollider:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 6779282248948444977}
+  m_Material: {fileID: 0}
+  m_IsTrigger: 1
+  m_Enabled: 1
+  serializedVersion: 2
+  m_Size: {x: 20, y: 6, z: 20}
+  m_Center: {x: 0, y: 3, z: 0}
 --- !u!1 &7932951198534922238
 GameObject:
   m_ObjectHideFlags: 0

File diff suppressed because it is too large
+ 155 - 318
Assets/Scenes/MainScene.unity


+ 4 - 0
Assets/Scripts/ColliderAddSlopeAdjustment.cs

@@ -59,6 +59,10 @@ public class ColliderAddSlopeAdjustment : MonoBehaviour
         if (Physics.Raycast(position,forward , out hit, rayLength, layerMask))
         {
             Debug.DrawRay(position, forward * hit.distance, Color.yellow);
+            if (hit.collider.isTrigger)
+            {
+                return null;
+            }
             return hit.distance;
             //Debug.Log("Did Hit: ");
         }

+ 49 - 10
Assets/Scripts/Routes/Route.cs

@@ -10,36 +10,75 @@ namespace Routes
     [Serializable]
     public struct RouteItem
     {
-        [SerializeReference]
         public Turn turn;
         public RoadDirection from;
         public RoadDirection to;
 
         public void Apply()
         {
-            turn.comingFrom = from;
-            turn.goingTo = to;
+            if (turn.comingFrom != from || turn.goingTo != to)
+            {
+                turn.comingFrom = from;
+                turn.goingTo = to;
+                turn.UpdateArrows();
+            }
         }
 
         public void Clear()
         {
-            turn.comingFrom = RoadDirection.None;
-            turn.goingTo = RoadDirection.None;
+            if (turn.comingFrom != RoadDirection.None || turn.goingTo != RoadDirection.None)
+            {
+                turn.comingFrom = RoadDirection.None;
+                turn.goingTo = RoadDirection.None;
+                turn.UpdateArrows();
+            }
         }
     }
-    
+
     public class Route : MonoBehaviour
     {
         public List<RouteItem> items;
 
-        public void Clear()
+        private int visibleLength;
+        private int visibleStart;
+        private Transform bicycle;
+
+        private int VisibleStart => Math.Max(0, visibleStart - 1);
+
+        private int VisibleEnd => Math.Min(items.Count, VisibleStart + visibleLength);
+
+        private void Start()
+        {
+            var routeManager = GetComponentInParent<RouteManager>();
+            visibleStart = 0;
+            visibleLength = routeManager.visibleLength;
+            bicycle = routeManager.bicycle;
+
+            items.ForEach((item) => item.turn.OnTriggerExitBicycle = NextTurn);
+            UpdateRouteItems();
+        }
+
+        private void NextTurn()
         {
-            items.ForEach(i => i.Clear());
+            Debug.Log("Route: left intersection - show next turn");
+            visibleStart++;
+            UpdateRouteItems();
         }
 
-        public void Show()
+        private void UpdateRouteItems()
         {
-            items.ForEach(i => i.Apply());
+            for (var i = 0; i < items.Count; i++)
+            {
+                var item = items[i];
+                if (i >= VisibleStart && i < VisibleEnd)
+                {
+                    item.Apply();
+                }
+                else
+                {
+                    item.Clear();
+                }
+            }
         }
     }
 }

+ 3 - 20
Assets/Scripts/Routes/RouteManager.cs

@@ -1,4 +1,5 @@
 using System;
+using Controller.Bicycle;
 using UnityEditor;
 using UnityEngine;
 using Valve.VR.InteractionSystem;
@@ -9,28 +10,10 @@ namespace Routes
     {
         public Route[] routes;
         public int selectedRoute;
+        public int visibleLength = 3;
+        public Transform bicycle;
 
         private void Awake()
-        {
-            ShowActiveRoute();
-        }
-
-        private void ShowActiveRoute()
-        {
-            routes.ForEach(r => r.Clear());
-            routes[selectedRoute].Show(); //TODO: maybe show when coming to it
-        }
-
-        private void OnValidate()
-        {
-            ChangeActiveRoute();
-            if (EditorApplication.isPlaying)
-            {
-                ShowActiveRoute();
-            }
-        }
-
-        private void ChangeActiveRoute()
         {
             for (int i = 0; i < routes.Length; i++)
             {

+ 82 - 24
Assets/Scripts/Routes/Turn.cs

@@ -1,9 +1,11 @@
 using System;
+using System.Collections.Generic;
 using System.Linq;
 using JetBrains.Annotations;
 using Pools;
 using Roads;
 using UnityEngine;
+using Valve.VR.InteractionSystem;
 
 namespace Routes
 {
@@ -11,50 +13,44 @@ namespace Routes
     {
         public RoadDirection comingFrom;
         public RoadDirection goingTo;
-        
+
         [CanBeNull] private Pool arrowPool;
 
         private bool arrowPoolAvailable;
         private TurnDirection turnDirection;
-        
+        private List<GameObject> usedArrows = new List<GameObject>();
+        public Action OnTriggerExitBicycle { get; set; }
+
         private void Awake()
         {
             arrowPool = FindObjectsOfType<Pool>().FirstOrDefault(o => o.CompareTag("ArrowPool"));
             arrowPoolAvailable = arrowPool != null;
-            if (!arrowPoolAvailable) Debug.LogWarning("Arrow Pool not found"); 
+            if (!arrowPoolAvailable) Debug.LogWarning("Arrow Pool not found");
         }
 
         private void Start()
         {
-            if (comingFrom == RoadDirection.None || goingTo == RoadDirection.None) return;
-            turnDirection = TurnDirectionMapper.GetTurnDirection(comingFrom, goingTo);
-
-            var items = new[] {RoadDirection.West, RoadDirection.North, RoadDirection.East, RoadDirection.South};
-            foreach (var position in items.Where(i => i != comingFrom && i != goingTo))
-            {
-                AddArrows(position);
-            }
+            UpdateArrows();
         }
 
         protected virtual Transform RoadDirectionToTransform(RoadDirection position)
         {
             throw new NotImplementedException();
         }
-        
-        private void AddArrows(RoadDirection position)
+
+        private void AddArrows(RoadDirection position, GameObject arrows)
         {
             if (!arrowPoolAvailable) return;
-            Transform t = RoadDirectionToTransform(position);
+            var t = RoadDirectionToTransform(position);
 
-            System.Diagnostics.Debug.Assert(arrowPool != null, nameof(arrowPool) + " != null");
-            var arrows = arrowPool.GetItem();
             SetRotation(arrows, position);
             arrows.transform.position = t.position;
         }
 
         private void SetRotation(GameObject arrows, RoadDirection position)
         {
-            //by default, the arrow shows to north
+            var t = arrows.transform;
+            //by default, the arrows show to east
             switch (position)
             {
                 case RoadDirection.West:
@@ -62,21 +58,24 @@ namespace Routes
                     if (turnDirection == TurnDirection.Left ||
                         turnDirection == TurnDirection.Straight && goingTo == RoadDirection.South)
                     {
-                        arrows.transform.Rotate(Vector3.up, 90);
+                        t.rotation = Quaternion.Euler(0, 90, 0);
+                        //arrows.transform.Rotate(Vector3.up, 90);
                     }
                     else if (turnDirection == TurnDirection.Right ||
                              turnDirection == TurnDirection.Straight && goingTo == RoadDirection.North)
                     {
-                        arrows.transform.Rotate(Vector3.up, 90);
+                        t.rotation = Quaternion.Euler(0, 270, 0);
+                        //arrows.transform.Rotate(Vector3.up, 90);
                     }
 
                     break;
                 }
                 case RoadDirection.North:
                     if (turnDirection == TurnDirection.Left ||
-                        turnDirection == TurnDirection.Straight && goingTo == RoadDirection.East)
+                        turnDirection == TurnDirection.Straight && goingTo == RoadDirection.West)
                     {
-                        arrows.transform.Rotate(Vector3.up, 180);
+                        t.rotation = Quaternion.Euler(0, 180, 0);
+                        //arrows.transform.Rotate(Vector3.up, 180);
                     }
 
                     break;
@@ -84,12 +83,14 @@ namespace Routes
                     if (turnDirection == TurnDirection.Right ||
                         turnDirection == TurnDirection.Straight && goingTo == RoadDirection.South)
                     {
-                        arrows.transform.Rotate(Vector3.up, 90);
+                        t.rotation = Quaternion.Euler(0, 90, 0);
+                        //arrows.transform.Rotate(Vector3.up, 90);
                     }
                     else if (turnDirection == TurnDirection.Left ||
                              turnDirection == TurnDirection.Straight && goingTo == RoadDirection.North)
                     {
-                        arrows.transform.Rotate(Vector3.up, -90);
+                        t.rotation = Quaternion.Euler(0, 270, 0);
+                        //arrows.transform.Rotate(Vector3.up, -90);
                     }
 
                     break;
@@ -97,7 +98,8 @@ namespace Routes
                     if (turnDirection == TurnDirection.Right ||
                         turnDirection == TurnDirection.Straight && goingTo == RoadDirection.West)
                     {
-                        arrows.transform.Rotate(Vector3.up, 180);
+                        t.rotation = Quaternion.Euler(0, 180, 0);
+                        //arrows.transform.Rotate(Vector3.up, 180);
                     }
 
                     break;
@@ -107,5 +109,61 @@ namespace Routes
                     throw new ArgumentOutOfRangeException(nameof(position), position, null);
             }
         }
+
+        public void UpdateArrows()
+        {
+            if (comingFrom == RoadDirection.None || goingTo == RoadDirection.None)
+            {
+                if (!arrowPoolAvailable) return;
+                usedArrows.ForEach(o =>
+                {
+                    // ReSharper disable once PossibleNullReferenceException
+                    arrowPool.ReturnToPool(o);
+                });
+                usedArrows.Clear();
+                return;
+            }
+
+            turnDirection = TurnDirectionMapper.GetTurnDirection(comingFrom, goingTo);
+
+            var items = new[] {RoadDirection.West, RoadDirection.North, RoadDirection.East, RoadDirection.South};
+
+            var usedArrowIndex = 0;
+            foreach (var position in items.Where(i => i != comingFrom && i != goingTo))
+            {
+                
+                GameObject arrows;
+                if (usedArrowIndex < usedArrows.Count)
+                {
+                    arrows = usedArrows[usedArrowIndex];
+                }
+                else
+                {
+                    // ReSharper disable once PossibleNullReferenceException
+                    arrows = arrowPool.GetItem();
+                    usedArrows.Add(arrows);
+                }
+                AddArrows(position, arrows);
+                usedArrowIndex++;
+            }
+        }
+
+        private void OnTriggerExit(Collider other)
+        {
+            if (other.CompareTag("bike"))
+            {
+                OnTriggerExitBicycle();
+            }
+        }
+
+        private void OnCollisionEnter(Collision other)
+        {
+            Debug.Log("Colission");
+        }
+
+        private void OnTriggerEnter(Collider other)
+        {
+            Debug.Log("Trigger");
+        }
     }
 }

+ 1 - 1
ProjectSettings/QualitySettings.asset

@@ -95,7 +95,7 @@ QualitySettings:
     skinWeights: 2
     textureQuality: 0
     anisotropicTextures: 1
-    antiAliasing: 2
+    antiAliasing: 0
     softParticles: 0
     softVegetation: 1
     realtimeReflectionProbes: 1

+ 1 - 0
ProjectSettings/TagManager.asset

@@ -7,6 +7,7 @@ TagManager:
   - projectile
   - FxTemporaire
   - ArrowPool
+  - bike
   layers:
   - Default
   - TransparentFX

Some files were not shown because too many files changed in this diff