Integrate Zwiebeln schneiden in 3.2 (wip)
This commit is contained in:
parent
8fe605216c
commit
3a28c19bc1
File diff suppressed because it is too large
Load Diff
@ -11,7 +11,7 @@ public class OnCollideSound : MonoBehaviour
|
||||
{
|
||||
#if FMOD_AVAILABLE
|
||||
[SerializeField]
|
||||
EventReference soundRef;
|
||||
public EventReference soundRef;
|
||||
|
||||
[SerializeField]
|
||||
float minVelocity = 0.1f;
|
||||
@ -25,7 +25,7 @@ public class OnCollideSound : MonoBehaviour
|
||||
private bool _specialCase = false;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Start()
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class OnGrabSound : MonoBehaviour
|
||||
{
|
||||
#if FMOD_AVAILABLE
|
||||
[SerializeField]
|
||||
EventReference soundRef;
|
||||
public EventReference soundRef;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
|
@ -4,6 +4,11 @@ using UnityEngine;
|
||||
using EzySlice;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
using System;
|
||||
#if FMOD_AVAILABLE
|
||||
using FMOD;
|
||||
using FMODUnity;
|
||||
#endif
|
||||
|
||||
public class SliceObjectsVR : MonoBehaviour
|
||||
{
|
||||
@ -17,6 +22,14 @@ public class SliceObjectsVR : MonoBehaviour
|
||||
private Vector3 lastSlicerPosition; // Letzte Position von SLICER
|
||||
private Vector3 slicerVelocity; // Berechnete Geschwindigkeit von SLICER
|
||||
|
||||
#if FMOD_AVAILABLE
|
||||
[SerializeField]
|
||||
EventReference onGrabSoundRef;
|
||||
|
||||
[SerializeField]
|
||||
EventReference onCollideSoundRef;
|
||||
#endif
|
||||
|
||||
void Start()
|
||||
{
|
||||
lastSlicerPosition = transform.position; // Startposition speichern
|
||||
@ -28,10 +41,7 @@ public class SliceObjectsVR : MonoBehaviour
|
||||
slicerVelocity = (transform.position - lastSlicerPosition) / Time.fixedDeltaTime;
|
||||
lastSlicerPosition = transform.position;
|
||||
|
||||
// Debugging: Prüfen, ob die Velocity sinnvoll ist
|
||||
//Debug.Log($"SLICER Velocity: {slicerVelocity}, Magnitude: {slicerVelocity.magnitude}");
|
||||
|
||||
// Prüfen, ob ein schneidbares Objekt getroffen wird
|
||||
// Pruefen, ob ein schneidbares Objekt getroffen wird
|
||||
bool hasHit = Physics.Linecast(startSlicePoint.position, endSlicePoint.position, out RaycastHit hit, sliceableLayer);
|
||||
if (hasHit)
|
||||
{
|
||||
@ -42,22 +52,18 @@ public class SliceObjectsVR : MonoBehaviour
|
||||
|
||||
public void Slice(GameObject target)
|
||||
{
|
||||
//Debug.Log("Slice Function active: " + target.name);
|
||||
|
||||
// Normalenvektor für die Schnittebene berechnen
|
||||
// Normalenvektor fuer die Schnittebene berechnen
|
||||
Vector3 planeNormal = Vector3.Cross(endSlicePoint.position - startSlicePoint.position, slicerVelocity);
|
||||
planeNormal.Normalize();
|
||||
|
||||
//Debug.Log($"Direction: {planeNormal}, Magnitude: {planeNormal.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);
|
||||
|
||||
if (hull != null)
|
||||
{
|
||||
//Debug.Log("Hull isn't empty");
|
||||
|
||||
GameObject upperHull = hull.CreateUpperHull(target, crossSectionMaterial);
|
||||
SetupSlicedComponent(upperHull);
|
||||
|
||||
@ -70,15 +76,29 @@ public class SliceObjectsVR : MonoBehaviour
|
||||
|
||||
public void SetupSlicedComponent(GameObject slicedObject)
|
||||
{
|
||||
//Debug.Log("New object created");
|
||||
Rigidbody rb = slicedObject.AddComponent<Rigidbody>(); //add Rigidbody
|
||||
rb.interpolation = RigidbodyInterpolation.Interpolate;
|
||||
|
||||
MeshCollider collider = slicedObject.AddComponent<MeshCollider>(); //add Meshcolider
|
||||
collider.convex = true; //make Collider convex
|
||||
|
||||
rb.AddExplosionForce(cutForce, slicedObject.transform.position, explosionRadius); //add force for realistic behaviour
|
||||
|
||||
slicedObject.layer = 6; // 6 = "sliceableLayer"
|
||||
slicedObject.AddComponent<XRGrabInteractable>(); //add grabbable Script
|
||||
slicedObject.AddComponent<ComponentController>(); //add BT-Controller
|
||||
slicedObject.AddComponent<OnGrabSound>(); //add grab sound
|
||||
slicedObject.AddComponent<OnCollideSound>(); //add collision sound
|
||||
|
||||
XRGrabInteractable grabInteractable = slicedObject.AddComponent<XRGrabInteractable>(); //add grabbable Script
|
||||
grabInteractable.movementType = XRBaseInteractable.MovementType.VelocityTracking;
|
||||
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}";
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ TagManager:
|
||||
- Parmigiano
|
||||
- Topf
|
||||
- Messer
|
||||
- SlicedZwiebel
|
||||
layers:
|
||||
- Default
|
||||
- TransparentFX
|
||||
|
Loading…
x
Reference in New Issue
Block a user