IEnumerator NavigationLine(float waitTime) { while (true) { yield return(new WaitForSeconds(waitTime)); //CurvySpline curvySpline = pathEnhanced.GetComponent<CurvySpline>(); segmentsToSearch.Add(curSegment); if (curSegment.SegmentIndex != curvySpline.Segments.Count - 1 && curSegment.SegmentIndex != 0) { segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex + 1].GetComponent <CurvySplineSegment>()); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex - 1].GetComponent <CurvySplineSegment>()); } else if (curSegment.SegmentIndex == curvySpline.Segments.Count - 1) { segmentsToSearch.Add(curvySpline[0].GetComponent <CurvySplineSegment>()); } else if (curSegment.SegmentIndex == 0) { segmentsToSearch.Add(curvySpline[1].GetComponent <CurvySplineSegment>()); } float carTf = curvySpline.GetNearestPointTFExt(transform.position, segmentsToSearch.ToArray()); linesUtilsAlt.DrawLine(gameObject, curvySpline, carTf); curSegment = curvySpline.TFToSegment(carTf); segmentsToSearch.Clear(); //else if (linesUtilsAlt.LineRend.positionCount != 0) // linesUtilsAlt.LineRend.positionCount = 0; //delete the LineRenderer } }
IEnumerator NavigationLine(float waitTime) { while (true) { yield return(new WaitForSeconds(waitTime)); CurvySpline curvySpline = pathEnhanced.GetComponent <CurvySpline>(); segmentsToSearch.Add(curSegment); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex + 1].GetComponent <CurvySplineSegment>()); segmentsToSearch.Add(curvySpline[curSegment.SegmentIndex - 1].GetComponent <CurvySplineSegment>()); //float carTf = curvySpline.GetNearestPointTFExt(transform.position, segmentsToSearch.ToArray()); float carTf = curvySpline.GetNearestPointTF(transform.position); Lane lane = MonitorLane(curvySpline.GetTangentFast(carTf)); if (lane == Lane.RIGHT) { linesUtilsAlt.DrawLine(gameObject, curvySpline, carTf); } else { linesUtilsAlt.LineRend.positionCount = 0; //delete the LineRenderer } curSegment = curvySpline.TFToSegment(carTf); segmentsToSearch.Clear(); } }
IEnumerator InitNavigationLine() { curvySpline = pathEnhanced.GetComponent <CurvySpline>(); while (!curvySpline.IsInitialized) { yield return(null); } float carTf = curvySpline.GetNearestPointTF(transform.position); curSegment = curvySpline.TFToSegment(carTf); }
CurvySplineSegment getSegment(float tf, out float localF) { if (mSpline is CurvySplineGroup) { float ltf; CurvySpline spl = ((CurvySplineGroup)mSpline).TFToSpline(tf, out ltf); return(spl.TFToSegment(ltf, out localF)); } else { return(((CurvySpline)mSpline).TFToSegment(tf, out localF)); } }
MetaCGOptions findPreviousReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; cp = spline.TFToSegment(tf); do { options = cp.GetMetadata <MetaCGOptions>(true); if (cp.IsFirstVisibleControlPoint) { return(options); } cp = cp.PreviousSegment; }while (cp && !options.UVEdge && !options.ExplicitU && !options.HasDifferentMaterial); return(options); }
MetaCGOptions findNextReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; float localF; cp = spline.TFToSegment(tf, out localF); do { cp = cp.NextControlPoint; options = cp.GetMetadata <MetaCGOptions>(true); if (!spline.Closed && cp.IsLastVisibleControlPoint) { return(options); } }while (!options.UVEdge && !options.ExplicitU && !options.HasDifferentMaterial && !cp.IsFirstSegment); return(options); }
MetaCGOptions findNextReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; float localF; cp = spline.TFToSegment(tf, out localF); do { cp = cp.NextControlPoint; options = cp.GetMetadata<MetaCGOptions>(true); if (!spline.Closed && cp.IsLastVisibleControlPoint) return options; } while (!options.UVEdge && !options.ExplicitU && !options.HasDifferentMaterial && !cp.IsFirstSegment); return options; }
MetaCGOptions findPreviousReferenceCPOptions(CurvySpline spline, float tf, out CurvySplineSegment cp) { MetaCGOptions options; cp = spline.TFToSegment(tf); do { options = cp.GetMetadata<MetaCGOptions>(true); if (cp.IsFirstVisibleControlPoint) return options; cp = cp.PreviousSegment; } while (cp && !options.UVEdge && !options.ExplicitU &&!options.HasDifferentMaterial); return options; }
void DoInterpolate() { if (!mSpline.IsInitialized) { return; } System.Type metaDataType; { if (String.IsNullOrEmpty(MetaDataType.Value)) { metaDataType = null; } else { #if NETFX_CORE Type[] knownTypes = this.GetType().GetAllTypes(); #else Type[] knownTypes = TypeExt.GetLoadedTypes(); #endif metaDataType = knownTypes.FirstOrDefault(t => t.FullName == MetaDataType.Value); } } bool calc = !Input.IsNone; if (calc) { float f = (UseWorldUnits.Value) ? mSpline.DistanceToTF(Input.Value) : Input.Value; if (StorePosition.IsNone == false) { StorePosition.Value = (UseCache.Value) ? mSpline.InterpolateFast(f) : mSpline.Interpolate(f); } if (StoreTangent.IsNone == false) { StoreTangent.Value = mSpline.GetTangent(f); } if (StoreUpVector.IsNone == false) { StoreUpVector.Value = mSpline.GetOrientationUpFast(f); } if (StoreRotation.IsNone == false) { StoreRotation.Value = (StoreUpVector.IsNone) ? mSpline.GetOrientationFast(f) : Quaternion.LookRotation(mSpline.GetTangent(f), StoreUpVector.Value); } if (StoreScale.IsNone == false) { float localF; CurvySplineSegment segment = mSpline.TFToSegment(f, out localF); CurvySplineSegment nextControlPoint = segment.Spline.GetNextControlPoint(segment); if (ReferenceEquals(segment, null) == false) { StoreScale.Value = nextControlPoint ? Vector3.Lerp(segment.transform.lossyScale, nextControlPoint.transform.lossyScale, localF) : segment.transform.lossyScale; } else { StoreScale.Value = Vector3.zero; } } if (StoreTF.IsNone == false) { StoreTF.Value = f; } if (StoreDistance.IsNone == false) { StoreDistance.Value = (UseWorldUnits.Value) ? Input.Value : mSpline.TFToDistance(f); } if (metaDataType != null) { if (metaDataType.IsSubclassOf(typeof(CurvyMetadataBase)) == false) { //this if statement's branch does not exclude classes inheriting from CurvyMetadataBase but not from CurvyInterpolatableMetadataBase, but that's ok, those classes are handled below Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>"); } else { if (StoreMetadata.IsNone == false) { MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetMetadata").MakeGenericMethod(metaDataType); StoreMetadata.Value = (Object)genericMethodInfo.Invoke(mSpline, new System.Object[] { f }); } if (StoreInterpolatedMetadata.IsNone == false) { Type argumentType = GetInterpolatableMetadataGenericType(metaDataType); if (argumentType == null) { Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>"); } else { MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetInterpolatedMetadata").MakeGenericMethod(metaDataType, argumentType); StoreInterpolatedMetadata.SetValue(genericMethodInfo.Invoke(mSpline, new System.Object[] { f })); } } } } CurvySplineSegment seg = null; float segF = 0; if (StoreSegment.IsNone == false) { seg = getSegment(f, out segF); StoreSegment.Value = seg.gameObject; } if (StoreSegmentF.IsNone == false) { if (!seg) { seg = getSegment(f, out segF); } StoreSegmentF.Value = segF; } if (StoreSegmentDistance.IsNone == false) { if (!seg) { seg = getSegment(f, out segF); } StoreSegmentDistance.Value = seg.LocalFToDistance(segF); } } // General if (StoreLength.IsNone == false) { StoreLength.Value = mSpline.Length; } if (StoreCount.IsNone == false) { StoreCount.Value = mSpline.Count; } }