|
@@ -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");
|
|
|
+ }
|
|
|
}
|
|
|
}
|