private float GetBakedTime(TrafficPath path) { float speed = path.bakedResolution; GoSpline spline = path.Spline(); float duration = spline.pathLength; return(fixedTime / (duration / (speed * 0.44704f))); }
//Worker thread to do the baking IEnumerator Worker(TrafficPath path) { Debug.Log("Start Worker"); //open folder to create new file //System.IO.FileStream fstream = Ultilities.OpenFile(path.gameObject.name, System.IO.FileMode.OpenOrCreate); string workerName = "Worker: " + path.gameObject.name; GameObject trafficBaker = new GameObject(workerName); trafficBaker.transform.SetParent(transform); float progress = 0; GoSpline spline = path.Spline(); float speed = path.bakedResolution; float duration = path.Spline().pathLength; List <Vector3> pathNodes = new List <Vector3>(); string pathName = path.gameObject.name; //baking while (progress <= 1.0f) { yield return(new WaitForFixedUpdate()); progress += Time.fixedDeltaTime / (duration / (speed * 0.44704f)); Vector3 pos = spline.getPointOnPath(progress); trafficBaker.transform.position = pos; pathNodes.Add(pos); trafficBaker.name = workerName + ": " + progress * 100 + "%"; } //done baking Debug.Log(workerName + ": Done"); Debug.Log("Nodes Count: " + pathNodes.Count); /* * BakedTrafficPath bakedPath = ScriptableObject.CreateInstance<BakedTrafficPath>(); * bakedPath.Init(pathNodes, pathName, path.pathType, path.pathSpeedMPH, path.bakedResolution, path.splitChance, path.smartTraffic, path.phaseTypes, path.notes); * bakedPath.CreateAndSave(savedLocation); */ yield return(null); }