void Update()
    {
        var enterList = CreatePathManager.GetSplineComputers(connectingSpline.GetPoints().First().position);

        if (enterList.Count != 0)
        {
            enterRoad = enterList[0];
        }
        else
        {
            if (enterRoad)
            {
                enterRoad = null;
            }
        }

        var exitList = CreatePathManager.GetSplineComputers(connectingSpline.GetPoints().Last().position);

        if (exitList.Count != 0)
        {
            exitRoad = exitList[0];
        }
        else
        {
            if (exitRoad)
            {
                exitRoad = null;
            }
        }
    }
Exemplo n.º 2
0
    void Start()
    {
        InitTriggers();

        indicatorText        = GetComponentInChildren <TextMesh>();
        connectingRoadScript = GetComponentInChildren <ConnectingRoadScript>();
        pathManager          = GameObject.FindGameObjectWithTag("Player").GetComponent <CreatePathManager>();
        pathManager.buildingPosList.Add(position);
    }
Exemplo n.º 3
0
 void CreateExternalPoint(int count)
 {
     for (int i = 0; i < count; i++)
     {
         var point = GetRandomBoundaryPoint();
         point = new Vector3(CreatePathManager.SnapGrid(point.x, 10), 0, CreatePathManager.SnapGrid(point.z, 10));
         externalPoint.Add(point);
         Instantiate(pathManager.debugobj, point, Quaternion.identity);
     }
 }
Exemplo n.º 4
0
    void Start()
    {
        pathManager = GameObject.FindGameObjectWithTag("Player").GetComponent <CreatePathManager>();

        var plus = new Vector3(transform.position.x + (transform.localScale.x) / 2, 0,
                               transform.position.z + (transform.localScale.z) / 2);
        var minus = new Vector3(transform.position.x - (transform.localScale.x) / 2, 0,
                                transform.position.z - (transform.localScale.z) / 2);

        boundaryPoint = new Tuple <Vector3, Vector3>(plus, minus);

        CreateExternalPoint(5);
    }
Exemplo n.º 5
0
    public bool AddConnector(SplineComputer spline, int start_offset, int end_offset)
    {
        var index = connectorList.FindIndex(con => con.spline.name == spline.name);

        if (index != -1)
        {
            CreatePathManager.DestroySpline(connectorList[index].spline);

            connectorList[index].spline = spline;
            spline.is_connector         = true;

            return(true);
        }
        else
        {
            connectorList.Add(new connectorType(start_offset, end_offset, spline));
            spline.is_connector = true;

            return(false);
        }
    }
Exemplo n.º 6
0
    public bool ConnectRoad()
    {
        foreach (var departRoad in roads)
        {
            foreach (var arrivRoad in roads)
            {
                if (departRoad != arrivRoad)
                {
                    Vector3 departDir;
                    Vector3 departOffsetDir;
                    if (departRoad.GetPoints().Last().position == this.GetPosition())
                    {
                        int lastIndex = departRoad.GetPoints().Length - 1;
                        departDir = departRoad.GetPoint(lastIndex).position -
                                    departRoad.GetPoint(lastIndex - 1).position;
                        departOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * departDir;
                    }
                    else
                    {
                        departDir       = departRoad.GetPoint(0).position - departRoad.GetPoint(1).position;
                        departOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * departDir;
                    }

                    Vector3 arrivDir;
                    Vector3 arrivOffsetDir;
                    if (arrivRoad.GetPoints().Last().position == GetPosition())
                    {
                        int lastIndex = arrivRoad.GetPoints().Length - 1;
                        arrivDir = arrivRoad.GetPoint(lastIndex - 1).position -
                                   arrivRoad.GetPoint(lastIndex).position;
                        arrivOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * arrivDir;
                    }
                    else
                    {
                        arrivDir       = arrivRoad.GetPoint(1).position - arrivRoad.GetPoint(0).position;
                        arrivOffsetDir = Quaternion.AngleAxis(90, Vector3.up) * arrivDir;
                    }


                    float depart_divider = 0;
                    float arriv_divider  = 0;

                    switch (departRoad.roadLane)
                    {
                    case CreatePathManager.ROADLANE.RL05:
                        depart_divider = 1.5f;
                        break;

                    case CreatePathManager.ROADLANE.RL1:
                        depart_divider = 3f;
                        break;

                    case CreatePathManager.ROADLANE.RL2:
                        depart_divider = 3f;
                        break;
                    }

                    switch (arrivRoad.roadLane)
                    {
                    case CreatePathManager.ROADLANE.RL05:
                        arriv_divider = 1.5f;
                        break;

                    case CreatePathManager.ROADLANE.RL1:
                        arriv_divider = 3f;
                        break;

                    case CreatePathManager.ROADLANE.RL2:
                        arriv_divider = 3f;
                        break;
                    }


                    var per_depart  = departRoad.Project(GetPosition() - departDir / depart_divider).percent;
                    var departPoint = departRoad.EvaluatePosition(per_depart);

                    var per_arriv  = arrivRoad.Project(GetPosition() + arrivDir / arriv_divider).percent;
                    var arrivPoint = arrivRoad.EvaluatePosition(per_arriv);


                    // If failed to get Point Value, Re-try
                    if (Vector3.Distance(departPoint, arrivPoint) >= 20)
                    {
                        ConnectRoad();
                        return(false);
                    }


                    // Normalize Offset Vectors
                    departOffsetDir.Normalize();
                    arrivOffsetDir.Normalize();


                    // Offset List
                    var departOffsetList = new List <float>();
                    var arrivOffsetList  = new List <float>();

                    switch (departRoad.roadLane)
                    {
                    case CreatePathManager.ROADLANE.RL05:
                        departOffsetList.Add(road_offset[0]);
                        break;

                    case CreatePathManager.ROADLANE.RL1:
                        departOffsetList.Add(road_offset[1]);
                        break;

                    case CreatePathManager.ROADLANE.RL2:
                        departOffsetList.Add(road_offset[1]);
                        departOffsetList.Add(road_offset[2]);
                        break;
                    }

                    switch (arrivRoad.roadLane)
                    {
                    case CreatePathManager.ROADLANE.RL05:
                        arrivOffsetList.Add(road_offset[0]);
                        break;

                    case CreatePathManager.ROADLANE.RL1:
                        arrivOffsetList.Add(road_offset[1]);
                        break;

                    case CreatePathManager.ROADLANE.RL2:
                        arrivOffsetList.Add(road_offset[1]);
                        arrivOffsetList.Add(road_offset[2]);
                        break;
                    }

                    foreach (var dRightOffset in departOffsetList)
                    {
                        foreach (var aRightOffset in arrivOffsetList)
                        {
                            var start_offset = road_offset.FirstOrDefault(x => x.Value == dRightOffset).Key;
                            var end_offset   = road_offset.FirstOrDefault(x => x.Value == aRightOffset).Key;

                            // Set Point Position by Offset
                            var departPointOA = departPoint + departOffsetDir * dRightOffset;
                            var arrivPointOA  = arrivPoint + arrivOffsetDir * aRightOffset;

                            // Calc Inter Point
                            Vector3 interPoint;
                            if (CreatePathManager.isVectorParallel(departDir, arrivDir))
                            {
                                interPoint = (departPointOA + arrivPointOA) / 2;
                            }
                            else
                            {
                                LineLineIntersection(out interPoint, departPointOA, departDir, arrivPointOA, -arrivDir);
                            }

                            if (Vector3.Distance(departPointOA, arrivPointOA) >= 20 ||
                                Vector3.Distance(departPointOA, interPoint) >= 20 ||
                                Vector3.Distance(interPoint, arrivPointOA) >= 20)
                            {
                                ConnectRoad();
                                return(false);
                            }

                            var connectingSpline = pathManager.InsSpline(GetPosition());
                            connectingSpline.name = departRoad.name + " - " + arrivRoad.name + " / " +
                                                    start_offset + " - " + end_offset;

                            // Spawn Depart Point
                            connectingSpline.SetPointNormal(0, CreatePathManager.def_normal);
                            connectingSpline.SetPointSize(0, 1);
                            connectingSpline.SetPointPosition(0, departPointOA);

                            // Spawn Inter Point
                            connectingSpline.SetPointNormal(1, CreatePathManager.def_normal);
                            connectingSpline.SetPointSize(1, 1);
                            connectingSpline.SetPointPosition(1, interPoint);

                            // Spawn Arriv Point
                            connectingSpline.SetPointNormal(2, CreatePathManager.def_normal);
                            connectingSpline.SetPointSize(2, 1);
                            connectingSpline.SetPointPosition(2, arrivPointOA);

                            var roadConnection = departRoad.roadConnectionList.FirstOrDefault(rc => rc.GetconnectedRoad() == arrivRoad);
                            if (roadConnection != null)
                            {
                                roadConnection.AddConnector(connectingSpline, start_offset, end_offset);
                            }
                            else
                            {
                                var rc = new RoadConnection(arrivRoad);
                                rc.AddConnector(connectingSpline, start_offset, end_offset);
                                departRoad.roadConnectionList.Add(rc);
                            }
                        }
                    }
                }
            }
        }

        return(true);
    }
Exemplo n.º 7
0
 public Crossroad()
 {
     lastRoadCount = 0;
     pathManager   = GameObject.FindGameObjectWithTag("Player").GetComponent <CreatePathManager>();
 }
Exemplo n.º 8
0
 void Start()
 {
     pathManager = GetComponent <CreatePathManager>();
 }
Exemplo n.º 9
0
 private void Start()
 {
     pathFinder  = GetComponent <PathFinder>();
     pathManager = GetComponent <CreatePathManager>();
 }
Exemplo n.º 10
0
 void Start()
 {
     connectingSpline = GetComponent <SplineComputer>();
     pathManager      = GameObject.FindGameObjectWithTag("Player").GetComponent <CreatePathManager>();
     dt = this.transform.parent.gameObject;
 }