forked from cgvr/DeltaVR
printer input hole animation
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class Printer3DInputHole : MonoBehaviour
|
||||
{
|
||||
public Printer3D printer;
|
||||
public XRInteractionManager interactionManager;
|
||||
public Transform insertionOrigin;
|
||||
public Transform insertionDestination;
|
||||
public float insertionDuration = 1f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -26,10 +30,56 @@ public class Printer3DInputHole : MonoBehaviour
|
||||
Printable printable = parent.GetComponent<Printable>();
|
||||
if (printable != null)
|
||||
{
|
||||
printer.PrintObject(printable.GetTexture());
|
||||
Destroy(printable.gameObject);
|
||||
if (printer.IsPrinting())
|
||||
{
|
||||
Debug.Log("priner is busy!");
|
||||
} else
|
||||
{
|
||||
ReleaseFromPlayer(printable);
|
||||
InsertPrintable(printable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ReleaseFromPlayer(Printable printable)
|
||||
{
|
||||
|
||||
var grab = printable.GetComponent<XRGrabInteractable>();
|
||||
var rb = printable.GetComponent<Rigidbody>();
|
||||
|
||||
// 1) If currently held, force release from the interactor
|
||||
if (grab != null && grab.isSelected)
|
||||
{
|
||||
var interactor = grab.firstInteractorSelecting; // the hand/controller currently holding it
|
||||
if (interactor != null)
|
||||
{
|
||||
// Transfer ownership: tell the manager to stop the selection
|
||||
interactionManager.SelectExit(interactor, grab);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) Make sure physics doesn't fight the tween (optional but recommended)
|
||||
if (rb != null)
|
||||
{
|
||||
rb.isKinematic = true; // prevent forces during tween
|
||||
rb.velocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
// 3) Optionally disable grabbing during the tween so the player can't re-grab mid-flight
|
||||
if (grab != null) grab.enabled = false;
|
||||
}
|
||||
|
||||
private void InsertPrintable(Printable printable)
|
||||
{
|
||||
Transform printableTransform = printable.transform;
|
||||
printableTransform.position = insertionOrigin.position;
|
||||
printableTransform.rotation = insertionOrigin.rotation;
|
||||
printableTransform.DOMove(insertionDestination.position, insertionDuration).OnComplete(() =>
|
||||
{
|
||||
printer.PrintObject(printable.GetTexture());
|
||||
Destroy(printable.gameObject);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user