/// <summary> /// Start a spline switch /// </summary> /// <param name="target">the target spline to switch to</param> /// <param name="targetTF">the target TF</param> /// <param name="duration">duration of the switch phase</param> public virtual void SwitchTo(CurvySpline target, float targetTF, float duration) { mSwitchStartTime = Time.time; mSwitchDuration = duration; mSwitchEventArgs = new CurvySplineMoveEventArgs(this, target, null, targetTF, 0, Direction); mSwitchEventArgs.Data = 0f; }
void onControllerEndReached(CurvySplineMoveEventArgs e) { FsmEventData eventData = new FsmEventData(); _OnEndReachedEventData = e; this.FirePlayMakerEvent(SplineControllerOnEndReached, splineControllerOnEndReachedTarget, eventData); e = _OnEndReachedEventData; }
// while we travel past CP's, we update the track public void Track_OnControlPointReached(CurvySplineMoveEventArgs e) { if (--mUpdateIn == 0) { mUpdateSpline = true; mUpdateIn = SectionCPCount; } }
void onSwitchEvent(CurvySplineMoveEventArgs e) { OnSwitch.Invoke(e); if (e.Cancel) { mSwitchEventArgs = null; } }
// Retrieve metadata public void OnCPReached(CurvySplineMoveEventArgs e) { mPossibleSwitchTarget = e.ControlPoint.GetMetadata <SplineRefMetadata>(); // if not properly configured, ignore! if (mPossibleSwitchTarget && !mPossibleSwitchTarget.Spline) { mPossibleSwitchTarget = null; } }
protected override void getData(CurvySplineMoveEventArgs e) { base.getData(e); if (e == null) { return; } if (!StoreControlPoint.IsNone) { StoreControlPoint.Value = e.ControlPoint; } }
/// <summary> /// Use a follow up, if present /// </summary> public static void UseFollowUpStatic(CurvySplineMoveEventArgs e) { // we need a SplineController as well as a following spline to work with if (e.Sender is SplineController && e.ControlPoint.FollowUp) { // Follow the connected spline e.Follow(e.ControlPoint.FollowUp, e.ControlPoint.FollowUpHeading); // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; // Handle controller events for the new passed ControlPoint controller.OnControlPointReached.Invoke(e); } }
protected virtual void getData(CurvySplineMoveEventArgs e) { if (e == null) { return; } if (!StoreSpline.IsNone) { StoreSpline.Value = e.Spline; } if (!StoreGameObject.IsNone) { StoreGameObject.Value = e.Spline.gameObject; } }
void onEndReachedEvent(CurvySplineMoveEventArgs e) { if (!(_active == this)) { return; } if (e.Spline && e.Spline != Spline) { e.Spline.OnMoveEndReached.RemoveListener(onEndReachedEvent); } else { e.Sender = this; OnEndReached.Invoke(e); } }
void OnCPReached(CurvySplineMoveEventArgs e) { var jc = e.ControlPoint.GetMetadata <MDJunctionControl>(); if (jc) { if (jc.UseJunction) { e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]); // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; } } }
// A: Use Head To/Follow Up ControlPoint to proceed // B: Start Falling if any Control Point connected // C: Else Die! public void UseFollowUpOrFall(CurvySplineMoveEventArgs e) { // we need a SplineController as well as a following spline to work with if (e.Sender is SplineController) { if (e.ControlPoint.FollowUp) { // Follow the connected spline e.Follow(e.ControlPoint.FollowUp, e.ControlPoint.FollowUpHeading); // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; // handle controller events for the new passed ControlPoint controller.OnControlPointReached.Invoke(e); } else { if (e.ControlPoint.Connection) { var otherCP = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]; mFreeFallTarget = otherCP.Spline; if (mMode == GuideMode.Jumping) { e.Follow(otherCP, ConnectionHeadingEnum.Auto); Spline = mFreeFallTarget; RelativePosition = otherCP.LocalFToTF(0); mNewMode = GuideMode.FreeFall; } else { mMode = GuideMode.FreeFall; } } else { Debug.Log("YOU DIED!"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } } }
/// <summary> /// Refresh the controller and advance position /// </summary> public override void Refresh() { if (IsSwitching) { mSwitchEventArgs.Delta = Mathf.Clamp01((Time.time - mSwitchStartTime) / mSwitchDuration); if (OnSwitch.HasListeners()) { onSwitchEvent(mSwitchEventArgs); } else { mSwitchEventArgs.Data = mSwitchEventArgs.Delta; } } base.Refresh(); if (IsSwitching) { Vector3 targetPos; Vector3 targetTan; Vector3 targetUp; getInterpolatedSourcePosition(mSwitchEventArgs.Spline, mSwitchEventArgs.TF, out targetPos, out targetTan, out targetUp); if (Space == Space.Self) { Transform.localPosition = Vector3.Lerp(Transform.localPosition, targetPos, (float)mSwitchEventArgs.Data); } else { Transform.position = Vector3.Lerp(Transform.localPosition, targetPos, (float)mSwitchEventArgs.Data); } if (OrientationMode != OrientationModeEnum.None) { //transform.localRotation = Quaternion.Lerp(transform.localRotation, GetRotation(tan, up), 1 - OrientationDamping); } if (mSwitchEventArgs.Delta == 1) { Spline = mSwitchEventArgs.Spline; RelativePosition = mSwitchEventArgs.TF; mSwitchEventArgs = null; } } }
public void UseRandomConnectionStatic(CurvySplineMoveEventArgs e) { // we need a SplineController as well as a connection to work with if (e.Sender is SplineController && e.ControlPoint.Connection) { CurvySplineSegment current = e.ControlPoint; // Find a new spline to follow: // Get all connected ControlPoints and check angle var others = e.ControlPoint.Connection.OtherControlPoints(current); // If it's smaller or equal 90°, consider the connected spline as a valid path to follow, otherwise remove it from the list for (int i = others.Count - 1; i >= 0; i--) { if (e.AngleTo(others[i]) > 90) { others.RemoveAt(i); } } int randomIndex = Random.Range(-1, others.Count); if (randomIndex < 0) // don't follow another, but use FollowUp if present { if (current.FollowUp) { e.Follow(current.FollowUp, current.FollowUpHeading); // Follow the connected spline } } else { e.Follow(others[randomIndex]); // Follow the new spline } // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; } }
public void UseRandomConnectionStatic(CurvySplineMoveEventArgs e) { // we need a SplineController as well as a connection to work with if (e.Sender is SplineController && e.ControlPoint.Connection) { CurvySplineSegment current = e.ControlPoint; // Find a new spline to follow: // Get all connected ControlPoints and check angle var others = e.ControlPoint.Connection.OtherControlPoints(current); // If it's smaller or equal 90°, consider the connected spline as a valid path to follow, otherwise remove it from the list for (int i = others.Count - 1; i >= 0; i--) { if (e.AngleTo(others[i]) > 90) others.RemoveAt(i); } int randomIndex = Random.Range(-1, others.Count); if (randomIndex < 0) // don't follow another, but use FollowUp if present { if (current.FollowUp) e.Follow(current.FollowUp, current.FollowUpHeading); // Follow the connected spline } else { e.Follow(others[randomIndex]); // Follow the new spline } // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; } }
// A: Use Head To/Follow Up ControlPoint to proceed // B: Start Falling if any Control Point connected // C: Else Die! public void UseFollowUpOrFall(CurvySplineMoveEventArgs e) { // we need a SplineController as well as a following spline to work with if (e.Sender is SplineController) { if (e.ControlPoint.FollowUp) { // Follow the connected spline e.Follow(e.ControlPoint.FollowUp, e.ControlPoint.FollowUpHeading); // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; // handle controller events for the new passed ControlPoint controller.OnControlPointReached.Invoke(e); } else { if (e.ControlPoint.Connection){ var otherCP=e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]; mFreeFallTarget = otherCP.Spline; if (mMode==GuideMode.Jumping) { e.Follow(otherCP, ConnectionHeadingEnum.Auto); Spline = mFreeFallTarget; RelativePosition = otherCP.LocalFToTF(0); mNewMode = GuideMode.FreeFall; } else mMode = GuideMode.FreeFall; } else { Debug.Log("YOU DIED!"); #if UNITY_EDITOR UnityEditor.EditorApplication.isPlaying = false; #else Application.Quit(); #endif } } } }
/// <summary> /// Print some event details to the console /// </summary> /// <param name="e"></param> public static void DebugLogStatic(CurvySplineMoveEventArgs e) { Debug.Log(string.Format("Segment/TF/Direction: {0}/{1}/{2}", e.ControlPoint, e.TF, e.Direction)); }
public static void DebugLog(CurvySplineMoveEventArgs e) { DebugLogStatic(e); }
public void UseRandomConnection(CurvySplineMoveEventArgs e) { UseRandomConnectionStatic(e); }
void onEndReachedEvent(CurvySplineMoveEventArgs e) { if (!(_active == this)) return; if (e.Spline && e.Spline != Spline) e.Spline.OnMoveEndReached.RemoveListener(onEndReachedEvent); else { e.Sender = this; OnEndReached.Invoke(e); } }
void OnCPReached(CurvySplineMoveEventArgs e) { var jc = e.ControlPoint.GetMetadata<MDJunctionControl>(); if (jc) { if (jc.UseJunction) { e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]); // Set the controller to use the new spline SplineController controller = (SplineController)e.Sender; controller.Spline = e.Spline; controller.RelativePosition = e.TF; } } }
public void UseFollowUp(CurvySplineMoveEventArgs e) { UseFollowUpStatic(e); }
/// <summary> /// Refresh the controller and advance position /// </summary> public override void Refresh() { if (IsSwitching) { mSwitchEventArgs.Delta = Mathf.Clamp01((Time.time - mSwitchStartTime) / mSwitchDuration); if (OnSwitch.HasListeners()) onSwitchEvent(mSwitchEventArgs); else mSwitchEventArgs.Data = mSwitchEventArgs.Delta; } base.Refresh(); if (IsSwitching) { Vector3 targetPos; Vector3 targetTan; Vector3 targetUp; getInterpolatedSourcePosition(mSwitchEventArgs.Spline, mSwitchEventArgs.TF, out targetPos, out targetTan, out targetUp); if (Space == Space.Self) transform.localPosition = Vector3.Lerp(transform.localPosition, targetPos, (float)mSwitchEventArgs.Data); else transform.position = Vector3.Lerp(transform.localPosition, targetPos, (float)mSwitchEventArgs.Data); if (OrientationMode != OrientationModeEnum.None) { //transform.localRotation = Quaternion.Lerp(transform.localRotation, GetRotation(tan, up), 1 - OrientationDamping); } if (mSwitchEventArgs.Delta == 1) { Spline = mSwitchEventArgs.Spline; RelativePosition = mSwitchEventArgs.TF; mSwitchEventArgs = null; } } }
// Retrieve metadata public void OnCPReached(CurvySplineMoveEventArgs e) { mPossibleSwitchTarget = e.ControlPoint.GetMetadata<SplineRefMetadata>(); // if not properly configured, ignore! if (mPossibleSwitchTarget && !mPossibleSwitchTarget.Spline) mPossibleSwitchTarget = null; }
void onSwitchEvent(CurvySplineMoveEventArgs e) { OnSwitch.Invoke(e); if (e.Cancel) mSwitchEventArgs = null; }