private void DrawTrackRegions(TrackSnapData trackSnapData, DragTrack_Hinge hingeTrack) { float minPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong - trackSnapData.Width); float maxPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong + trackSnapData.Width); Quaternion rot = Quaternion.AngleAxis(hingeTrack.MaxAngle * trackSnapData.PositionAlong, hingeTrack.transform.forward); Vector3 endUp = RotatePointAroundPivot(hingeTrack.transform.up, Vector3.zero, rot); Handles.color = trackSnapData.GizmoColor; Vector3 positionAlongWorld = hingeTrack.GetGizmoPosition(trackSnapData.PositionAlong); Handles.DrawSolidDisc(positionAlongWorld, endUp, hingeTrack.discSize / 2f); rot = Quaternion.AngleAxis(hingeTrack.MaxAngle * minPositionAlong, hingeTrack.transform.forward); endUp = RotatePointAroundPivot(hingeTrack.transform.right, Vector3.zero, rot); Handles.DrawWireArc(hingeTrack.transform.position, hingeTrack.transform.forward, endUp, hingeTrack.MaxAngle * (maxPositionAlong - minPositionAlong), hingeTrack.radius); Quaternion minRot = Quaternion.AngleAxis(hingeTrack.MaxAngle * minPositionAlong, hingeTrack.transform.forward); endUp = RotatePointAroundPivot(hingeTrack.transform.up, Vector3.zero, minRot); Vector3 minPositionAlongWorld = hingeTrack.GetGizmoPosition(minPositionAlong); Handles.DrawSolidDisc(minPositionAlongWorld, endUp, hingeTrack.discSize / 4f); Quaternion maxRot = Quaternion.AngleAxis(hingeTrack.MaxAngle * maxPositionAlong, hingeTrack.transform.forward); endUp = RotatePointAroundPivot(hingeTrack.transform.up, Vector3.zero, maxRot); Vector3 maxPositionAlongWorld = hingeTrack.GetGizmoPosition(maxPositionAlong); Handles.DrawSolidDisc(maxPositionAlongWorld, endUp, hingeTrack.discSize / 4f); }
/** * <summary>Connects a draggable object to the track defined in this data block</summary> * <param name="draggable">The draggable object to update</param> */ public void MakeConnection(Moveable_Drag draggable) { // First need to decide which snap point on the connectedTrack is closest to the draggable TrackSnapData winningSnap = null; float winningDistance = Mathf.Infinity; foreach (TrackSnapData trackSnapData in connectedTrack.allTrackSnapData) { if (!trackSnapData.IsEnabled) { continue; } Vector3 snapWorldPosition = trackSnapData.GetWorldPosition(connectedTrack); float sqrDist = (snapWorldPosition - draggable.Transform.position).sqrMagnitude; if (sqrDist < winningDistance) { winningDistance = sqrDist; winningSnap = trackSnapData; } } if (winningSnap != null) { draggable.SnapToTrack(connectedTrack, winningSnap.ID); } }
public void DrawHandles(Vector3 ownPosition) { if (connectedTrack) { TrackSnapData winningSnap = null; float winningDistance = Mathf.Infinity; foreach (TrackSnapData trackSnapData in connectedTrack.allTrackSnapData) { Vector3 snapWorldPosition = trackSnapData.GetWorldPosition(connectedTrack); float sqrDist = (snapWorldPosition - ownPosition).sqrMagnitude; if (sqrDist < winningDistance) { winningDistance = sqrDist; winningSnap = trackSnapData; } } if (winningSnap != null) { float connectedPositionAlong = connectedTrack.GetRegionPositionAlong(winningSnap.ID); Vector3 worldPosition = connectedTrack.GetGizmoPosition(connectedPositionAlong); Handles.DrawDottedLine(ownPosition, worldPosition, 4f); } } }
public void SnapDataGUI(DragTrack _target, bool useAngles) { CustomGUILayout.BeginVertical(); EditorGUILayout.LabelField("Track regions", EditorStyles.boldLabel); for (int i = 0; i < _target.allTrackSnapData.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Region " + _target.allTrackSnapData[i].ID.ToString()); GUILayout.FlexibleSpace(); if (GUILayout.Button("-")) { Undo.RecordObject(this, "Delete region"); _target.allTrackSnapData.RemoveAt(i); i = -1; break; } EditorGUILayout.EndHorizontal(); _target.allTrackSnapData[i] = _target.allTrackSnapData[i].ShowGUI(_target, useAngles); EditorGUILayout.Space(); if (i < _target.allTrackSnapData.Count - 1) { GUILayout.Box(string.Empty, GUILayout.ExpandWidth(true), GUILayout.Height(1)); } } if (GUILayout.Button("Create new track region")) { Undo.RecordObject(this, "Create track region"); TrackSnapData trackSnapData = new TrackSnapData(0f, GetSnapIDArray(_target.allTrackSnapData)); _target.allTrackSnapData.Add(trackSnapData); } CustomGUILayout.EndVertical(); if (_target.allTrackSnapData.Count > 0) { CustomGUILayout.BeginVertical(); EditorGUILayout.LabelField("Snapping", EditorStyles.boldLabel); _target.doSnapping = CustomGUILayout.Toggle("Enable region snapping?", _target.doSnapping, string.Empty, "If True, then snapping is enabled and any object attached to the track can snap to pre-set regions along it when let go by the player"); if (_target.doSnapping) { _target.snapSpeed = CustomGUILayout.FloatField("Snap speed:", _target.snapSpeed, string.Empty, "The speed to move by when attached objects snap"); _target.onlySnapOnPlayerRelease = CustomGUILayout.Toggle("Only snap on release?", _target.onlySnapOnPlayerRelease, string.Empty, "If True, then snapping will only occur when the player releases the object - and not when moving on its own accord"); _target.actionListSource = (ActionListSource)CustomGUILayout.EnumPopup("ActionList source:", _target.actionListSource, string.Empty, "The source of ActionLists that can be run when a draggable option snaps to a region."); } CustomGUILayout.EndVertical(); } UnityVersionHandler.CustomSetDirty(_target); }
private void DrawSnapHandles(TrackSnapData trackSnapData, DragTrack_Straight _target) { float minPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong - trackSnapData.Width); float maxPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong + trackSnapData.Width); Handles.color = trackSnapData.GizmoColor; Handles.DrawSolidDisc(_target.GetGizmoPosition(trackSnapData.PositionAlong), _target.transform.up, _target.discSize / 2f); Handles.DrawSolidDisc(_target.GetGizmoPosition(minPositionAlong), _target.transform.up, _target.discSize / 4f); Handles.DrawSolidDisc(_target.GetGizmoPosition(maxPositionAlong), _target.transform.up, _target.discSize / 4f); Handles.DrawLine(_target.GetGizmoPosition(minPositionAlong), _target.GetGizmoPosition(maxPositionAlong)); }
public override float Run() { if (runtimeTrack) { TrackSnapData snapData = track.GetSnapData(trackRegionID); if (snapData != null) { snapData.IsEnabled = enable; } } return(0f); }
private void DrawTrackRegions(TrackSnapData trackSnapData, DragTrack_Straight straightTrack) { float minPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong - trackSnapData.Width); float maxPositionAlong = Mathf.Clamp01(trackSnapData.PositionAlong + trackSnapData.Width); Handles.color = trackSnapData.GizmoColor; Handles.DrawSolidDisc(straightTrack.GetGizmoPosition(trackSnapData.PositionAlong), straightTrack.transform.up, straightTrack.discSize / 2f); Handles.DrawSolidDisc(straightTrack.GetGizmoPosition(minPositionAlong), straightTrack.transform.up, straightTrack.discSize / 4f); Handles.DrawSolidDisc(straightTrack.GetGizmoPosition(maxPositionAlong), straightTrack.transform.up, straightTrack.discSize / 4f); Handles.DrawLine(straightTrack.GetGizmoPosition(minPositionAlong), straightTrack.GetGizmoPosition(maxPositionAlong)); trackSnapData.DrawConnectionHandles(straightTrack); }
public override void LoadData(string stringData) { TrackData data = Serializer.LoadScriptData <TrackData> (stringData); if (data == null) { return; } SavePrevented = data.savePrevented; if (savePrevented) { return; } DragTrack track = GetComponent <DragTrack>(); if (track && track.allTrackSnapData != null) { string[] valuesArray = data.enabledStates.Split(SaveSystem.pipe[0]); for (int i = 0; i < track.allTrackSnapData.Count; i++) { if (i < valuesArray.Length) { string[] chunkData = valuesArray[i].Split(SaveSystem.colon[0]); if (chunkData != null && chunkData.Length == 2) { int _regionID = 0; if (int.TryParse(chunkData[0], out _regionID)) { TrackSnapData snapData = track.GetSnapData(_regionID); if (snapData != null) { int _isEnabled = 1; if (int.TryParse(chunkData[1], out _isEnabled)) { snapData.IsEnabled = (_isEnabled == 1); } } } } } } } }
public bool CheckForEnd(Moveable_Drag draggable, bool beAccurate = true) { float currentValue = draggable.trackValue; if (draggable.track.Loops) { if (targetValue - currentValue > 0.5f) { currentValue += 1f; } else if (currentValue - targetValue > 0.5f) { currentValue -= 1f; } } float diff = Mathf.Abs(targetValue - currentValue); if (diff < 0.01f) { if (draggable.canCallSnapEvents && snapID >= 0) { TrackSnapData snapData = draggable.track.GetSnapData(snapID); if (snapData.IsEnabled) { snapData.RunSnapCutscene(draggable.track.actionListSource); KickStarter.eventManager.Call_OnDraggableSnap(draggable, draggable.track, snapData); draggable.canCallSnapEvents = false; } } if (!beAccurate) { return(true); } } if (diff < 0.001f) { return(true); } return(false); }
public void SnapDataGUI(DragTrack _target, bool useAngles) { EditorGUILayout.BeginVertical("Button"); EditorGUILayout.LabelField("Snapping", EditorStyles.boldLabel); _target.doSnapping = CustomGUILayout.Toggle("Enable snapping?", _target.doSnapping, "", "If True, then snapping is enabled and any object attached to the track can snap to pre-set points along it when let go by the player"); if (_target.doSnapping) { _target.snapSpeed = CustomGUILayout.FloatField("Snap speed:", _target.snapSpeed, "", "The speed to move by when attached objects snap"); _target.onlySnapOnPlayerRelease = CustomGUILayout.ToggleLeft("Only snap on player release?", _target.onlySnapOnPlayerRelease, "", "If True, then snapping will only occur when the player releases the object - and not when moving on its own accord"); for (int i = 0; i < _target.allTrackSnapData.Count; i++) { GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1)); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Snap " + _target.allTrackSnapData[i].ID.ToString()); GUILayout.FlexibleSpace(); if (GUILayout.Button("-")) { Undo.RecordObject(this, "Delete snap point"); _target.allTrackSnapData.RemoveAt(i); i = -1; break; } EditorGUILayout.EndHorizontal(); _target.allTrackSnapData[i] = _target.allTrackSnapData[i].ShowGUI(useAngles); EditorGUILayout.Space(); } if (GUILayout.Button("Create new snap point")) { Undo.RecordObject(this, "Create snap point"); TrackSnapData trackSnapData = new TrackSnapData(0f, GetSnapIDArray(_target.allTrackSnapData)); _target.allTrackSnapData.Add(trackSnapData); } } EditorGUILayout.EndVertical(); UnityVersionHandler.CustomSetDirty(_target); }