This commit is contained in:
Andras Schmelczer 2026-09-13 20:53:11 +01:00
commit 36a53f343e
16 changed files with 300431 additions and 0 deletions

View file

@ -0,0 +1,7 @@
# Misc scriptek
Az itteni kódok egyrésze triviális feladatot lát el, amit Unity-ben csak scripten keresztül lehet végrehajtani. A többi pedig szintén nem bonyolult, viszont kicsit fontosabb szerepe van.
A lényegesebb fájlok a :
+ trafficLightColor, ami a lámpák szinkronizálását végzi.
+ networkManagerCustom, ami a hálozati hibákat kezeli minimálisan
+ peopleTurning, ami az animált embereket irányítja

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 4d13aa4de089def459e4f9982889a5b7
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
/* A pályát elhagyó autókat (robbanás nem számít) számolja, és írja ki a 3D textbe.
*/
[NetworkSettings(channel = 0, sendInterval = 0.5f)]
public class carCount : NetworkBehaviour {
[SyncVar]
public int throughput = 0;
//Csak akkor updateli a szöveget, ha szükséges.
private int previous = 0;
public void Update ()
{
if (isServer) return;
if(throughput != previous)
{
previous = throughput;
GetComponent<TextMesh>().text = throughput.ToString();
}
}
[Server]
public void IncrementValue()
{
throughput++;
GetComponent<TextMesh>().text = throughput.ToString();
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a9f9e08d88a333c498413a0f763044ed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class destroyCar : NetworkBehaviour {
public carCount text;
void OnTriggerEnter (Collider other)
{
if(isServer) {
text.IncrementValue();
Destroy(other.gameObject);
}
}
}

View file

@ -0,0 +1,17 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class destroyCar : NetworkBehaviour {
public carCount text;
void OnTriggerEnter (Collider other)
{
if(isServer) {
text.IncrementValue();
Destroy(other.gameObject);
}
}
}

View file

@ -0,0 +1,12 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class moveForward : MonoBehaviour {
public float speed = 1;
void FixedUpdate () {
transform.position += transform.forward * speed * Time.deltaTime;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f6f156956c17e3d4ab528b1dc6be0b3b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
/* Saját NetworkManager, hogy a hálozati hibakezelést meg lehessen vele valósítani.
*/
public class networkManagerCustom : NetworkManager
{
public GameObject offlineCanvas;
public GameObject onlineCanvas;
public override void OnClientDisconnect (NetworkConnection conn)
{
//onlineCanvas.SetActive(false);
offlineCanvas.SetActive(true);
offlineCanvas.GetComponent<clientMenu>().errorField.text = "Error: " + conn.lastError.ToString();
base.OnServerDisconnect(conn);
}
public override void OnClientConnect (NetworkConnection conn)
{
//onlineCanvas.SetActive(true);
offlineCanvas.GetComponent<clientMenu>().errorField.text = "No errors so far.";
offlineCanvas.SetActive(false);
base.OnClientConnect(conn);
}
public override void OnClientError (NetworkConnection conn, int errorCode)
{
onlineCanvas.SetActive(false);
offlineCanvas.SetActive(true);
offlineCanvas.GetComponent<clientMenu>().errorField.text = "Error: " + conn.lastError.ToString();
base.OnClientError(conn, errorCode);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c0f1c6e8020f95342a7ca0d014c3551d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Minimális logika, hogy az animált emberek megfelelően változtassanak irányt.
* A prefabs mappában található megfelelő prefab lerakásával lehet 90°-os fordulásra bíztatni az embereket.
* Az előbbit lassan, szép átmenettel csinálja. Tud 180°-ot is fordulni, azt ugrásszerűen végzi.
*/
public class peopleTurning : MonoBehaviour {
public float turningSpeed = 0.1f;
private float turningSpeedWithDirection;
private bool isTurning = false;
public float currentAngle;
public float endAngle;
void FixedUpdate () {
if(isTurning)
{
currentAngle += turningSpeedWithDirection * Time.deltaTime;
transform.rotation = Quaternion.AngleAxis(currentAngle, transform.up);
if (Mathf.Abs(currentAngle % 360 - endAngle) < 10)
{
transform.rotation = Quaternion.AngleAxis(endAngle, transform.up);
isTurning = false;
}
}
}
private void OnTriggerEnter (Collider other)
{
if (!isTurning)
{
if (other.tag == "peopleTurnRight")
{
isTurning = true;
currentAngle = transform.rotation.eulerAngles.y;
endAngle = currentAngle + 90;
turningSpeedWithDirection = turningSpeed;
}
else if (other.tag == "peopleTurnLeft")
{
isTurning = true;
currentAngle = transform.rotation.eulerAngles.y;
endAngle = currentAngle - 90;
turningSpeedWithDirection = -turningSpeed;
}
}
if (other.tag == "peopleTurnAround")
{
transform.rotation = Quaternion.AngleAxis(transform.rotation.eulerAngles.y + 180, transform.up);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e3dd0ff0484ad1e4c87a15c030d51b83
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Megfelelő safeSpace-k elhelyezésével lehet figyelni, hogy adott pozicíóban van-e még szabad helye egy új autónak.
*/
public class safeSpace : MonoBehaviour {
public int roadID;
public TrafficController traffic;
void OnTriggerEnter ()
{
traffic.roads[roadID].isThereSpace = false;
}
void OnTriggerExit ()
{
traffic.roads[roadID].isThereSpace = true;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed316f5bd09830c46bd502b7cb2bed3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 200
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed316f5bd09830c46bd502b7cb2bed3f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 200
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 868d3726895a3414b86334e7957eb8ea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: