mirror of
https://github.com/DerTyp7/traffic-unity.git
synced 2025-10-30 05:07:10 +01:00
Add project files.
This commit is contained in:
8
Assets/Scripts/BuildingSystem.meta
Normal file
8
Assets/Scripts/BuildingSystem.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2633af91422c23f46a89b1e2b54c4074
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/Scripts/BuildingSystem/NodePlacer.cs
Normal file
29
Assets/Scripts/BuildingSystem/NodePlacer.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class NodePlacer : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private GameObject nodeObject;
|
||||
|
||||
[SerializeField]
|
||||
private TrafficNode prevPlacedNode;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.B))
|
||||
{
|
||||
Vector3 newPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
newPosition.z = 0;
|
||||
TrafficNode newNode = Instantiate(nodeObject, newPosition, Quaternion.identity).GetComponent<TrafficNode>();
|
||||
|
||||
if (prevPlacedNode != null)
|
||||
{
|
||||
prevPlacedNode.AddNextNode(newNode);
|
||||
|
||||
}
|
||||
prevPlacedNode = newNode;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/BuildingSystem/NodePlacer.cs.meta
Normal file
11
Assets/Scripts/BuildingSystem/NodePlacer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4da8003edf1936e4b9a1af5a937c1074
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/Scripts/TrafficSystem.meta
Normal file
8
Assets/Scripts/TrafficSystem.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8a759e83ab2e8bd49a923efeddbe427e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/TrafficSystem/TrafficNode.cs
Normal file
28
Assets/Scripts/TrafficSystem/TrafficNode.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TrafficNode : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private List<TrafficNode> nextTrafficNodes;
|
||||
|
||||
public List<TrafficNode> GetNextTrafficNodes() { return nextTrafficNodes; }
|
||||
|
||||
public void AddNextNode(TrafficNode node)
|
||||
{
|
||||
nextTrafficNodes.Add(node);
|
||||
}
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.green;
|
||||
Gizmos.DrawSphere(transform.position, 0.2f);
|
||||
foreach (TrafficNode node in nextTrafficNodes)
|
||||
{
|
||||
if (node != null)
|
||||
{
|
||||
Gizmos.color = Color.blue;
|
||||
Gizmos.DrawLine(transform.position, node.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TrafficSystem/TrafficNode.cs.meta
Normal file
11
Assets/Scripts/TrafficSystem/TrafficNode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23522bc3f6b64e9478f91a82fa664918
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Assets/Scripts/TrafficSystem/TrafficParticipant.cs
Normal file
65
Assets/Scripts/TrafficSystem/TrafficParticipant.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class TrafficParticipant : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TrafficNode nextNode;
|
||||
|
||||
[SerializeField]
|
||||
private TrafficNode currentTrafficNode;
|
||||
|
||||
[SerializeField]
|
||||
private float speed = 5f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
if (nextNode == null)
|
||||
{
|
||||
ChooseNextNode();
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (nextNode != null)
|
||||
{
|
||||
transform.position = Vector3.MoveTowards(transform.position, nextNode.transform.position, speed * Time.deltaTime); if (transform.position == nextNode.transform.position)
|
||||
{
|
||||
Arrived();
|
||||
ChooseNextNode();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ChooseNextNode();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Arrived()
|
||||
{
|
||||
Debug.Log("Arrived");
|
||||
currentTrafficNode = nextNode;
|
||||
nextNode = null;
|
||||
}
|
||||
|
||||
private void ChooseNextNode()
|
||||
{
|
||||
Debug.Log("Choose next node");
|
||||
if (nextNode == null)
|
||||
{
|
||||
nextNode = currentTrafficNode.GetNextTrafficNodes()[Random.Range(0, (currentTrafficNode.GetNextTrafficNodes().Count))];
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
if (nextNode != null)
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
|
||||
Gizmos.DrawLine(transform.position, nextNode.transform.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/TrafficSystem/TrafficParticipant.cs.meta
Normal file
11
Assets/Scripts/TrafficSystem/TrafficParticipant.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a6d45731a032c2940adc3df033eab75f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user