Integrate Zwiebeln schneiden in 3.2 (wip)

This commit is contained in:
Nadine Ganz 2025-03-10 19:42:58 +01:00
parent 8fe605216c
commit 3a28c19bc1
5 changed files with 972171 additions and 972076 deletions

File diff suppressed because it is too large Load Diff

View File

@ -11,7 +11,7 @@ public class OnCollideSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE #if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference soundRef; public EventReference soundRef;
[SerializeField] [SerializeField]
float minVelocity = 0.1f; float minVelocity = 0.1f;
@ -25,7 +25,7 @@ public class OnCollideSound : MonoBehaviour
private bool _specialCase = false; private bool _specialCase = false;
private Rigidbody _rigidbody; private Rigidbody _rigidbody;
private void Start() private void Awake()
{ {
_rigidbody = GetComponent<Rigidbody>(); _rigidbody = GetComponent<Rigidbody>();
} }

View File

@ -12,7 +12,7 @@ public class OnGrabSound : MonoBehaviour
{ {
#if FMOD_AVAILABLE #if FMOD_AVAILABLE
[SerializeField] [SerializeField]
EventReference soundRef; public EventReference soundRef;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()

View File

@ -4,6 +4,11 @@ using UnityEngine;
using EzySlice; using EzySlice;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.XR.Interaction.Toolkit; using UnityEngine.XR.Interaction.Toolkit;
using System;
#if FMOD_AVAILABLE
using FMOD;
using FMODUnity;
#endif
public class SliceObjectsVR : MonoBehaviour public class SliceObjectsVR : MonoBehaviour
{ {
@ -17,6 +22,14 @@ public class SliceObjectsVR : MonoBehaviour
private Vector3 lastSlicerPosition; // Letzte Position von SLICER private Vector3 lastSlicerPosition; // Letzte Position von SLICER
private Vector3 slicerVelocity; // Berechnete Geschwindigkeit von SLICER private Vector3 slicerVelocity; // Berechnete Geschwindigkeit von SLICER
#if FMOD_AVAILABLE
[SerializeField]
EventReference onGrabSoundRef;
[SerializeField]
EventReference onCollideSoundRef;
#endif
void Start() void Start()
{ {
lastSlicerPosition = transform.position; // Startposition speichern lastSlicerPosition = transform.position; // Startposition speichern
@ -28,10 +41,7 @@ public class SliceObjectsVR : MonoBehaviour
slicerVelocity = (transform.position - lastSlicerPosition) / Time.fixedDeltaTime; slicerVelocity = (transform.position - lastSlicerPosition) / Time.fixedDeltaTime;
lastSlicerPosition = transform.position; lastSlicerPosition = transform.position;
// Debugging: Prüfen, ob die Velocity sinnvoll ist // Pruefen, ob ein schneidbares Objekt getroffen wird
//Debug.Log($"SLICER Velocity: {slicerVelocity}, Magnitude: {slicerVelocity.magnitude}");
// Prüfen, ob ein schneidbares Objekt getroffen wird
bool hasHit = Physics.Linecast(startSlicePoint.position, endSlicePoint.position, out RaycastHit hit, sliceableLayer); bool hasHit = Physics.Linecast(startSlicePoint.position, endSlicePoint.position, out RaycastHit hit, sliceableLayer);
if (hasHit) if (hasHit)
{ {
@ -42,22 +52,18 @@ public class SliceObjectsVR : MonoBehaviour
public void Slice(GameObject target) public void Slice(GameObject target)
{ {
//Debug.Log("Slice Function active: " + target.name); // Normalenvektor fuer die Schnittebene berechnen
// Normalenvektor für die Schnittebene berechnen
Vector3 planeNormal = Vector3.Cross(endSlicePoint.position - startSlicePoint.position, slicerVelocity); Vector3 planeNormal = Vector3.Cross(endSlicePoint.position - startSlicePoint.position, slicerVelocity);
planeNormal.Normalize(); planeNormal.Normalize();
//Debug.Log($"Direction: {planeNormal}, Magnitude: {planeNormal.magnitude}"); //Debug.Log($"Direction: {planeNormal}, Magnitude: {planeNormal.magnitude}");
//Debug.Log($"Velocity: {slicerVelocity}, Magnitude: {slicerVelocity.magnitude}"); //Debug.Log($"Velocity: {slicerVelocity}, Magnitude: {slicerVelocity.magnitude}");
// Prüfen, ob das Objekt geschnitten werden kann // Pruefen, ob das Objekt geschnitten werden kann
SlicedHull hull = target.Slice(endSlicePoint.position, planeNormal); SlicedHull hull = target.Slice(endSlicePoint.position, planeNormal);
if (hull != null) if (hull != null)
{ {
//Debug.Log("Hull isn't empty");
GameObject upperHull = hull.CreateUpperHull(target, crossSectionMaterial); GameObject upperHull = hull.CreateUpperHull(target, crossSectionMaterial);
SetupSlicedComponent(upperHull); SetupSlicedComponent(upperHull);
@ -70,15 +76,29 @@ public class SliceObjectsVR : MonoBehaviour
public void SetupSlicedComponent(GameObject slicedObject) public void SetupSlicedComponent(GameObject slicedObject)
{ {
//Debug.Log("New object created");
Rigidbody rb = slicedObject.AddComponent<Rigidbody>(); //add Rigidbody Rigidbody rb = slicedObject.AddComponent<Rigidbody>(); //add Rigidbody
rb.interpolation = RigidbodyInterpolation.Interpolate;
MeshCollider collider = slicedObject.AddComponent<MeshCollider>(); //add Meshcolider MeshCollider collider = slicedObject.AddComponent<MeshCollider>(); //add Meshcolider
collider.convex = true; //make Collider convex collider.convex = true; //make Collider convex
rb.AddExplosionForce(cutForce, slicedObject.transform.position, explosionRadius); //add force for realistic behaviour rb.AddExplosionForce(cutForce, slicedObject.transform.position, explosionRadius); //add force for realistic behaviour
slicedObject.layer = 6; // 6 = "sliceableLayer" slicedObject.layer = 6; // 6 = "sliceableLayer"
slicedObject.AddComponent<XRGrabInteractable>(); //add grabbable Script
slicedObject.AddComponent<ComponentController>(); //add BT-Controller XRGrabInteractable grabInteractable = slicedObject.AddComponent<XRGrabInteractable>(); //add grabbable Script
slicedObject.AddComponent<OnGrabSound>(); //add grab sound grabInteractable.movementType = XRBaseInteractable.MovementType.VelocityTracking;
slicedObject.AddComponent<OnCollideSound>(); //add collision sound grabInteractable.useDynamicAttach = true;
#if FMOD_AVAILABLE
OnGrabSound onGrabSoundScript = slicedObject.AddComponent<OnGrabSound>(); //add grab sound
onGrabSoundScript.soundRef = onGrabSoundRef;
OnCollideSound onCollideSoundScript = slicedObject.AddComponent<OnCollideSound>(); //add collision sound
onCollideSoundScript.soundRef = onCollideSoundRef;
#endif
slicedObject.gameObject.tag = "SlicedZwiebel";
string timeStamp = DateTime.Now.ToString("mmssffff");
slicedObject.gameObject.name = $"SlicedZwiebel_{timeStamp}";
} }
} }

View File

@ -18,6 +18,7 @@ TagManager:
- Parmigiano - Parmigiano
- Topf - Topf
- Messer - Messer
- SlicedZwiebel
layers: layers:
- Default - Default
- TransparentFX - TransparentFX