コード例 #1
0
 /// <summary>
 /// Standarad Constructor
 /// </summary>
 /// <param name="roadObject">The base road object</param>
 /// <param name="list">The list of guids for the cross roads</param>
 /// <param name="roadNetworkNode"></param>
 /// <param name="materialName"></param>
 public MeshBuilderCrossRoad(IRoadBuildData roadObject, List <Guid> list, RoadNetworkNode roadNetworkNode, string materialName)
 {
     _roadObject      = roadObject;
     _list            = list;
     _roadNetworkNode = roadNetworkNode;
     _materialName    = materialName;
 }
コード例 #2
0
 /// <summary>
 /// Do all of the road links match
 /// </summary>
 private void CheckRoadLinksMatch()
 {
     Transform[] allChildren = GetComponentsInChildren <Transform>(true);
     foreach (Transform child in allChildren)
     {
         RoadNetworkNode rnn = child.GetComponent <RoadNetworkNode>();
         if (rnn != null)
         {
             rnn.Details.CompressRoads();
             foreach (RoadNetworkNode rnnInner in rnn.Details.Roads)
             {
                 if (rnnInner != null)
                 {
                     rnnInner.Details.CompressRoads();
                     if (!rnnInner.HasLinksToNode(rnn))
                     {
                         Debug.Log("Node " + rnn.name + " links to " + rnnInner.name + " but not the other way around. Adding missing link");
                         RoadNetworkLayout.AddRoadToNode(rnnInner, rnn);
                         RoadNetworkLayout.AddRoadToNode(rnn, rnnInner);
                         rnn.Details.CompressRoads();
                         rnnInner.Details.CompressRoads();
                     }
                 }
                 else
                 {
                     Debug.Log("Node " + rnn.name + " Has a missing link.");
                 }
             }
         }
     }
 }
コード例 #3
0
        /// <summary>
        /// Remove the mesh from all the road
        /// </summary>
        /// <param name="forceRemove">Force remove even if it has not changed</param>
        public void RemoveRoadMesh(bool forceRemove)
        {
            // remove all mesh from each node
            Transform[] allChildren = GetComponentsInChildren <Transform>(true);
            foreach (Transform child in allChildren)
            {
                RoadNetworkNode rub = child.GetComponent <RoadNetworkNode>();
                if (rub != null)
                {
                    if (rub.Details.IsNeighbourModified || forceRemove)
                    {
                        MeshFilter mf = child.GetComponent <MeshFilter>();
                        if (mf != null)
                        {
                            RoadBuilderHelper.RemoveMeshData(child.gameObject);
                            rub.Details.Modified = true;
                        }
                    }
                }
            }

            // Remove from the main object
            MeshFilter mf2 = GetComponent <MeshFilter>();

            if (mf2 != null)
            {
                RoadBuilderHelper.RemoveMeshData(gameObject);
            }

            IntersectionManager.Instance.Clear();
            StreetManager.Instance.Clear();
        }
コード例 #4
0
 /// <summary>
 /// Standard Constructor
 /// </summary>
 /// <param name="connectionSet"></param>
 /// <param name="roadNetworkNode">The master node for the junction</param>
 /// <param name="materialName">The name of the material for this mesh</param>
 public DrawDetailsFiveRoad(int connectionSet, RoadNetworkNode roadNetworkNode, string materialName)
 {
     _connectionSet   = connectionSet;
     _materialName    = materialName;
     _roadNetworkNode = roadNetworkNode;
     _materialName    = materialName;
 }
コード例 #5
0
        /// <summary>
        /// Update all of the end points of the cross roads
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="leftIntersectionInner">The inner left cross section</param>
        /// <param name="leftIntersectionOutter">The outter left cross section</param>
        /// <param name="rightIntersectionInner">The inner right cross section</param>
        /// <param name="rightIntersectionOutter">The outter right cross section</param>
        /// <param name="middleIntersectionInner">The middle road cross sections</param>
        /// <param name="oppositeIntersectionInner">The opposite road cross sections</param>
        private void UpdateRoadNodesEndPoints(out RoadCrossRoadOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner, out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter, out RoadCrossSection middleIntersectionInner, out RoadCrossSection oppositeIntersectionInner)
        {
            RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0];
            RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1];
            RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2];
            RoadNetworkNode roadD = _roadNetworkNode.Details.Roads[3];

            order = new RoadCrossRoadOrder(
                _list[0], roadA,
                _list[1], roadB,
                _list[2], roadC,
                _list[3], roadD);
            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            // left road
            Vector3 posA;
            Vector3 posA2;
            Vector3 posB;

            FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.CurbLeftEnd, order.LeftRoad.CurbRightEnd, out posA);
            FindOverlapPoint(order.MiddleRoad.Angle, order.LeftRoad.Angle, order.MiddleRoad.Left, order.LeftRoad.CurbRightEnd, out posA2);
            FindOverlapPoint(order.OppositeRoad.Angle, order.LeftRoad.Angle, order.OppositeRoad.CurbRightEnd, order.LeftRoad.CurbLeftEnd, out posB);

            Vector3 curbToCurb   = posA - posB;
            float   newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);

            leftIntersectionInner  = order.LeftRoad.GetIntersection(newRoadAngle, posA);
            leftIntersectionOutter = order.LeftRoad.GetIntersection(newRoadAngle, posA2);
            FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.CurbRightEnd, order.RightRoad.CurbLeftEnd, out posA);
            FindOverlapPoint(order.MiddleRoad.Angle, order.RightRoad.Angle, order.MiddleRoad.Right, order.RightRoad.CurbLeftEnd, out posA2);
            FindOverlapPoint(order.OppositeRoad.Angle, order.RightRoad.Angle, order.OppositeRoad.CurbLeftEnd, order.RightRoad.CurbRightEnd, out posB);
            curbToCurb = posB - posA;

            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);
            rightIntersectionInner  = order.RightRoad.GetIntersection(newRoadAngle, posA);
            rightIntersectionOutter = order.RightRoad.GetIntersection(newRoadAngle, posA2);
            curbToCurb              = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd;
            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);
            middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbLeftEnd);
            curbToCurb              = rightIntersectionInner.CurbRightEnd - leftIntersectionInner.CurbLeftEnd;
            newRoadAngle            = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) - (Mathf.PI / 2);

            oppositeIntersectionInner = order.OppositeRoad.GetIntersection(newRoadAngle, rightIntersectionInner.CurbRightEnd);

            // Store the ids so we know where to update them later
            Guid leftRoadNodeId     = order.LeftRoad.ID;
            Guid rightRoadNodeId    = order.RightRoad.ID;
            Guid middleRoadNodeId   = order.MiddleRoad.ID;
            Guid oppositeRoadNodeId = order.OppositeRoad.ID;

            order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle));
            order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle));
            order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle));
            order.ReSetOpposite(FindSmallestRoadForJunction(order.OppositeRoadNode, oppositeIntersectionInner, order.OppositeRoad.Middle));

            IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad);
            IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad);
            IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad);
            IntersectionManager.Instance.SetIntersection(oppositeRoadNodeId, order.OppositeRoad);
        }
コード例 #6
0
        /// <summary>
        /// Modifiy the terrain for the junction
        /// </summary>
        /// <param name="sections">The number of sections</param>
        /// <param name="tm">The terrain modifier</param>
        private void CreateJunctionsTerrain(int sections, TerrainModifier tm)
        {
            float couveSize = 2.5f;

            _roadNetworkNode.OrderRoads();

            IMaterialFrequency materialFrequency = _roadNetworkNode.GetComponent <OverridableMaterialFrequency>();

            if (materialFrequency == null)
            {
                materialFrequency = RoadConstructorHelper.MaterialFrequencySet;
            }

            RoadNetworkNode  roadA, roadB, roadC;
            RoadCrossSection rA, rB, rC;

            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 0, _roadNetworkNode, out roadA, out rA);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 1, _roadNetworkNode, out roadB, out rB);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 2, _roadNetworkNode, out roadC, out rC);

            int connectionSet = IntersectionManager.Instance.AddLinkedIntersecions(rA, rB, rC);

            RoadNetworkNode roadNetworkNode = _roadNetworkNode;
            string          materialName    = RoadConstructorHelper.GetMainMaterial(materialFrequency);

            DrawDetailsJunctionRoad drs = new DrawDetailsJunctionRoad(connectionSet, roadNetworkNode, materialName);

            drs.ModifyTerrain(_roadNetworkNode.BuildData, tm);

            RoadConstructorHelper.ApplyLeadingStrights(_roadNetworkNode, tm, 0);
            RoadConstructorHelper.ApplyLeadingStrights(_roadNetworkNode, tm, 1);
            RoadConstructorHelper.ApplyLeadingStrights(_roadNetworkNode, tm, 2);
        }
コード例 #7
0
 /// <summary>
 /// Connect two nodes together
 /// </summary>
 /// <param name="firstRoad">The first road</param>
 /// <param name="secondRoad">The second road</param>
 public void ConnectNodes(RoadNetworkNode firstRoad, RoadNetworkNode secondRoad)
 {
     if (firstRoad != secondRoad)
     {
         RoadNetworkLayout.AddRoadToNode(firstRoad, secondRoad);
         RoadNetworkLayout.AddRoadToNode(secondRoad, firstRoad);
     }
 }
コード例 #8
0
 /// <summary>
 /// Update linked roads
 /// </summary>
 /// <param name="roadNode">The road To link to</param>
 public void UpdateLinkedRoads(RoadNetworkNode roadNode)
 {
     for (int i = 0; i < Roads.Count; i++)
     {
         if (Roads[i] != null)
         {
             Roads[i].Details.BackLink(roadNode);
         }
     }
 }
コード例 #9
0
        /// <summary>
        /// can we remove all the nodes
        /// </summary>
        /// <returns>Whether we have child road nodes</returns>
        public bool CanRemoveAllNodes()
        {
            foreach (Transform child in gameObject.transform)
            {
                RoadNetworkNode rnr = child.gameObject.GetComponent <RoadNetworkNode>();
                if (rnr != null)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #10
0
        private void AddAngle(Guid id, RoadNetworkNode node)
        {
            RoadCrossSection road  = IntersectionManager.Instance[id];
            float            angle = MathsHelper.ClampAngle(road.Angle);

            while (_angles.ContainsKey(angle))
            {
                angle = angle + 0.001f;
                Debug.Log("Overlap node " + node.name);
            }

            _angles.Add(angle, road);
            _nodes.Add(angle, node);
            _orderedAngles.Add(angle);
        }
コード例 #11
0
        /// <summary>
        /// Clear the current network
        /// </summary>
        private void ClearCurrentNetwork()
        {
            bool more = true;

            while (more)
            {
                more = false;
                foreach (Transform child in gameObject.transform)
                {
                    RoadNetworkNode rnr = child.gameObject.GetComponent <RoadNetworkNode>();
                    if (rnr != null)
                    {
                        DestroyImmediate(child.gameObject);
                        more = true;
                    }
                }
            }
        }
コード例 #12
0
        /// <summary>
        /// On Draw Gizmo selection. Draw when selected
        /// </summary>
        public void OnDrawGizmosSelected()
        {
            RoadBuilder rb = GetComponent <RoadBuilder>();

            RoadConstructorHelper.CrossSectionDetails  = rb.CrossSectionDetails;
            RoadConstructorHelper.Lighting             = rb.Lighting;
            RoadConstructorHelper.MaterialFrequencySet = rb;
            RoadConstructorHelper.BaseNodeLayoutNode   = GetComponent <RoadNetworkLayout>();

            foreach (Transform child in gameObject.transform)
            {
                RoadNetworkNode rnr = child.gameObject.GetComponent <RoadNetworkNode>();
                if (rnr != null)
                {
                    rnr.DrawGizmosSelected();
                }
            }
        }
コード例 #13
0
        /// <summary>
        /// Remove node from all links
        /// </summary>
        /// <param name="node">The node to remove</param>
        internal static void RemoveLinkFrom(RoadNetworkNode node)
        {
            for (int r = 0; r < node.Details.Roads.Count; r++)
            {
                RoadNetworkNode innerRoad = node.Details.Roads[r];

                for (int i = 0; i < innerRoad.Details.Roads.Count; i++)
                {
                    if (innerRoad.Details.Roads[i] == node)
                    {
                        innerRoad.Details.Roads[i] = null;
                        node.Details.Modified      = true;
                    }
                }

                innerRoad.Details.CompressRoads();
            }
        }
コード例 #14
0
        /// <summary>
        /// Standard Constructor
        /// </summary>
        /// <param name="a">Guid A</param>
        /// <param name="nodeA">Node A</param>
        /// <param name="b">Guid B</param>
        /// <param name="nodeB">Node B</param>
        /// <param name="c">Guid C</param>
        /// <param name="nodeC">Node C</param>
        /// <param name="d">Guid D</param>
        /// <param name="nodeD">Node D</param>
        public RoadCrossRoadOrder(Guid a, RoadNetworkNode nodeA,
                                  Guid b, RoadNetworkNode nodeB,
                                  Guid c, RoadNetworkNode nodeC,
                                  Guid d, RoadNetworkNode nodeD)
        {
            _orderedAngles = new List <float>();
            _angles        = new Dictionary <float, RoadCrossSection>();
            _nodes         = new Dictionary <float, RoadNetworkNode>();

            AddAngle(a, nodeA);

            AddAngle(b, nodeB);

            AddAngle(c, nodeC);

            AddAngle(d, nodeD);

            _orderedAngles.Sort();
        }
コード例 #15
0
        /// <summary>
        /// Link to the road node
        /// </summary>
        /// <param name="roadNode">The road To link to</param>
        private void BackLink(RoadNetworkNode roadNode)
        {
            foreach (RoadNetworkNode n in Roads)
            {
                if (n == roadNode)
                {
                    return;
                }
            }

            for (int i = 0; i < Roads.Count; i++)
            {
                if (Roads[i] == null)
                {
                    Roads[i] = roadNode;
                    Modified = true;
                    return;
                }
            }
        }
コード例 #16
0
        /// <summary>
        /// Update all of the end points of the jucntions
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="leftIntersectionInner">The inner left cross section</param>
        /// <param name="leftIntersectionOutter">The outter left cross section</param>
        /// <param name="rightIntersectionInner">The inner right cross section</param>
        /// <param name="rightIntersectionOutter">The outter right cross section</param>
        /// <param name="middleIntersectionInner">The middle road cross sections</param>
        private void UpdateRoadNodesEndPoint(out RoadJunctionOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner,
                                             out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter,
                                             out RoadCrossSection middleIntersectionInner)
        {
            RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0];
            RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1];
            RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2];

            order = new RoadJunctionOrder(
                _list[0], roadA,
                _list[1], roadB,
                _list[2], roadC);
            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            // left road
            leftIntersectionInner        = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbLeftEnd);
            leftIntersectionOutter       = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Left);
            leftIntersectionInner.Angle += (float)(Math.PI);

            rightIntersectionInner  = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbRightEnd);
            rightIntersectionOutter = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Right);
            Vector3 curbToCurb   = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd;
            float   newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);

            middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, leftIntersectionInner.CurbRightEnd);

            // Store the ids so we know where to update them later
            Guid leftRoadNodeId   = order.LeftRoad.ID;
            Guid rightRoadNodeId  = order.RightRoad.ID;
            Guid middleRoadNodeId = order.MiddleRoad.ID;

            // reduce the run off roads
            order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle));
            order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle));
            order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle));

            IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad);
            IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad);
            IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad);
        }
コード例 #17
0
        /// <summary>
        /// Add a road
        /// </summary>
        /// <param name="node">The node to add the road too</param>
        /// <param name="nodeToAdd">The node to add</param>
        public static void AddRoadToNode(RoadNetworkNode node, RoadNetworkNode nodeToAdd)
        {
            if (node.HasLinksToNode(nodeToAdd))
            {
                return;
            }

            int roadCount = UnionHelper.GetRoadCount(node.Details.Union) + 1;

            node.Details.Union = UnionHelper.SetRoadUnionTypeFromRoadCount(roadCount);

            node.CreateRoadArray();
            for (int r = 0; r < node.Details.Roads.Count; r++)
            {
                if (node.Details.Roads[r] == null)
                {
                    node.Details.Roads[r] = nodeToAdd;
                    node.Details.Modified = true;
                    return;
                }
            }
        }