示例#1
0
    public void SetTrafficSystemPiece(TrafficSystemTooltip a_tooltip, TrafficSystemPiece a_obj)
    {
        switch (a_tooltip)
        {
        case TrafficSystemTooltip.ANCHOR:
        {
            AnchorTrafficSystemPiece = a_obj;
            if (AnchorTrafficSystemPiece)
            {
                PositionTooltip(TrafficSystem.TrafficSystemTooltip.ANCHOR, AnchorTrafficSystemPiece);
            }
        }
        break;

        case TrafficSystemTooltip.EDIT:
        {
            EditTrafficSystemPiece = a_obj;
            if (EditTrafficSystemPiece)
            {
                PositionTooltip(TrafficSystem.TrafficSystemTooltip.EDIT, EditTrafficSystemPiece);
            }
        }
        break;
        }
    }
示例#2
0
    public void CleanUp(TrafficSystemPiece a_piece)
    {
        if (a_piece)
        {
            a_piece.PerformCleanUp();

            for (int cIndex = 0; cIndex < a_piece.transform.childCount; cIndex++)
            {
                if (a_piece.transform.GetChild(cIndex).GetComponent <TrafficSystemPiece>())
                {
                    CleanUp(a_piece.transform.GetChild(cIndex).GetComponent <TrafficSystemPiece>());
                }
            }
        }
    }
示例#3
0
    public void CleanUp( TrafficSystemPiece a_piece )
    {
        if(a_piece)
        {
            a_piece.PerformCleanUp();

            for(int cIndex = 0; cIndex < a_piece.transform.childCount; cIndex++)
            {
                if(a_piece.transform.GetChild(cIndex).GetComponent<TrafficSystemPiece>())
                {
                    CleanUp( a_piece.transform.GetChild(cIndex).GetComponent<TrafficSystemPiece>() );
                }
            }
        }
    }
    void Awake()
    {
        // HACK - START
        ///       for some reason sometimes m_connectedNodes end up with null values ... have checked every inch of the code and found nothing! ... this removed them on Play so should clean any issues up.
        for (int cIndex = m_connectedNodes.Count - 1; cIndex >= 0; cIndex--)
        {
            if (m_connectedNodes[cIndex] == null)
            {
                m_connectedNodes.RemoveAt(cIndex);
            }
        }
        // HACK - END

        GameObject obj = TrafficSystemGameUtils.FindParentItem(gameObject, TrafficSystemGameUtils.GameObjectItem.TRAFFIC_SYSTEM_PIECE);

        if (obj && obj.GetComponent <TrafficSystemPiece>())
        {
            Parent = obj.GetComponent <TrafficSystemPiece>();
        }

        if (transform.childCount > 0)
        {
            m_linkedIndicator = transform.GetChild(0).gameObject;
        }

        if (Application.isPlaying)
        {
#if UNITY_EDITOR
            ShowRenderers(true);
#else
            ShowRenderers(false);
#endif
        }

//		if(TrafficSystem.Instance && TrafficSystem.Instance.ShouldSpawnVehicle())
//		{
//			TrafficSystemVehicle prefab  = TrafficSystem.Instance.GetVehiclePrefabToSpawn();
//			TrafficSystemVehicle vehicle = Instantiate( prefab, transform.position, transform.rotation ) as TrafficSystemVehicle;
//			vehicle.m_nextNode           = this;
//			vehicle.m_velocityMax        = Random.Range(TrafficSystem.Instance.m_randVelocityMin, TrafficSystem.Instance.m_randVelocityMax);
//		}
    }
示例#5
0
    public void PositionTooltip(TrafficSystemTooltip a_tooltip, TrafficSystemPiece a_obj)
    {
        switch (a_tooltip)
        {
        case TrafficSystemTooltip.ANCHOR:
        {
            if (TooltipAnchor)
            {
                TooltipAnchor.transform.position = new Vector3(a_obj.transform.position.x, a_obj.transform.position.y + a_obj.m_renderer.bounds.extents.y + 2.0f, a_obj.transform.position.z);
            }
        }
        break;

        case TrafficSystemTooltip.EDIT:
        {
            if (TooltipEdit)
            {
                TooltipEdit.transform.position = new Vector3(a_obj.transform.position.x, a_obj.transform.position.y + a_obj.m_renderer.bounds.extents.y + 2.4f, a_obj.transform.position.z);
            }
        }
        break;
        }
    }
示例#6
0
    void FindAllNodesRecursive(TrafficSystemPiece a_trafficSystemPiece, GameObject a_obj)
    {
        if (a_obj)
        {
            if (a_obj.GetComponent <TrafficSystemNode>())
            {
                TrafficSystemNode node = a_obj.GetComponent <TrafficSystemNode>();
                if (node)
                {
                    if (node.m_driveSide == TrafficSystem.DriveSide.LEFT)
                    {
                        if (node.m_roadType == TrafficSystem.RoadType.CHANGE_LANE)
                        {
                            a_trafficSystemPiece.m_leftLaneChangeNodes.Add(node);
                        }
                        else if (node.m_isPrimary)
                        {
                            a_trafficSystemPiece.m_primaryLeftLaneNodes.Add(node);
                        }
                        else
                        {
                            //						bool wasInserted = false;
                            //						for(int sIndex = 0; sIndex < a_trafficSystemPiece.m_secondaryLeftLaneNodes.Count; sIndex++)
                            //						{
                            //							if(a_trafficSystemPiece.m_secondaryLeftLaneNodes[sIndex].m_priority > node.m_priority)
                            //							{
                            //								a_trafficSystemPiece.m_secondaryLeftLaneNodes.Insert(sIndex, node);
                            //								wasInserted = true;
                            //								break;
                            //							}
                            //						}
                            //
                            //						if(!wasInserted)
                            a_trafficSystemPiece.m_secondaryLeftLaneNodes.Add(node);
                        }
                    }
                    else
                    {
                        if (node.m_roadType == TrafficSystem.RoadType.CHANGE_LANE)
                        {
                            a_trafficSystemPiece.m_rightLaneChangeNodes.Add(node);
                        }
                        else if (node.m_isPrimary)
                        {
                            a_trafficSystemPiece.m_primaryRightLaneNodes.Add(node);
                        }
                        else
                        {
                            //						bool wasInserted = false;
                            //						for(int sIndex = 0; sIndex < a_trafficSystemPiece.m_secondaryRightLaneNodes.Count; sIndex++)
                            //						{
                            //							if(a_trafficSystemPiece.m_secondaryRightLaneNodes[sIndex].m_priority > node.m_priority)
                            //							{
                            //								a_trafficSystemPiece.m_secondaryRightLaneNodes.Insert(sIndex, node);
                            //								wasInserted = true;
                            //								break;
                            //							}
                            //						}
                            //
                            //						if(!wasInserted)
                            a_trafficSystemPiece.m_secondaryRightLaneNodes.Add(node);
                        }
                    }
                }
            }

            for (int cIndex = 0; cIndex < a_obj.transform.childCount; cIndex++)
            {
                Transform child = a_obj.transform.GetChild(cIndex);
                if (child.gameObject)
                {
                    FindAllNodesRecursive(a_trafficSystemPiece, child.gameObject);
                }
            }
        }
    }
    void Awake()
    {
        // HACK - START
        ///       for some reason sometimes m_connectedNodes end up with null values ... have checked every inch of the code and found nothing! ... this removed them on Play so should clean any issues up.
        for(int cIndex = m_connectedNodes.Count - 1; cIndex >= 0; cIndex--)
        {
            if(m_connectedNodes[cIndex] == null)
                m_connectedNodes.RemoveAt(cIndex);
        }
        // HACK - END

        GameObject obj = TrafficSystemGameUtils.FindParentItem( gameObject, TrafficSystemGameUtils.GameObjectItem.TRAFFIC_SYSTEM_PIECE );
        if(obj && obj.GetComponent<TrafficSystemPiece>())
            Parent = obj.GetComponent<TrafficSystemPiece>();

        if(transform.childCount > 0)
            m_linkedIndicator = transform.GetChild(0).gameObject;

        if(Application.isPlaying)
            ShowRenderers(false);

        //		if(TrafficSystem.Instance && TrafficSystem.Instance.ShouldSpawnVehicle())
        //		{
        //			TrafficSystemVehicle prefab  = TrafficSystem.Instance.GetVehiclePrefabToSpawn();
        //			TrafficSystemVehicle vehicle = Instantiate( prefab, transform.position, transform.rotation ) as TrafficSystemVehicle;
        //			vehicle.m_nextNode           = this;
        //			vehicle.m_velocityMax        = Random.Range(TrafficSystem.Instance.m_randVelocityMin, TrafficSystem.Instance.m_randVelocityMax);
        //		}
    }
示例#8
0
    void Awake()
    {
        TrafficSystemPiece = (TrafficSystemPiece)target;

        TrafficSystemPiece.CleanUp( TrafficSystemPiece );

        //		Debug.Log (TrafficSystemPiece.gameObject.name + ": " + TrafficSystemPiece.m_renderer.bounds.extents);
    }
示例#9
0
    void FindAllNodesRecursive(TrafficSystemPiece a_trafficSystemPiece, GameObject a_obj)
    {
        if(a_obj)
        {
            if(a_obj.GetComponent<TrafficSystemNode>())
            {
                TrafficSystemNode node = a_obj.GetComponent<TrafficSystemNode>();
                if(node)
                {
                    if(node.m_driveSide == TrafficSystem.DriveSide.LEFT)
                    {
                        if(node.m_roadType == TrafficSystem.RoadType.CHANGE_LANE)
                            a_trafficSystemPiece.m_leftLaneChangeNodes.Add(node);
                        else if(node.m_isPrimary)
                            a_trafficSystemPiece.m_primaryLeftLaneNodes.Add(node);
                        else
                        {
                            //						bool wasInserted = false;
                            //						for(int sIndex = 0; sIndex < a_trafficSystemPiece.m_secondaryLeftLaneNodes.Count; sIndex++)
                            //						{
                            //							if(a_trafficSystemPiece.m_secondaryLeftLaneNodes[sIndex].m_priority > node.m_priority)
                            //							{
                            //								a_trafficSystemPiece.m_secondaryLeftLaneNodes.Insert(sIndex, node);
                            //								wasInserted = true;
                            //								break;
                            //							}
                            //						}
                            //
                            //						if(!wasInserted)
                            a_trafficSystemPiece.m_secondaryLeftLaneNodes.Add(node);
                        }
                    }
                    else
                    {
                        if(node.m_roadType == TrafficSystem.RoadType.CHANGE_LANE)
                            a_trafficSystemPiece.m_rightLaneChangeNodes.Add(node);
                        else if(node.m_isPrimary)
                            a_trafficSystemPiece.m_primaryRightLaneNodes.Add(node);
                        else
                        {
                            //						bool wasInserted = false;
                            //						for(int sIndex = 0; sIndex < a_trafficSystemPiece.m_secondaryRightLaneNodes.Count; sIndex++)
                            //						{
                            //							if(a_trafficSystemPiece.m_secondaryRightLaneNodes[sIndex].m_priority > node.m_priority)
                            //							{
                            //								a_trafficSystemPiece.m_secondaryRightLaneNodes.Insert(sIndex, node);
                            //								wasInserted = true;
                            //								break;
                            //							}
                            //						}
                            //
                            //						if(!wasInserted)
                            a_trafficSystemPiece.m_secondaryRightLaneNodes.Add(node);
                        }
                    }
                }
            }

            for(int cIndex = 0; cIndex < a_obj.transform.childCount; cIndex++)
            {
                Transform child = a_obj.transform.GetChild(cIndex);
                if(child.gameObject)
                    FindAllNodesRecursive(a_trafficSystemPiece, child.gameObject);
            }
        }
    }
示例#10
0
    void SetTrafficSystemPiece( TrafficSystem.TrafficSystemTooltip a_tooltip, TrafficSystemPiece a_obj )
    {
        switch(a_tooltip)
        {
        case TrafficSystem.TrafficSystemTooltip.ANCHOR:
        {
            AnchorTrafficSystemPiece = a_obj;

            if(TrafficSystem.Instance && AnchorTrafficSystemPiece)
            {
                TrafficSystem.Instance.PositionTooltip(a_tooltip, AnchorTrafficSystemPiece);
            }
        }
            break;
        case TrafficSystem.TrafficSystemTooltip.EDIT:
        {
            EditTrafficSystemPiece = a_obj;

            if(TrafficSystem.Instance && EditTrafficSystemPiece)
            {
                TrafficSystem.Instance.PositionTooltip(a_tooltip, EditTrafficSystemPiece);
            }
        }
            break;
        }
    }
示例#11
0
 public void SetTrafficSystemPiece( TrafficSystemPiece a_piece )
 {
     EditTrafficSystemPiece   = a_piece;
     AnchorTrafficSystemPiece = a_piece;
 }
示例#12
0
    //    void OnEnable()
    //    {
    //        TrafficSystem = GameObject.FindObjectOfType(typeof(TrafficSystem)) as TrafficSystem;
    //
    //        if(!TrafficSystem)
    //            Debug.LogError("Traffic System Error -> \"Traffic System\" script must be in the scene. It is missing. Drop in the \"Traffic System\" Prefab to fix this.");
    //    }
    public void ChangeChildRoadQuality( TrafficSystemPiece a_obj )
    {
        if(!a_obj)
            return;

        a_obj.GetComponent<TrafficSystemPiece>().ProcessRoadQuality( TrafficSystem.Instance.GetRoadQualityVal() );

        for(int cIndex = 0; cIndex < a_obj.transform.childCount; cIndex++)
        {
            if(a_obj.transform.GetChild(cIndex).GetComponent<TrafficSystemPiece>())
                ChangeChildRoadQuality(a_obj.transform.GetChild(cIndex).GetComponent<TrafficSystemPiece>());
        }
    }
示例#13
0
    void PositionTrafficSystemPiece( TrafficSystemPiece a_currentPiece, TrafficSystemPiece a_attachToPiece, bool a_incIndex = true, bool a_useEditOffset = false, bool a_useAnchorOffset = false )
    {
        if(!a_currentPiece)
            return;

        if(!a_attachToPiece)
            return;

        if(a_incIndex)
            m_roadAttachmentPointIndex++;

        if(m_roadAttachmentPointIndex == RoadAttachmentPoint.MAX)
            m_roadAttachmentPointIndex = RoadAttachmentPoint.NORTH;

        EditTrafficSystemPiece.transform.position = a_attachToPiece.transform.position;

        if(TrafficSystem.Instance.m_quickSpawn)
            EditTrafficSystemPiece.transform.rotation = a_attachToPiece.transform.rotation;

        Vector3 pos = a_attachToPiece.transform.position;

        if(a_currentPiece.m_renderer && a_attachToPiece.m_renderer)
        {
            EditTrafficSystemPiece.transform.position = a_attachToPiece.m_renderer.transform.position;
        //			EditTrafficSystemPiece.transform.rotation = a_attachToPiece.m_renderer.transform.rotation;
            pos = a_attachToPiece.m_renderer.transform.position;
        }

        float   roadPieceSize = m_roadPieceSize;

        switch(m_roadAttachmentPointIndex)
        {
        case RoadAttachmentPoint.EAST:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.z;

                float currentSize = a_currentPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.z;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.x = a_attachToPiece.m_renderer.transform.position.x + roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.SOUTH:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.x;

                float currentSize = a_currentPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.x;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.z = a_attachToPiece.m_renderer.transform.position.z - roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.WEST:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.z;

                float currentSize = a_currentPiece.GetRenderBounds().extents.x;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.z;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.x = a_attachToPiece.m_renderer.transform.position.x - roadPieceSize;
        }
            break;
        case RoadAttachmentPoint.NORTH:
        {
            if(a_attachToPiece.m_renderer && a_currentPiece.m_renderer)
            {
                float anchorSize  = a_attachToPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapAnchorDimensions)
                    anchorSize    = a_attachToPiece.GetRenderBounds().extents.x;

                float currentSize = a_currentPiece.GetRenderBounds().extents.z;
                if(TrafficSystem.Instance.m_swapEditDimensions)
                    currentSize   = a_currentPiece.GetRenderBounds().extents.x;

                roadPieceSize     = anchorSize + currentSize;
            }
            pos.z  = a_attachToPiece.m_renderer.transform.position.z + roadPieceSize;
        }
            break;
        }

        Vector3 posOffset = a_currentPiece.m_posOffset;
        if(a_useAnchorOffset)
            posOffset = a_attachToPiece.m_posOffset;

        Vector3 dir = a_attachToPiece.transform.position - pos;

        if(a_attachToPiece.m_renderer)
            dir = a_attachToPiece.m_renderer.transform.position - pos;

        dir = dir.normalized;

        if(a_useEditOffset || a_useAnchorOffset)
        {
        //			if(TrafficSystem.Instance.m_swapOffsetDir)
        //			{
        //				if(TrafficSystem.Instance.m_swapOffsetSize)
        //				{
        //					posOffset.x = posOffset.z * dir.z;
        //					posOffset.y = posOffset.y * dir.y;
        //					posOffset.z = posOffset.x * dir.x;
        //				}
        //				else
        //				{
        //					posOffset.x = posOffset.x * dir.z;
        //					posOffset.y = posOffset.y * dir.y;
        //					posOffset.z = posOffset.z * dir.x;
        //				}
        //			}
        //			else
        //			{
                if(TrafficSystem.Instance.m_swapOffsetSize)
                {
                    float x = posOffset.x;
                    posOffset.x = posOffset.z;
                    posOffset.y = posOffset.y;
                    posOffset.z = x;
                }
                else
                {
                    posOffset.x = posOffset.x;
                    posOffset.y = posOffset.y;
                    posOffset.z = posOffset.z;
                }
        //			}

            if(TrafficSystem.Instance.m_negateOffsetSize)
            {
                posOffset.x = -posOffset.x;
                posOffset.y = -posOffset.y;
                posOffset.z = -posOffset.z;
            }

            a_currentPiece.transform.position = pos + posOffset;
        }
        else
            a_currentPiece.transform.position = pos;

        UpdateEditTrafficSystemPiecePos();
    }
示例#14
0
    TrafficSystemPiece FindParentTrafficSystemPiece( TrafficSystemPiece a_obj )
    {
        if(a_obj.transform.parent && a_obj.transform.parent.GetComponent<TrafficSystemPiece>())
            a_obj = FindParentTrafficSystemPiece( a_obj.transform.parent.GetComponent<TrafficSystemPiece>() );

        return a_obj;
    }
示例#15
0
 public void SetTrafficSystemPiece( TrafficSystemTooltip a_tooltip, TrafficSystemPiece a_obj )
 {
     switch(a_tooltip)
     {
     case TrafficSystemTooltip.ANCHOR:
     {
         AnchorTrafficSystemPiece = a_obj;
         if(AnchorTrafficSystemPiece)
         {
             PositionTooltip(TrafficSystem.TrafficSystemTooltip.ANCHOR, AnchorTrafficSystemPiece);
         }
     }
         break;
     case TrafficSystemTooltip.EDIT:
     {
         EditTrafficSystemPiece = a_obj;
         if(EditTrafficSystemPiece)
         {
             PositionTooltip(TrafficSystem.TrafficSystemTooltip.EDIT, EditTrafficSystemPiece);
         }
     }
         break;
     }
 }
示例#16
0
 public void PositionTooltip( TrafficSystemTooltip a_tooltip, TrafficSystemPiece a_obj )
 {
     switch(a_tooltip)
     {
     case TrafficSystemTooltip.ANCHOR:
     {
         if(TooltipAnchor)
         {
             TooltipAnchor.transform.position = new Vector3(a_obj.transform.position.x, a_obj.transform.position.y + a_obj.m_renderer.bounds.extents.y + 2.0f, a_obj.transform.position.z);
         }
     }
         break;
     case TrafficSystemTooltip.EDIT:
     {
         if(TooltipEdit)
         {
             TooltipEdit.transform.position = new Vector3(a_obj.transform.position.x, a_obj.transform.position.y + a_obj.m_renderer.bounds.extents.y + 2.4f, a_obj.transform.position.z);
         }
     }
         break;
     }
 }