/// <summary>Adds a rail node to the end of the specified rail</summary> /// <param name="rail">The rail to add a node to</param> /// <param name="nodePosition">The position of the node to add</param> public static void AddRailNode(Rail rail, Vector2 nodePosition) { Undo.RecordObject(rail, "Add Node"); var node = new RailNode() { Position = nodePosition }; rail.Nodes.Add(node); }
/// <summary>Inserts a rail node on the specified rail</summary> /// <param name="rail">The rail to insert a node on</param> /// <param name="nodeIndex">The index of the node to insert</param> /// <param name="nodePosition">The position of the node to insert</param> public static void InsertRailNode(Rail rail, int nodeIndex, Vector2 nodePosition) { Undo.RecordObject(rail, "Insert Node"); var nodes = rail.Nodes; var node = new RailNode() { Position = nodePosition }; nodes.Insert(nodeIndex, node); }
/// <summary>Returns an adjusted interpolation value with FX Threshold applied.</summary> /// <param name="nodeInterpolationValue">Initial interpolation value.</param> /// <param name="preNode">The closest node before the target.</param> private float ApplyThresholdFX(float nodeInterpolationValue, RailNode preNode) { float thresholdFX = preNode.Threshold; if (thresholdFX == 0f) { return(nodeInterpolationValue); } else if (thresholdFX == 1f) { return(1f); } if (preNode.InvertThreshold) { return((nodeInterpolationValue) / (1f - preNode.Threshold)); } return((nodeInterpolationValue - preNode.Threshold) / (1f - preNode.Threshold)); }
/// <summary>Returns camera position calculated from an adjusted target position.</summary> /// <param name="targetPosition">Adjusted Target position.</param> private Vector2 GetIntendedPositionFromTargetPosition(Vector2 targetPosition) { // Sets preNode as the closest node below targetPosition, and postNode as preNode + 1 RailNode preNode = Nodes[0]; RailNode postNode = Nodes[1]; for (int i = 0; i < Nodes.Count - 1; i++) { if ((Orientation == RailOrientation.Horizontal && targetPosition.x - Nodes[i].Position.x < 0) || (Orientation == RailOrientation.Vertical && targetPosition.y - Nodes[i].Position.y < 0)) { break; } preNode = Nodes[i]; postNode = Nodes[i + 1]; } // The true interpolation value float targetNodeInterpolation = GetTargetNodeInterpolation(targetPosition, preNode.Position, postNode.Position); // Lead-In Effect if (LeadIn != 0.0f && preNode == Nodes[0]) { targetNodeInterpolation = ApplyLeadInFX(targetNodeInterpolation); } // Trail-Out Effect if (TrailOut != 0.0f && postNode == Nodes[Nodes.Count - 1]) { targetNodeInterpolation = ApplyTrailOutFX(targetNodeInterpolation); } // Threshold Effect targetNodeInterpolation = ApplyThresholdFX(targetNodeInterpolation, preNode); return(Vector2.Lerp(preNode.Position, postNode.Position, targetNodeInterpolation)); }