Cleaned up and commented version.
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
// Ehemaliges Skript für die Start-Szene. Nicht mehr in Verwendung
|
||||
|
||||
public class GameStarter : MonoBehaviour
|
||||
{
|
||||
[SerializeField] int startScene = 1;
|
||||
private int currentscene;
|
||||
private int nextscene;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
StopRecordingTrigger.OnRecordStop += HandleRecordStop;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
StopRecordingTrigger.OnRecordStop -= HandleRecordStop;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(this);
|
||||
currentscene = startScene;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
|
||||
{
|
||||
if (SceneManager.GetActiveScene() != SceneManager.GetSceneByBuildIndex(startScene)) return;
|
||||
nextscene = currentscene + 1;
|
||||
currentscene = nextscene;
|
||||
StartGameByLoadingScene(nextscene);
|
||||
}
|
||||
}
|
||||
|
||||
void StartGameByLoadingScene(int sceneIndex)
|
||||
{
|
||||
SceneManager.LoadScene(sceneIndex);
|
||||
}
|
||||
|
||||
private void HandleRecordStop()
|
||||
{
|
||||
StartGameByLoadingScene(startScene);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e580ea451ce98a24b81fd7e238ac6393
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Globalization;
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
// Hilfs-Skript um bestimmte Objekte für den lokalen Spieler unsichtbar zu machen. Findet momentan keine Anwendung.
|
||||
|
||||
public class InvisibleForLocalPlayer : NetworkBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
foreach (var r in GetComponentsInChildren<Renderer>())
|
||||
{
|
||||
r.enabled = !IsOwner;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 819e00be8a4fb934ba765757fac39145
|
||||
@@ -0,0 +1,47 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
public class LocalOnly : NetworkBehaviour
|
||||
{
|
||||
public Behaviour[] componentsToDisable;
|
||||
public GameObject[] objectsToDisable;
|
||||
public GameObject[] objectsToTag;
|
||||
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
if (!IsOwner)
|
||||
{
|
||||
|
||||
foreach (var comp in componentsToDisable)
|
||||
{
|
||||
if (comp != null) comp.enabled = false;
|
||||
}
|
||||
|
||||
foreach (var obj in objectsToDisable)
|
||||
{
|
||||
if (obj != null) obj.SetActive(false);
|
||||
}
|
||||
|
||||
foreach(var obj in objectsToTag)
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
obj.tag = "RemotePlayer";
|
||||
obj.layer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Kamera-Tags sicherstellen
|
||||
Camera cam = GetComponentInChildren<Camera>();
|
||||
if (cam != null && cam.CompareTag("MainCamera"))
|
||||
cam.enabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Nur der lokale Spieler darf "MainCamera" haben
|
||||
Camera cam = GetComponentInChildren<Camera>();
|
||||
if (cam != null)
|
||||
cam.tag = "MainCamera";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3b7b9f0672db49f42af8fec3493cb307
|
||||
@@ -0,0 +1,16 @@
|
||||
using Unity.Netcode;
|
||||
using UnityEngine;
|
||||
|
||||
// Script zum Spawnen der Spieler im Multiplayer. Aktuell nicht in Benutzung.
|
||||
|
||||
public class PlayerSpawner : NetworkBehaviour
|
||||
{
|
||||
public override void OnNetworkSpawn()
|
||||
{
|
||||
if (IsOwner)
|
||||
{
|
||||
var spawnPoints = GameObject.FindGameObjectsWithTag("SpawnPoint");
|
||||
transform.position = spawnPoints[Random.Range(0, spawnPoints.Length)].transform.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46b4f915883259f4fbff20729a599ded
|
||||
@@ -0,0 +1,80 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
// Script zur automatisierten Ausrichtung der Basis-Szene am Spielbereich. Wird in der aktuellen Version nicht verwendet.
|
||||
|
||||
public class SpawnAtLongestEdge : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] GameObject roomPrefab;
|
||||
[SerializeField] GameObject pointPrefab;
|
||||
[SerializeField] GameObject reticlePrefab;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// Prüfe, ob die Boundary aktiviert ist
|
||||
if (OVRManager.boundary != null)
|
||||
{
|
||||
// Hole die Boundary-Geometrie (Play Area)
|
||||
Vector3[] boundaryPoints = OVRManager.boundary.GetGeometry(OVRBoundary.BoundaryType.PlayArea);
|
||||
|
||||
if (boundaryPoints != null && boundaryPoints.Length > 0)
|
||||
{
|
||||
Debug.Log("Boundary Points gefunden: " + boundaryPoints.Length);
|
||||
AlignObjectToLongestEdge(boundaryPoints);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Keine Boundary Points gefunden.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("OVRManager.boundary ist nicht aktiviert.");
|
||||
}
|
||||
}
|
||||
|
||||
void AlignObjectToLongestEdge(Vector3[] boundaryPoints)
|
||||
{
|
||||
float maxLength = 0f;
|
||||
Vector3 longestEdgeStart = Vector3.zero;
|
||||
Vector3 longestEdgeEnd = Vector3.zero;
|
||||
|
||||
// Iteriere über die Punkte und finde die längste Kante
|
||||
for (int i = 0; i < boundaryPoints.Length; i++)
|
||||
{
|
||||
Vector3 start = boundaryPoints[i];
|
||||
Vector3 end = boundaryPoints[(i + 1) % boundaryPoints.Length]; // Modulo für den letzten Punkt
|
||||
|
||||
// Debug Visuals for Points
|
||||
Instantiate(pointPrefab, start, Quaternion.LookRotation(end));
|
||||
|
||||
float length = Vector3.Distance(start, end);
|
||||
if (length > maxLength)
|
||||
{
|
||||
maxLength = length;
|
||||
longestEdgeStart = start;
|
||||
longestEdgeEnd = end;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log($"Längste Kante gefunden: Start({longestEdgeStart}), Ende({longestEdgeEnd}), Länge: {maxLength}");
|
||||
|
||||
// Richte dein Objekt aus
|
||||
Vector3 midPoint = (longestEdgeStart + longestEdgeEnd) / 2;
|
||||
Vector3 direction = (longestEdgeEnd - longestEdgeStart).normalized;
|
||||
|
||||
Instantiate(roomPrefab, midPoint, Quaternion.LookRotation(direction));
|
||||
Transform reticle = Instantiate(reticlePrefab, longestEdgeStart, Quaternion.LookRotation(direction)).transform;
|
||||
reticle.position = new Vector3 (reticle.position.x - 0.75f, reticle.position.y, reticle.position.z + 1);
|
||||
|
||||
// Beispiel: Objekt positionieren und ausrichten
|
||||
//Transform objTransform = this.transform;
|
||||
//objTransform.position = midPoint;
|
||||
//objTransform.rotation = Quaternion.LookRotation(direction);
|
||||
|
||||
Debug.Log("Objekt wurde an der längsten Kante ausgerichtet.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78d0b4c770471684b819e3235a0688bf
|
||||
Reference in New Issue
Block a user