示例#1
0
    public void AddControlPoint(Vector3 Pt, int segCount, BendType bendType, Bend bend)
    {
        if (segCount != 0)
        {
            segCount = bend.EndSegIdx - bend.StartSegIdx;
        }
        RLPt BCP = new RLPt(this, Pt);

        BCP.BendType = bendType;
        BCP.Bend     = bend;
        CtrlPts[CtrlPts.Count - 2].SegCount = segCount;     //set the SegCount of the previous CtrlPt
        CtrlPts.Insert(CtrlPts.Count - 1, BCP);

        SetCtrlPtIds();
        SetSegStartIds();
        CtrlPts[CtrlPts.Count - 1].Pos = Pt;        //cos the last control point is a dummy and is in the same place
        if (BCP.CtrlPtId == 1)
        {
            if (Rd.IsCircular)
            {
                CtrlPts[0].Pos = CtrlPts[CtrlPts.Count - 2].Pos;
            }
        }
        else
        {
            CtrlPts[0].Pos = Pt;                    //cos the first one is a dummy too
        }
        if (BCP.CtrlPtId > 1)
        {
            AddPathPoints(segCount);
        }
    }
示例#2
0
    public void RemoveLastControlPoint()
    {
        int  IdxToRemove = CtrlPts.Count - 2;
        RLPt CPToRemove  = CtrlPts[IdxToRemove];
        RLPt PrevCP      = CtrlPts[IdxToRemove - 1];

        //This isnt quite right but it'll do
        //I hope it doesn't cause a memory leak
        //DO we have to remove the Section and Segments and the gameobjects?
        int PrevCtrlPtId = -1;
        int NxtCtrlPtId  = -1;

        try
        {
            PrevCtrlPtId = CPToRemove.CtrlPtId - 1;
            NxtCtrlPtId  = CPToRemove.CtrlPtId + 1;
        }
        catch (Exception e) { Debug.Log(e.Message); }
        //not needed ? //if(Road.Instance.IsCircular) Path.RemoveRange(Path.Count - 20, 20);
        Path.RemoveRange(PrevCP.SegStartIdx, PrevCP.SegCount);
        CtrlPts.Remove(CPToRemove);
        PrevCP.SegCount = 0;
        PrevCP.Select();
        SetCtrlPtIds();
        SetSegStartIds();
    }
示例#3
0
 /// <summary>
 /// This gets called on a new game. It doesn't get called when you load a saved game
 /// </summary>
 public void Init()
 {
     Rd = Road.Instance;
     Path.Clear();
     CtrlPts.Clear();
     //Add 2 control points - this is the minimum to get it working
     for (int i = 0; i < 2; i++)
     {
         RLPt BCP = new RLPt(this, Vector3.zero);
         CtrlPts.Add(BCP);
     }
     RLPt.Current = CtrlPts[0];
     SetCtrlPtIds();
 }
示例#4
0
    public void Select()
    {
        if (goRdMkr == null)
        {
            return;
        }
        RoadMarker RM = goRdMkr.gameObject.GetComponent <RoadMarker>();

        if (!RM.Selected)
        {
            RM.Select();
        }
        Current = this;
        RM      = null;
    }
示例#5
0
    /// <summary>
    /// Inserts a control point just after the selected one
    /// </summary>
    public void InsertControlPoint(int idx)
    {
        Vector3 InsertPos  = Path[(idx - 1) * 20 + 10];
        RLPt    InsertedCP = new RLPt(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);
    }