public override void OnInspectorGUI() { base.OnInspectorGUI(); spline = (SplineComputer)target; Undo.RecordObject(spline, "Edit Points"); if (splines.Length == 1) { SplineEditorGUI.BeginContainerBox(ref pathEditor.open, "Edit"); if (pathEditor.open) { pathEditor.DrawInspector(); } else if (pathEditor.lastEditorTool != Tool.None && Tools.current == Tool.None) { Tools.current = pathEditor.lastEditorTool; } SplineEditorGUI.EndContainerBox(); } SplineEditorGUI.BeginContainerBox(ref computerEditor.open, "Spline Computer"); if (computerEditor.open) { computerEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); if (splines.Length == 1) { SplineEditorGUI.BeginContainerBox(ref triggersEditor.open, "Triggers"); if (triggersEditor.open) { triggersEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); SplineEditorGUI.BeginContainerBox(ref debugEditor.open, "Info & Debug"); if (debugEditor.open) { debugEditor.DrawInspector(); } SplineEditorGUI.EndContainerBox(); } if (GUI.changed) { if (spline.isClosed) { pathEditor.points[pathEditor.points.Length - 1] = pathEditor.points[0]; } EditorUtility.SetDirty(spline); } }
public void EnterSplineSegment(int previousSplineExitPoint, SplineComputer spline, int entryPoint, Spline.Direction direction) { if (!isEngine) { return; } if (back != null) { segment.end = previousSplineExitPoint; back.segment = segment; } segment = new SplineSegment(spline, entryPoint, direction); }
protected virtual void OnSceneGUI() { if (doRebuild) { DoRebuild(); } SplineUser user = (SplineUser)target; if (user == null) { return; } if (user.spline != null) { SplineComputer rootComputer = user.GetComponent <SplineComputer>(); List <SplineComputer> allComputers = user.spline.GetConnectedComputers(); for (int i = 0; i < allComputers.Count; i++) { if (allComputers[i] == rootComputer && _editIndex == -1) { continue; } if (allComputers[i].alwaysDraw) { continue; } DSSplineDrawer.DrawSplineComputer(allComputers[i], 0.0, 1.0, 0.4f); } DSSplineDrawer.DrawSplineComputer(user.spline); } if (_editIndex == 0) { SceneClipEdit(); } if (offsetModifierEditor != null) { offsetModifierEditor.DrawScene(); } if (rotationModifierEditor != null) { rotationModifierEditor.DrawScene(); } if (colorModifierEditor != null) { colorModifierEditor.DrawScene(); } if (sizeModifierEditor != null) { sizeModifierEditor.DrawScene(); } }
private void OnDrawGizmosSelected() { if (_spline == null) { _spline = GetComponent <SplineComputer>(); } var points = _spline.GetPoints(); for (var i = 0; i < points.Length; i++) { var point = _spline.Evaluate(i); Gizmos.color = Color.black; Gizmos.DrawSphere(point.position, 0.1f); if (showUp) { Gizmos.color = Color.green; Gizmos.DrawLine(point.position, point.position + point.normal * _length); } if (showForward) { Gizmos.color = Color.blue; Gizmos.DrawLine(point.position, point.position + point.direction * _length); } if (showRight) { Gizmos.color = Color.red; Gizmos.DrawLine(point.position, point.position + point.right * _length); if (showXz) { var r = point.right; r.y = 0f; Gizmos.DrawLine(point.position, point.position + r * _length); } } if (i > 0) { var point2 = _spline.Evaluate(i - 1); if (showUp) { Gizmos.color = Color.green; Gizmos.DrawLine(point2.position + point2.normal * _length, point.position + point.normal * _length); } if (showRight) { Gizmos.color = Color.red; Gizmos.DrawLine(point2.position + point2.right * _length, point.position + point.right * _length); } } } }
public SplineComputer CalculateMainRailway() { Debug.Log("<color=red>CalculateMainRailway</color>"); mainRailway = allRailways[0]; foreach (var railway in allRailways) { if (railway.CalculateLength() > mainRailway.CalculateLength()) { mainRailway = railway; } } return(mainRailway); }
List <SplineComputer> GetSelectedSplines() { List <SplineComputer> selected = new List <SplineComputer>(); foreach (GameObject obj in Selection.gameObjects) { SplineComputer comp = obj.GetComponent <SplineComputer>(); if (comp != null) { selected.Add(comp); } } return(selected); }
int[] GetAvailablePoints(SplineComputer computer) { List <int> indices = new List <int>(); for (int i = 0; i < computer.pointCount; i++) { if (computer.GetNode(i) != null) { continue; } indices.Add(i); } return(indices.ToArray()); }
public void Initialize(Transform enemyTransform) { _center = new Vector3(Screen.width / 2, Screen.height / 2); _followTransform = enemyTransform; _myT = GetComponent <RectTransform>(); _isWorking = true; _playerT = DataHolder.GetCurrentPlayer().transform; _myImage = GetComponent <Image>(); _spline = DataHolder.GetSplineComputer(); _cam = Camera.main; _canvas = GetComponentInParent <Canvas>().GetComponent <RectTransform>(); _renderer = _followTransform.GetComponentInChildren <Renderer>(); Finish.OnPlayerCrossFinish += DisableArrow; }
public bool IsCurrentSpline(SplineComputer p_spline) { int num = 0; if (num < this.m_ChildSMs.Count) { return(this.m_ChildSMs[num].IsCurrentSpline(p_spline)); } if (this.m_State == null) { return(false); } return(this.m_State.IsCurrentSpline(p_spline)); }
public void GetReferences() { if (transform == null) { Debug.LogError("Null transform found for property"); return; } settingsComponent = transform.GetComponent <SegmentObjectSettings>(); meshFilter = transform.GetComponent <MeshFilter>(); spriteRenderer = transform.GetComponent <SpriteRenderer>(); if (spriteRenderer == null || spriteRenderer.sprite == null) { extrusionSettings.bendSprite = false; } if (extrusionSettings.bendMesh && meshFilter.sharedMesh == null) { extrusionSettings.bendMesh = false; } colliders = transform.GetComponents <Collider>(); for (int i = 0; i < colliders.Length; i++) { if (colliders[i] is MeshCollider) { meshCollider = (MeshCollider)colliders[i]; break; } } localRotation = Quaternion.Inverse(transform.root.rotation) * transform.rotation; #if DREAMTECK_SPLINES if (extrusionSettings.bendSpline) { if (!isRoot) { splineComputer = transform.GetComponent <SplineComputer>(); if (splineComputer != null) { editSplinePoints = splineComputer.GetPoints(); } else { extrusionSettings.bendSpline = false; } } else { extrusionSettings.bendSpline = false; } } #endif }
public ComputerEditor(SplineComputer[] splines, SerializedObject serializedObject, DreamteckSplinesEditor pathEditor) : base() { spline = splines[0]; this.splines = splines; this.pathEditor = pathEditor; this.serializedObject = serializedObject; modules = new ComputerEditorModule[2]; modules[0] = new ComputerMergeModule(spline); modules[1] = new ComputerSplitModule(spline); GUIContent[] utilityContents = new GUIContent[modules.Length], utilityContentsSelected = new GUIContent[modules.Length]; for (int i = 0; i < modules.Length; i++) { utilityContents[i] = modules[i].GetIconOff(); utilityContentsSelected[i] = modules[i].GetIconOn(); modules[i].undoHandler += OnRecordUndo; modules[i].repaintHandler += OnRepaint; } utilityToolbar = new Dreamteck.Editor.Toolbar(utilityContents, utilityContentsSelected, 35f); utilityToolbar.newLine = false; int index = 0; GUIContent[] transformContents = new GUIContent[4], transformContentsSelected = new GUIContent[4]; transformContents[index] = new GUIContent("OFF"); transformContentsSelected[index++] = new GUIContent("OFF"); transformContents[index] = EditorGUIUtility.IconContent("MoveTool"); transformContentsSelected[index++] = EditorGUIUtility.IconContent("MoveTool On"); transformContents[index] = EditorGUIUtility.IconContent("RotateTool"); transformContentsSelected[index++] = EditorGUIUtility.IconContent("RotateTool On"); transformContents[index] = EditorGUIUtility.IconContent("ScaleTool"); transformContentsSelected[index] = EditorGUIUtility.IconContent("ScaleTool On"); transformToolbar = new Dreamteck.Editor.Toolbar(transformContents, transformContentsSelected, 35f); transformToolbar.newLine = false; index = 0; GUIContent[] operationContents = new GUIContent[3], operationContentsSelected = new GUIContent[3]; for (int i = 0; i < operationContents.Length; i++) { operationContents[i] = new GUIContent(""); operationContentsSelected[i] = new GUIContent(""); } operationsToolbar = new Dreamteck.Editor.Toolbar(operationContents, operationContentsSelected, 64f); operationsToolbar.newLine = false; }
Vector3 GetOrigin(SplineComputer comp) { Vector3 avg = Vector3.zero; SplinePoint[] points = comp.GetPoints(SplineComputer.Space.Local); for (int i = 0; i < comp.pointCount; i++) { avg += points[i].position; } if (points.Length > 0) { avg /= points.Length; } return(avg); }
public void UpdateSplineComputer(SplineComputer comp) { Generate(); ApplyOffset(); comp.type = GetSplineType(); comp.SetPoints(points, SplineComputer.Space.Local); if (closed) { comp.Close(); } else if (comp.isClosed) { comp.Break(); } }
protected override void OnSplineRemoved(SplineComputer spline) { base.OnSplineRemoved(spline); for (int i = 0; i < collections.Count; i++) { if (collections[i].spline == spline) { collections[i].Clear(); collections.RemoveAt(i); spline.onRebuild -= Rebuild; Rebuild(); return; } } }
void OnSceneGUI() { spline = (SplineComputer)target; debugEditor.DrawScene(); computerEditor.drawComputer = !(pathEditor.currentModule is CreatePointModule); computerEditor.DrawScene(); if (splines.Length == 1 && triggersEditor.open) { triggersEditor.DrawScene(); } if (splines.Length == 1 && pathEditor.open) { pathEditor.DrawScene(); } }
// Use this for initialization void Start() { if (source == null) { source = GetComponent <AudioSource>(); } computer = GetComponent <SplineComputer>(); SplinePoint[] points = computer.GetPoints(); positions = new Vector3[points.Length]; for (int i = 0; i < points.Length; i++) { positions[i] = points[i].position; } spectrumLerp = new float[points.Length]; }
/// <summary> /// Sets up all protected parameters. /// </summary> /// <param name="parent"> Object in the scene (called RuntimeRows) that is a parent to all generated rows of elements. </param> protected void SetupNet(Transform parent) { knotClone = GameObject.Find("KnotForNet"); UpdateKnot(); knotClone.transform.parent = parent; knotClone.tag = "knotrow"; knotClone.layer = 9; splineComputer = knotClone.GetComponent <SplineComputer>(); basePoints = splineComputer.GetPoints(); basePointCount = basePoints.Length; currentPointCount = basePointCount; point_size = splineComputer.GetPointSize(0); updateValues = false; }
public SplineComputer CreateSplineComputer(string name, Vector3 position, Quaternion rotation) { Generate(); ApplyOffset(); GameObject go = new GameObject(name); SplineComputer comp = go.AddComponent <SplineComputer>(); comp.SetPoints(points, SplineComputer.Space.Local); if (closed) { comp.Close(); } comp.transform.position = position; comp.transform.rotation = rotation; return(comp); }
protected override void InsertMode(Vector3 screenCoordinates) { base.InsertMode(screenCoordinates); double percent = ProjectScreenSpace(screenCoordinates); editor.evaluate(percent, evalResult); if (editor.eventModule.mouseRight) { SplineEditorHandles.DrawCircle(evalResult.position, Quaternion.LookRotation(editorCamera.transform.position - evalResult.position), HandleUtility.GetHandleSize(evalResult.position) * 0.2f); return; } if (SplineEditorHandles.CircleButton(evalResult.position, Quaternion.LookRotation(editorCamera.transform.position - evalResult.position), HandleUtility.GetHandleSize(evalResult.position) * 0.2f, 1.5f, color)) { RecordUndo("Create Point"); SplinePoint newPoint = new SplinePoint(evalResult.position, evalResult.position); newPoint.size = evalResult.size; newPoint.color = evalResult.color; newPoint.normal = evalResult.up; SplinePoint[] newPoints = new SplinePoint[points.Length + 1]; double floatIndex = (points.Length - 1) * percent; int pointIndex = Mathf.Clamp(DMath.FloorInt(floatIndex), 0, points.Length - 2); for (int i = 0; i < newPoints.Length; i++) { if (i <= pointIndex) { newPoints[i] = points[i]; } else if (i == pointIndex + 1) { newPoints[i] = newPoint; } else { newPoints[i] = points[i - 1]; } } SplineComputer spline = dsEditor.spline; points = newPoints; lastCreated = points.Length - 1; dsEditor.UpdateSpline(); spline.ShiftNodes(pointIndex + 1, spline.pointCount - 1, 1); if (createNode) { CreateNodeForPoint(pointIndex + 1); } } }
public SplineComputer CreateSplineComputer(string name, Vector3 position, Quaternion rotation) { Generate(); ApplyOffset(); GameObject gameObject = new GameObject(name); SplineComputer splineComputer = gameObject.AddComponent <SplineComputer>(); splineComputer.type = type; splineComputer.SetPoints(points, SplineComputer.Space.Local); if (closed) { splineComputer.Close(); } splineComputer.transform.position = position; splineComputer.transform.rotation = rotation; return(splineComputer); }
void ApplyOffset() { if (isEngine) { ResetSegments(); return; } float totalMoved = 0f, moved = 0f; double start = front.tracer.UnclipPercent(front.tracer.result.percent); //Travel backwards along the front wagon's spline Spline.Direction inverseDirection = front.segment.direction; InvertDirection(ref inverseDirection); SplineComputer spline = front.segment.spline; double percent = front.segment.Travel(start, offset, inverseDirection, out moved, front.segment.spline.isClosed); totalMoved += moved; //Finalize if moved fully without reaching a spline end or a junction if (Mathf.Approximately(totalMoved, offset)) { if (segment != front.segment) { if (back != null) { back.segment = segment; } } if (segment != front.segment) { segment = front.segment; } ApplyTracer(spline, percent, front.tracer.direction); return; } //Otherwise, move along the current recorded spline segment if (segment != front.segment) { inverseDirection = segment.direction; InvertDirection(ref inverseDirection); spline = segment.spline; percent = segment.Travel(offset - totalMoved, inverseDirection, out moved, segment.spline.isClosed); totalMoved += moved; } ApplyTracer(spline, percent, segment.direction); }
private IEnumerator SplineFollowWithDelay(SplineComputer sc) { float delay = splineFollowFirstCartStartDelay; foreach (SplineFollower sf in splineFollowers) { /* Set the spline computer to the new spline */ sf.computer = sc; /* Turn autoFollow back on and restart the follow */ sf.autoFollow = true; sf.Restart(); /* Wait before starting the next cart */ yield return(new WaitForSeconds(delay / sf.followSpeed)); delay = splineFollowOtherCartStartDelay; } }
private void RecalculateGrindTriggers(GameObject go) { foreach (Transform transform in go.GetComponentsInChildren <Transform>()) { if (transform.name.Contains("GrindSpline") && !transform.name.Contains("Colliders")) { Transform grindColliders = go.transform.Find(transform.name + "Colliders").transform; Vector3[] grindPoints = new Vector3[transform.childCount]; SplinePoint[] splinePoints = new SplinePoint[grindPoints.Length]; for (int i = 0; i < grindPoints.Length; i++) { grindPoints[i] = transform.GetChild(i).position; splinePoints[i] = new SplinePoint(grindPoints[i]); } SplineComputer splineComputer = grindColliders.gameObject.GetComponent <SplineComputer>(); Vector3[] grindNormals = new Vector3[grindPoints.Length]; for (int i = 0; i < grindPoints.Length - 1; i++) { GameObject grindCollider = grindColliders.Find("RailCol" + i).gameObject; grindCollider.transform.position = grindPoints[i]; grindCollider.transform.LookAt(grindPoints[i + 1]); BoxCollider boxCollider = grindCollider.GetComponent <BoxCollider>(); float segmentLength = Vector3.Distance(grindPoints[i], grindPoints[i + 1]); boxCollider.size = new Vector3(0.08f / go.transform.lossyScale.x, 0.08f / go.transform.lossyScale.y, segmentLength); boxCollider.center = Vector3.forward * segmentLength / 2f; grindNormals[i] = grindCollider.transform.up; } grindNormals[grindNormals.Length - 1] = grindNormals[grindNormals.Length - 2]; splineComputer.SetPoints(splinePoints); splineComputer.Evaluate(0.9); for (int i = 0; i < grindPoints.Length; i++) { splineComputer.SetPointNormal(i, splineComputer.GetPointNormal(i, SplineComputer.Space.World) + grindNormals[i], SplineComputer.Space.World); } } if (transform.name.Contains("GrindCollider")) { transform.localScale = new Vector3(1f / go.transform.lossyScale.x, 1f / go.transform.lossyScale.y, 1f); } } }
void SplitAtPercent(double percent) { RecordUndo("Split Spline"); float pointValue = (spline.pointCount - 1) * (float)percent; int lastPointIndex = Mathf.FloorToInt(pointValue); int nextPointIndex = Mathf.CeilToInt(pointValue); SplinePoint[] splitPoints = new SplinePoint[spline.pointCount - lastPointIndex]; float lerpPercent = Mathf.InverseLerp(lastPointIndex, nextPointIndex, pointValue); SplinePoint splitPoint = SplinePoint.Lerp(spline.GetPoint(lastPointIndex), spline.GetPoint(nextPointIndex), lerpPercent); splitPoint.SetPosition(spline.EvaluatePosition(percent)); splitPoints[0] = splitPoint; for (int i = 1; i < splitPoints.Length; i++) { splitPoints[i] = spline.GetPoint(lastPointIndex + i); } SplineComputer newSpline = CreateNewSpline(); newSpline.SetPoints(splitPoints); HandleNodes(newSpline, lastPointIndex); SplineUser[] users = newSpline.GetSubscribers(); for (int i = 0; i < users.Length; i++) { users[i].clipFrom = DMath.InverseLerp(percent, 1.0, users[i].clipFrom); users[i].clipTo = DMath.InverseLerp(percent, 1.0, users[i].clipTo); } splitPoints = new SplinePoint[lastPointIndex + 2]; for (int i = 0; i <= lastPointIndex; i++) { splitPoints[i] = spline.GetPoint(i); } splitPoints[splitPoints.Length - 1] = splitPoint; spline.SetPoints(splitPoints); users = spline.GetSubscribers(); for (int i = 0; i < users.Length; i++) { users[i].clipFrom = DMath.InverseLerp(0.0, percent, users[i].clipFrom); users[i].clipTo = DMath.InverseLerp(0.0, percent, users[i].clipTo); } }
public CSV(SplineComputer computer) { Spline spline = new Spline(computer.type, computer.sampleRate); spline.points = computer.GetPoints(); if (spline.type != Spline.Type.Bezier && spline.type != Spline.Type.Linear) { spline.CatToBezierTangents(); } if (computer.isClosed) { spline.Close(); } buffer = new SplineDefinition(computer.name, spline); fileName = computer.name; columns.Add(ColumnType.Position); columns.Add(ColumnType.Tangent); columns.Add(ColumnType.Tangent2); }
public SplineCompEditor(SplineComputer[] splines, SerializedObject serializedObject, DreamteckSplinesEditor pathEditor) : base() { spline = splines[0]; this.splines = splines; this.pathEditor = pathEditor; this.serializedObject = serializedObject; modules = new ComputerEditorModule[2]; modules[0] = new ComputerMergeModule(spline); modules[1] = new ComputerSplitModule(spline); GUIContent[] toolbarContents = new GUIContent[modules.Length], toolbarContentsSelected = new GUIContent[modules.Length]; for (int i = 0; i < modules.Length; i++) { toolbarContents[i] = modules[i].GetIconOff(); toolbarContentsSelected[i] = modules[i].GetIconOn(); modules[i].undoHandler += OnRecordUndo; modules[i].repaintHandler += OnRepaint; } toolbar = new Dreamteck.Editor.Toolbar(toolbarContents, toolbarContentsSelected, 35f); toolbar.newLine = false; }
public static bool BuildSplineComputer(GrindSegment segment) { // Create Spline Computer component and settings for GrindSpline Object SplineComputer sc = segment.grindRoot.gameObject.AddComponent <SplineComputer>(); sc.type = Spline.Type.Linear; sc.SetPoints(segment.points, SplineComputer.Space.World); sc.Evaluate(0.9); // Shift normal vectors up a position for spline points points segment.normals[segment.normals.Length - 1] = segment.normals[segment.normals.Length - 2]; // Set point normals for (int i = 0; i < segment.points.Length; i++) { sc.SetPointNormal(i, sc.GetPoint(i, SplineComputer.Space.World).normal + segment.normals[i], SplineComputer.Space.World); } return(true); }
public bool AddConnector(SplineComputer spline, int start_offset, int end_offset) { var index = connectorList.FindIndex(con => con.spline.name == spline.name); if (index != -1) { CreatePathManager.DestroySpline(connectorList[index].spline); connectorList[index].spline = spline; spline.is_connector = true; return(true); } else { connectorList.Add(new connectorType(start_offset, end_offset, spline)); spline.is_connector = true; return(false); } }
void HandleNodes(SplineComputer newSpline, int splitIndex) { List <Node> nodes = new List <Node>(); List <int> indices = new List <int>(); for (int i = splitIndex; i < spline.pointCount; i++) { Node node = spline.GetNode(i); if (node != null) { nodes.Add(node); indices.Add(i); spline.DisconnectNode(i); i--; } } for (int i = 0; i < nodes.Count; i++) { newSpline.ConnectNode(nodes[i], indices[i] - splitIndex); } }
SplineComputer CreateNewSpline() { GameObject go = Object.Instantiate(spline.gameObject); Undo.RegisterCreatedObjectUndo(go, "New Spline"); go.name = spline.name + "_split"; SplineUser[] users = go.GetComponents <SplineUser>(); SplineComputer newSpline = go.GetComponent <SplineComputer>(); for (int i = 0; i < users.Length; i++) { spline.Unsubscribe(users[i]); users[i].spline = newSpline; newSpline.Subscribe(users[i]); } for (int i = go.transform.childCount - 1; i >= 0; i--) { Undo.DestroyObjectImmediate(go.transform.GetChild(i).gameObject); } return(newSpline); }