Ejemplo n.º 1
0
        /// <summary>
        /// Repair all the nodes in the layout
        /// </summary>
        public void RepairAllNodes()
        {
            Transform[] allChildren = GetComponentsInChildren <Transform>(true);
            foreach (Transform child in allChildren)
            {
                RoadNetworkNode rnn = child.GetComponent <RoadNetworkNode>();
                if (rnn != null)
                {
                    rnn.CheckNodeAreValid();
                    rnn.Details.CompressRoads();

                    for (int r = 0; r < rnn.Details.Roads.Count; r++)
                    {
                        RoadNetworkNode rnnInner = rnn.Details.Roads[r];
                        if (!rnnInner.HasLinksToNode(rnn))
                        {
                            Debug.Log("Node " + rnn.name + " links to " + rnnInner.name + " Linking them");
                            RoadNetworkLayout.AddRoadToNode(rnn, rnnInner);
                            rnn.Details.CompressRoads();
                            rnnInner.Details.CompressRoads();
                        }
                    }
                }
            }
        }
Ejemplo n.º 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.");
                 }
             }
         }
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Unityed Editor shoe the road link
        /// </summary>
        public void OnDrawGizmosSelected()
        {
            RoadNetworkLayout rnl = gameObject.GetComponentInParent <RoadNetworkLayout>();

            if (rnl != null)
            {
                rnl.OnDrawGizmosSelected();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add the Material Frequency overridables
        /// </summary>
        public void AddOverridableMaterialsDetails()
        {
            gameObject.AddComponent <OverridableMaterialFrequency>();
            OverridableMaterialFrequency omf = gameObject.GetComponent <OverridableMaterialFrequency>();
            RoadNetworkLayout            rnl = gameObject.GetComponentInParent <RoadNetworkLayout>();

            omf.PopulateDefaultMaterials(rnl);
            Details.Modified = true;
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Connect the nodes to make a road.
        /// </summary>
        /// <param name="nodes">The list of selected node</param>
        public void ConnectNodes(List <RoadNetworkNode> nodes)
        {
            if (nodes.Count != 2)
            {
                return;
            }

            RoadNetworkLayout.AddRoadToNode(nodes[0], nodes[1]);
            RoadNetworkLayout.AddRoadToNode(nodes[1], nodes[0]);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Check all the node are valid
 /// </summary>
 public void CheckNodeAreValid()
 {
     foreach (RoadNetworkNode rnn in Details.Roads)
     {
         if (rnn == this)
         {
             Debug.Log("We are linked to us -> removing node");
             RoadNetworkLayout.RemoveLinkFrom(rnn);
             CreateRoadArray();
             break;
         }
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Insect a new node between the two nodes
        /// </summary>
        /// <param name="nodes">The list of selected node</param>
        /// <returns>The newly inserted node</returns>
        public GameObject InsertNewNode(List <RoadNetworkNode> nodes)
        {
            Vector3    pos    = (nodes[0].transform.position + nodes[1].transform.position) / 2;
            GameObject rnnNew = RoadNetworkNodeHelper.CreateBasicNode(pos, RoadConstructorHelper.GetUniqueRoadName(this.gameObject), this.gameObject);

            RoadNetworkNodeHelper.RemoveRoadAFromB(nodes[0], nodes[1]);
            RoadNetworkNodeHelper.RemoveRoadAFromB(nodes[1], nodes[0]);

            RoadNetworkLayout.AddRoadToNode(nodes[0], rnnNew.GetComponent <RoadNetworkNode>());
            RoadNetworkLayout.AddRoadToNode(rnnNew.GetComponent <RoadNetworkNode>(), nodes[0]);

            RoadNetworkLayout.AddRoadToNode(nodes[1], rnnNew.GetComponent <RoadNetworkNode>());
            RoadNetworkLayout.AddRoadToNode(rnnNew.GetComponent <RoadNetworkNode>(), nodes[1]);

            return(rnnNew);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Populated the materials
        /// </summary>
        /// <param name="rnl">The current road network layout</param>
        public void PopulateDefaultMaterials(RoadNetworkLayout rnl)
        {
            if (rnl == null)
            {
                return;
            }

            RoadBuilder rb = rnl.GetComponent <RoadBuilder>();

            if (rb == null)
            {
                return;
            }

            Copy(rb.GetComponent <IMaterialFrequency>());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Extrude the road out, by creating a new node
        /// </summary>
        /// <returns>The newly created road section</returns>
        public GameObject ExtrudeRoad()
        {
            Details.CompressRoads();
            Details.Modified = true;

            float roadAngle = GetCurrentAngle() + (float)(Math.PI / 2);

            if (Details.Union != UNION_TYPE.END)
            {
                roadAngle += (float)(Math.PI / 2);
            }

            Vector3    pos     = MathsHelper.OffSetVector(transform.position, roadAngle, 100);
            GameObject newNode = RoadNetworkNodeHelper.CreateBasicNode(pos, RoadConstructorHelper.GetUniqueRoadName(gameObject), gameObject);

            GameObject rnnB = gameObject;

            RoadNetworkLayout.AddRoadToNode(newNode.GetComponent <RoadNetworkNode>(), rnnB.GetComponent <RoadNetworkNode>());
            RoadNetworkLayout.AddRoadToNode(rnnB.GetComponent <RoadNetworkNode>(), newNode.GetComponent <RoadNetworkNode>());

            ICrossSection sc = gameObject.GetComponent <ICrossSection>();

            if (sc != null)
            {
                newNode.AddComponent <OverridableCrossSection>();
                OverridableCrossSection ocs = newNode.GetComponent <OverridableCrossSection>();
                ocs.Copy(sc);
            }

            IMaterialFrequency fm = gameObject.GetComponent <IMaterialFrequency>();

            if (fm != null)
            {
                newNode.AddComponent <OverridableMaterialFrequency>();
                OverridableMaterialFrequency ocs = newNode.GetComponent <OverridableMaterialFrequency>();
                ocs.Copy(fm);
            }

            return(newNode);
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            RoadNetworkLayout roadScript = (RoadNetworkLayout)target;

            if (roadScript.CanRemoveAllNodes())
            {
                GUI.color = Color.red;
                if (GUILayout.Button("Remove all road Nodes"))
                {
                    roadScript.RemoveAllNodes();
                }
            }
            else
            {
                GUI.color = Color.yellow;
                if (GUILayout.Button("Start new road"))
                {
                    Selection.activeGameObject = roadScript.StartNewRoad();
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Delete the this node
 /// </summary>
 public void DeleteNode()
 {
     RoadNetworkLayout.RemoveLinkFrom(this);
     DestroyImmediate(gameObject);
 }