private IEnumerator InitToTrack() { if (track != null) { ChildTransformData[] childTransformData = GetChildTransforms(); track.Connect(this); if (retainOriginalTransform) { track.SnapToTrack(this, true); SetChildTransforms(childTransformData); yield return(new WaitForEndOfFrame()); } if (setOnStart) { track.SetPositionAlong(trackValueOnStart, this); } else { track.SnapToTrack(this, true); } trackValue = track.GetDecimalAlong(this); } }
protected override void Awake() { base.Awake(); if (_rigidbody) { SetGravity(true); } if (GetComponent <SphereCollider>()) { colliderRadius = GetComponent <SphereCollider>().radius *transform.localScale.x; } if (track != null) { track.Connect(this); if (setOnStart) { track.SetPositionAlong(trackValueOnStart, this); } else { track.SnapToTrack(this, true); } trackValue = track.GetDecimalAlong(this); } }
/** * <summary>Forces the object to move along a DragTrack without the player's direct input.</summary> * <param name = "_targetTrackValue">The intended proportion along the track to send the object to</param> * <param name = "_targetTrackSpeed">The intended speed to move the object by</param> * <param name = "removePlayerControl">If True and the player is currently moving the object, then player control will be removed</param> * <param name = "layerMask">A LayerMask that determines what collisions will cause the automatic movement to cease</param> * <param name = "snapID">The ID number of the associated snap, if snapping</param> */ public void AutoMoveAlongTrack(float _targetTrackValue, float _targetTrackSpeed, bool removePlayerControl, LayerMask layerMask, int snapID = -1) { if (dragMode == DragMode.LockToTrack && track != null) { if (snapID < 0) { canCallSnapEvents = true; } if (_targetTrackSpeed <= 0f) { activeAutoMove = null; track.SetPositionAlong(_targetTrackValue, this); return; } if (removePlayerControl) { isHeld = false; } activeAutoMove = new AutoMoveTrackData(_targetTrackValue, _targetTrackSpeed / 6000f, layerMask, snapID); } else { ACDebug.LogWarning("Cannot move " + this.name + " along a track, because no track has been assigned to it", this); } }
public void Stop(DragTrack track, Moveable_Drag draggable, bool snapToTarget) { if (snapToTarget) { track.SetPositionAlong(targetValue, draggable); } }
/** * <summary>Snaps the object to a track at a given position along it</summary> * <param name="newTrack">The new DragTrack to snap to</param> * <param name="positionAlong">How far along the track, as a decimal of its length, to snap to</param> */ public void SnapToTrack(DragTrack newTrack, float positionAlong) { if (newTrack == null) { return; } if (track && newTrack != track) { track.OnDisconnect(this); } dragMode = DragMode.LockToTrack; if (IsAutoMoving()) { activeAutoMove.Stop(track, this, true); activeAutoMove = null; } track = newTrack; track.SetPositionAlong(positionAlong, this); if (_rigidbody) { _rigidbody.velocity = Vector3.zero; _rigidbody.angularVelocity = Vector3.zero; } }
private void Start() { if (track != null) { track.Connect(this); if (setOnStart) { track.SetPositionAlong(trackValueOnStart, this); } else { track.SnapToTrack(this, true); } trackValue = track.GetDecimalAlong(this); } }