Example #1
0
    public void AddSection(Vector3 Point)
    //We add the section but we can't say how many segments it has
    //So we add the Xsecs and Segs for the previous section
    {
        if (Road.Instance.IsCircular)
        {
            return;
        }
        if (Bez.CtrlPts.Count > 3 && Vector3.Distance(Point, Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos) > 80)
        {
            Tut.gameObject.SetActive(true); Tut.ShowSpeech("This cone is too far from the last", 5); return;
        }
        int NewIdx = Road.Instance.Sectns.Count;
        int SegCount;

        Point = Bez.LimitSlope(Point, 0.33f);
        if (Bez.CtrlPts.Count == 2)
        {
            SegCount = 0;
        }
        else
        {
            SegCount = Mathf.CeilToInt(Vector3.Distance(Point, Bez.CtrlPts[Bez.CtrlPts.Count - 2].Pos) / 0.84f);
        }
        Bez.AddControlPoint(Point, 0, SegCount);
        Bez.Interp(NewIdx - 1);
        Bez.DrawLine();

        RoadSectn Sectn = new RoadSectn();

        Sectn.Idx  = NewIdx;
        Sectn.name = "RoadSection" + (NewIdx);
        Rd.Sectns[NewIdx - 1].Chargeable = true;
        Rd.Sectns[NewIdx - 1].AddXSecs(SegCount); //Add XSecs to the PREVIOUS Section
        Sectn.CreateGameObjects();
        Road.Instance.Sectns.Add(Sectn);          // Section1 comes after RoadMarker1
        Bez.CtrlPts[NewIdx].CreateRoadMarker();
        Bez.AlignAllRoadMarkers();

        XSecCalculator.CalcXSecs(NewIdx - 1, RoadWidth);                                                  //calculates for the section up to the previous marker
        for (int Idx = Bez.CtrlPts[NewIdx - 1].SegStartIdx; Idx < Bez.CtrlPts[NewIdx].SegStartIdx; Idx++) //create the segs ahead of the marker but don't mesh them
        {
            RoadSegment seg = new RoadSegment();
            seg.Idx      = Idx;
            seg.SectnIdx = NewIdx - 1;
            Rd.Sectns[NewIdx - 1].Segments.Add(seg);
            seg.CreateGameObjects();
            seg.goSeg.name = "RoadSeg" + Idx;
            Rd.Segments.Add(seg);
            seg.SetMaterial(RoadMat);
            seg.LFenceType = LFenceType;
            seg.RFenceType = RFenceType;
            seg.goSeg.transform.SetParent(Rd.Sectns[NewIdx - 1].goSectn.transform);
        }
        Rd.Sectns[NewIdx].SetMaterial(RoadMat);
        Rd.Sectns[NewIdx - 1].LFenceType = LFenceType;
        Rd.Sectns[NewIdx - 1].RFenceType = RFenceType;
        Rd.Sectns[NewIdx - 1].SetMaterial(RoadMat);
        XSecCalculator.AdjustHairpin(Bez, NewIdx - 2);
        if (NewIdx > 3)
        {
            Road.Instance.Sectns[NewIdx - 3].CalcVisibleFenceVerts();
        }
        BuildQueue.Enqueue(NewIdx - 3);
        Bez.CtrlPts[NewIdx].goRdMkr.GetComponent <RoadMarker>().Select();
        //Update the tutorial
        if (SaveLoadModel.savedGames.Count < 3)
        {
            Tutorial Tut          = _canvas.transform.Find("pnlTutorialBuild2(Clone)").GetComponent <Tutorial>();
            int      _roadCost    = BillOfRoadMaterials.Items.Sum(i => i.Cost);
            int      _sceneryCost = BillOfSceneryMaterials.Items.Sum(i => i.Opt.Cost);
            int      conesLeft    = (UserDataManager.Instance.Data.Coins - _roadCost - _sceneryCost) / 5;
            Tut.ShowSpeech(string.Format("You have money for {0:0.} more cones\n\nThe track must be a loop", conesLeft), 3);
        }
    }