Created
March 7, 2020 22:28
-
-
Save dmbfm/821a0c022f8d4080e7468fd9a271e21b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using ARLocation; | |
using System; | |
public class PlaceObjectsLine : MonoBehaviour | |
{ | |
[Serializable] | |
public class Entry | |
{ | |
public LocationData ObjectLocation; | |
public OverrideAltitudeData OverrideAltitude = new OverrideAltitudeData(); | |
} | |
[Tooltip("The locations where the objects will be instantiated.")] | |
public List<PlaceAtLocation.LocationSettingsData> Locations; | |
public PlaceAtLocation.PlaceAtOptions PlacementOptions; | |
/// <summary> | |
/// The game object that will be instantiated. | |
/// </summary> | |
[Tooltip("The game object that will be instantiated.")] | |
public GameObject Prefab; | |
[Space(4.0f)] | |
private readonly List<Location> locations = new List<Location>(); | |
private readonly List<GameObject> instances = new List<GameObject>(); | |
private void Start() | |
{ | |
foreach (var entry in Locations) | |
{ | |
var newLoc = entry.GetLocation(); | |
AddLocation(newLoc); | |
} | |
} | |
public void AddLocation(Location location) | |
{ | |
var instance = PlaceAtLocation.CreatePlacedInstance(Prefab, location, PlacementOptions, true); | |
instance.name = $"{gameObject.name} - {locations.Count}"; | |
locations.Add(location); | |
instances.Add(instance); | |
} | |
public void Update() | |
{ | |
float currentDist = 1000000; | |
GameObject closest = null; | |
foreach(var instance in instances) | |
{ | |
var dist = Vector3.Distance(instance.transform.position, ARLocationManager.Instance.MainCamera.transform.position); | |
if (dist < currentDist) | |
{ | |
currentDist = dist; | |
closest = instance; | |
} | |
} | |
foreach(var instance in instances) | |
{ | |
var deb = instance.GetComponent<ARLocation.UI.DebugDistance>(); | |
if (deb != null) | |
{ | |
if (closest == instance) | |
{ | |
deb.enabled = true; | |
} | |
else | |
{ | |
deb.enabled = false; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment