示例#1
0
    public void DeleteLastSectn()
    {
        //Actually we delete the penultimate section because the last section is empty
        if (Sectns.Count < 2)
        {
            return;
        }
        int        LastSectnId   = Sectns.Count - 1;
        int        PenultSectnId = Sectns.Count - 2;
        iRoadSectn LastSection   = Sectns.Last();
        iRoadSectn PenultSection = Sectns[Sectns.Count - 2];
        //iRoadSectn PrevSection = Sectns[Sectns.Count - 3];
        //int PrevSegCount = PrevSection.Segments.Count;
        int PenultSegCount   = PenultSection.Segments.Count;
        int PenultSegStartId = PenultSegCount > 0 ? PenultSection.Segments[0].Idx : 0;

        //I tested this function using Watches on all the XSecCounts, SegmentCounts and SegStart and SegCount for each section
        //comparing them before adding and deleting a section and then after

        //Remove Section's Segment GameObjects
        foreach (RoadSegment seg in PenultSection.Segments)
        {
            GameObject.Destroy(seg.goSeg);
        }

        if (!IsCircular)
        {
            Segments.RemoveRange(PenultSegStartId, PenultSegCount);
            PenultSection.Segments.Clear();
            PenultSection.DeleteFence();
            XSecs.RemoveRange(PenultSegStartId, PenultSegCount);
            //PenultSection.XSecs.Clear();
        }

        if (IsCircular)
        {
            PenultSection.DeleteFence();
            Segments.RemoveRange(PenultSegStartId, PenultSegCount);
            PenultSection.Segments.Clear();
            XSecs.RemoveRange(PenultSegStartId, PenultSegCount);
            //PenultSection.XSecs.Clear();
            //Road.Instance.XSecs.RemoveRange(PrevSegStartId, PrevSegCount);
        }

        //Delete Section
        GameObject.Destroy(LastSection.goSectn);
        Sectns.Remove(LastSection);

        BezierLine.Instance.RemoveLastControlPoint();  //also removes the path points and selects the previous CtrlPt
        IsCircular         = false;
        Game.current.Dirty = true;
    }
示例#2
0
    public void Init()
    {
        //This is just because the sections and segments start at Idx=1
        //Segment[0] doesn't do anything
        Segments.Clear();
        XSecs.Clear();
        Sectns.Clear();
        //RacingLine = new RacingLine();
        IsCircular = false;
        RoadSectn sectn = new RoadSectn();

        Sectns.Add(sectn);
        sectn.Idx = 0;
        //Put all the materials in a dictionary for faster retrieval
        Material M;

        RoadMaterials = new Dictionary <string, Material>();
        M             = (Material)Resources.Load("Prefabs/Materials/Tarmac", typeof(Material));
        RoadMaterials.Add("Tarmac", M);
        M = (Material)Resources.Load("Prefabs/Materials/Tarmac0", typeof(Material));
        RoadMaterials.Add("Tarmac0", M);
        M = (Material)Resources.Load("Prefabs/Materials/Tarmac1", typeof(Material));
        RoadMaterials.Add("Tarmac1", M);
        M = (Material)Resources.Load("Prefabs/Materials/Tarmac2", typeof(Material));
        RoadMaterials.Add("Tarmac2", M);
        M = (Material)Resources.Load("Prefabs/Materials/Tarmac3", typeof(Material));
        RoadMaterials.Add("Tarmac3", M);
        M = (Material)Resources.Load("Prefabs/Materials/Washboard0", typeof(Material));
        RoadMaterials.Add("Washboard0", M);
        M = (Material)Resources.Load("Prefabs/Materials/Washboard1", typeof(Material));
        RoadMaterials.Add("Washboard1", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtyRoad", typeof(Material));
        RoadMaterials.Add("DirtyRoad", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtRoad0", typeof(Material));
        RoadMaterials.Add("DirtRoad0", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtRoad1", typeof(Material));
        RoadMaterials.Add("DirtRoad1", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtRoad2", typeof(Material));
        RoadMaterials.Add("DirtRoad2", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtRoad3", typeof(Material));
        RoadMaterials.Add("DirtRoad3", M);
        M = (Material)Resources.Load("Prefabs/Materials/TarmacUnderside", typeof(Material));
        RoadMaterials.Add("TarmacUnderside", M);
        M = (Material)Resources.Load("Prefabs/Materials/WashboardUnderside", typeof(Material));
        RoadMaterials.Add("WashboardUnderside", M);
        M = (Material)Resources.Load("Prefabs/Materials/DirtyRoadUnderside", typeof(Material));
        RoadMaterials.Add("DirtyRoadUnderside", M);
        SkidMks = new Queue <FlatLineRenderer>();
    }