public IEnumerator WhenMoveFindNearestNeighbour_ThenNearestNeighbourUpdate() { FindNearestNeighbour firstNearestNeighbour = Object.Instantiate(prefab); firstNearestNeighbour.GetComponent <RandomMove>().gameObject.SetActive(false); FindNearestNeighbour secondNearestNeighbour = Object.Instantiate(prefab); secondNearestNeighbour.GetComponent <RandomMove>().gameObject.SetActive(false); FindNearestNeighbour thirdNearestNeighbour = Object.Instantiate(prefab); thirdNearestNeighbour.GetComponent <RandomMove>().gameObject.SetActive(false); //Act & Asserts firstNearestNeighbour.transform.position = Vector3.zero; secondNearestNeighbour.transform.position = Vector3.one; thirdNearestNeighbour.transform.position = new Vector3(10, 10, 10); positionHandler.UpdatePositions(); yield return(0); Assert.AreSame(secondNearestNeighbour, firstNearestNeighbour.CurrentNearestNeighbour, "No the correct neighbour"); yield return(0); secondNearestNeighbour.transform.position = new Vector3(11, 11, 11); yield return(0); positionHandler.UpdatePositions(); yield return(0); Assert.AreSame(thirdNearestNeighbour, firstNearestNeighbour.CurrentNearestNeighbour, "No the correct neighbour"); }
public static void RegisterFindNearestNeighbour(FindNearestNeighbour findNearestNeighbour) { if (Instance.objectsToUpdateNearestNeighbours.Contains(findNearestNeighbour)) { throw new Exception("Trying to register an already registered object "); } Instance.objectsToUpdateNearestNeighbours.Add(findNearestNeighbour); Instance.UpdateKdTree(); }
public void UpdatePositions() { int size = objectsToUpdateNearestNeighbours.Count; for (int i = 0; i < size; i++) { FindNearestNeighbour nearestNeighbour = kdTree.FindClosest(objectsToUpdateNearestNeighbours[i].GetPosition(), objectsToUpdateNearestNeighbours[i]); objectsToUpdateNearestNeighbours[i].CurrentNearestNeighbour = nearestNeighbour; } }
public static void DeregisterFindNearestNeighbour(FindNearestNeighbour findNearestNeighbour) { if (Instance.objectsToUpdateNearestNeighbours.Contains(findNearestNeighbour)) { Instance.objectsToUpdateNearestNeighbours.Remove(findNearestNeighbour); Instance.UpdateKdTree(); return; } throw new Exception("Trying to deregister an not registered object"); }
public IEnumerator WhenInstantiateObjectOfTypeFindNearestNeighbour_ThenPositionHandlerRegisterNewFindNearestNeighbour() { //Act FindNearestNeighbour findNearestNeighbour = Object.Instantiate(prefab); findNearestNeighbour.GetComponent <RandomMove>().Initialize(areaOfMove); yield return(0); //Asserts Assert.IsTrue(positionHandler.ItIsRegistered(findNearestNeighbour), "do not register the instantiated FindNearestNeighbour"); }
public bool ItIsRegistered(FindNearestNeighbour findNearestNeighbour) { foreach (var nearestNeighbour in objectsToUpdateNearestNeighbours) { if (nearestNeighbour == findNearestNeighbour) { return(true); } } return(false); }
public IEnumerator WhenDisableFindNearestNeighbour_ThenFindDeregisterNeighbour() { //Act FindNearestNeighbour findNearestNeighbour = Object.Instantiate(prefab); findNearestNeighbour.GetComponent <RandomMove>().Initialize(areaOfMove); yield return(0); findNearestNeighbour.Deregister(); yield return(0); //Asserts Assert.IsFalse(positionHandler.ItIsRegistered(findNearestNeighbour), "it is registered deactivate FindNearestNeighbour"); }
public void Initialize(bool useLineRenderer) { CurrentNearestNeighbour = this; SetDrawLine(useLineRenderer); }
public void SetUp() { positionHandler = new PositionHandler(); prefab = Resources.Load <FindNearestNeighbour>("TestResources/GameObject_FindNearestNeighbour"); areaOfMove = new AreaOfMove(); }