public void HighLight(bool on, Color color) { if ((on && highlighted) || (!on && !highlighted)) { return; } if (on && !highlighted) { for (int i = 1; i < route.Count; i++) { GizmosDrawer.AddVectorPair(new Vector3[] { route[i - 1].Position, route[i].Position }, color); } //GizmosDrawer.AddVectorPair(new Vector3[] { route[route.Count - 1].transform.position, route[0].transform.position }, color); highlighted = true; } else { for (int i = 1; i < route.Count; i++) { GizmosDrawer.RemoveVectorPair(new Vector3[] { route[i - 1].Position, route[i].Position }); } //GizmosDrawer.RemoveVectorPair(new Vector3[] { endPoint, startPoint }); highlighted = false; } }
private void Initialize() { if (TryToInit()) { _gizmosDrawer = GameObject.FindGameObjectWithTag("GizmosDrawer").GetComponent <GizmosDrawer>(); _isInitialize = true; } }
private IEnumerator ReDrawRoutes() { while (true) { RouteSet.HighLightAll(false); GizmosDrawer.Clear(); RouteSet.HighLightAll(true); yield return(new WaitForSeconds(2)); } }
void OnEnable() { // Setup the SerializedProperties. if (!gd) { GameObject go = new GameObject("Gizmos"); gd = go.AddComponent <GizmosDrawer>(); if (!gd) { Debug.Log("Fiald"); } } }
public static IEnumerator CheckRoutes() { while (checking) { if (routes.Count > 0) { Timer timer = new Timer(); timer.Start(); for (int i = 0; i < routes.Count; i++) { Route route = routes[i]; int curr = 0, last = route.Count - 1; while (curr != last) { if (route[curr] == null) { Timer t = new Timer(); t.Start(); route.UpdateTempStartWP(); var newRoute = RouteCreator.CreatePathWP(route.startWP, route.endWP, !route.IsTemp); route.Set(newRoute); Debug.Log("<color=orange>Coroutine route " + route.RouteID + " recalculation:</color><color=green> " + t.ElapsedTime(Timer.Units.Milliseconds) + " ms.</color>"); break; //yield return null; } else { curr++; } } } Debug.Log("Coroutine routes recalculation:<color=green> " + timer.ElapsedTime(Timer.Units.Milliseconds) + " ms.</color>"); } HighLightAll(false); GizmosDrawer.Clear(); HighLightAll(true); yield return(new WaitUntil(() => { return Time.frameCount % 10 == 0; })); } }
void OnDisable() { foreach (var item in nodes.Values) { if (item.Tip) { DestroyImmediate(item.Tip); } } nodes.Clear(); if (gd) { DestroyImmediate(gd.gameObject); gd = null; } }