Example #1
0
    /// <summary>
    /// Divides the Current Section in half
    /// </summary>
    public void InsertSection()
    {
        int        CurrIdx              = BezCtrlPt.Current.CtrlPtId;
        int        newSectnIdx          = CurrIdx + 1;
        iRoadSectn CurrSectn            = Rd.Sectns[CurrIdx];
        int        CurrSectnSegStartId  = BezCtrlPt.Current.SegStartIdx;
        int        CurrSectnSegCount    = BezCtrlPt.Current.SegCount;
        int        CurrSectnNewSegCount = CurrSectnSegCount / 2;
        int        NewSectnSegStartId   = CurrSectnSegStartId + CurrSectnNewSegCount;
        int        NewSectnSegCount     = CurrSectnSegCount - CurrSectnNewSegCount;
        int        NxtSectnStartId      = Bez.CtrlPts[newSectnIdx].SegStartIdx;

        //Insert Bezier Control Point
        Vector3   NewPos    = Bez.Path[NewSectnSegStartId];
        BezCtrlPt NewCtrlPt = new BezCtrlPt(Bez, NewPos);

        NewCtrlPt.BankAngle = BezCtrlPt.Current.BankAngle;
        Bez.CtrlPts.Insert(newSectnIdx, NewCtrlPt);
        Bez.SetCtrlPtIds();
        //We dont have to move the path points from the old CtrlPt to the new one
        BezCtrlPt.Current.SegCount = CurrSectnNewSegCount;
        NewCtrlPt.SegCount         = NewSectnSegCount;
        Bez.SetSegStartIds();
        NewCtrlPt.CreateRoadMarker();
        Bez.Interp(newSectnIdx - 1);
        Bez.Interp(newSectnIdx);
        Bez.Interp(newSectnIdx + 1);
        Bez.DrawLine();

        Bez.AlignAllRoadMarkers();
        //Insert Section
        iRoadSectn NewSectn = new RoadSectn();

        NewSectn.Chargeable = false;
        NewSectn.Idx        = newSectnIdx;
        NewSectn.LFenceType = CurrSectn.LFenceType;
        NewSectn.RFenceType = CurrSectn.RFenceType;
        NewSectn.SetMaterial(CurrSectn.Segments[0].roadMaterial);
        NewSectn.CreateGameObjects();
        NewSectn.name         = "RoadSection" + (newSectnIdx);
        NewSectn.goSectn.name = "RoadSection" + (newSectnIdx);
        Road.Instance.Sectns.Insert(newSectnIdx, NewSectn);    // Section1 comes after RoadMarker1

        Rd.OrganiseObjectsUsingBezierCtrlPtsAndPath();

        /*
         * XSecCalculator.CalcXSecs(newSectnIdx-1, RoadWidth);
         * XSecCalculator.CalcXSecs(newSectnIdx, RoadWidth);
         * XSecCalculator.CalcXSecs(newSectnIdx+1, RoadWidth);
         *
         * CurrSectn.CalcFenceVerts();
         * NewSectn.CalcFenceVerts();
         * BuildQueue.Enqueue(newSectnIdx-1);
         * BuildQueue.Enqueue(newSectnIdx);
         */
    }
Example #2
0
    /// <summary>
    /// Inserts a control point just after the selected one
    /// </summary>
    public void InsertControlPoint(int idx)
    {
        Vector3   InsertPos  = Path[(idx - 1) * 20 + 10];
        BezCtrlPt InsertedCP = new BezCtrlPt(this, InsertPos);

        InsertPathPoints(idx);               //CtrlPt 3 is Path 40
        CtrlPts.Insert(idx + 1, InsertedCP); //this adds an element just before idx+1
        SetCtrlPtIds();
        InsertedCP.CreateRoadMarker();
        //Rename all the Roadmarkers after the inserted one
        for (int idxAdj = idx + 2; idxAdj < CtrlPts.Count; idxAdj++)
        {
            GameObject goRM = CtrlPts[idxAdj].goRdMkr;
            if (goRM != null)
            {
                RoadMarker RM = goRM.GetComponent <RoadMarker>();
                RM.name  = "RoadMarker" + idxAdj;
                RM.Index = idxAdj;
            }
        }
        //dunno why it ended up with the wrong parent
        CtrlPts[idx + 2].goRdMkr.transform.SetParent(Rd.Sectns[idx + 2].goSectn.transform);
    }