void Start() { // GUI has four types of objects. Controlpoints, in and out controls and a line between all of these. // All these are RageSpline objects, instantiated from a prefab controlPoints = new RageSpline[rageSpline.GetPointCount()]; inControlPoints = new RageSpline[rageSpline.GetPointCount()]; outControlPoints = new RageSpline[rageSpline.GetPointCount()]; handleLines = new RageSpline[rageSpline.GetPointCount()]; for (int index = 0; index < rageSpline.GetPointCount(); index++) { // Instantiate control point GUI object from the controlPointPrefab -prefab GameObject controlPointGO = Instantiate( controlPointPrefab, rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -1f), Quaternion.identity) as GameObject; // Save the new RageSpline instance reference of the GUI object controlPoints[index] = controlPointGO.GetComponent(typeof(RageSpline)) as RageSpline; controlPoints[index].SetFillColor1(unSelectedColor); // Instantiate inCtrl handle GUI object from the handleControlPointPrefab -prefab GameObject inControlPointGO = Instantiate( handleControlPointPrefab, rageSpline.GetInControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f), Quaternion.identity) as GameObject; // Save the new RageSpline instance reference of the GUI object inControlPoints[index] = inControlPointGO.GetComponent(typeof(RageSpline)) as RageSpline; inControlPoints[index].SetFillColor1(unSelectedColor); // Instantiate outCtrl handle GUI object from the handleControlPointPrefab -prefab GameObject outControlPointGO = Instantiate( handleControlPointPrefab, rageSpline.GetOutControlPositionWorldSpace(index) + new Vector3(0f, 0f, -1f), Quaternion.identity) as GameObject; // Save the new RageSpline instance reference of the GUI object outControlPoints[index] = outControlPointGO.GetComponent(typeof(RageSpline)) as RageSpline; outControlPoints[index].SetFillColor1(unSelectedColor); // Instantiate line GUI object from the handleLinePrefab -prefab GameObject handleLineGO = Instantiate( handleLinePrefab, rageSpline.GetPositionWorldSpace(index) + new Vector3(0f, 0f, -0.5f), Quaternion.identity) as GameObject; handleLines[index] = handleLineGO.GetComponent(typeof(RageSpline)) as RageSpline; } refreshEditorGUI(); }
public static bool RemoveOverlap(this IRageSpline path, int index0, int index1, float snapRadius, bool debug) { if (index1 == 0) { index0 = path.GetPointCount() - 1; } if (Vector3.Distance(path.GetPositionWorldSpace(index0), path.GetPositionWorldSpace(index1)) <= snapRadius) { if (debug) { Debug.Log("overlap path pos = " + path.GetPositionWorldSpace(index0)); } path.SetNatural(index1, false); path.SetInControlPositionWorldSpace(index1, path.GetInControlPositionWorldSpace(index0)); path.RemovePoint(index0); // Then deletes the duplicate previous point return(true); } return(false); }
/// <summary> Special case for start-end points, where the out tangent must be copied instead of the in tangent </summary> public static bool MergeStartEndPoints(this IRageSpline rageSpline, bool debug) { if (rageSpline.GetPointCount() <= 2) { return(false); } var lastPointIdx = rageSpline.GetPointCount() - 1; var lastPointPos = rageSpline.GetPositionWorldSpace(lastPointIdx); var firstPointPos = rageSpline.GetPositionWorldSpace(0); if (Vector3.Distance(firstPointPos, lastPointPos) < 0.0001f) { if (debug) { Debug.Log("\t Removing endpoint overlap "); } rageSpline.SetInControlPositionWorldSpace(0, rageSpline.GetInControlPositionWorldSpace(lastPointIdx)); rageSpline.RemovePoint(lastPointIdx); // Then deletes the last point return(true); } return(false); }