void OnTriggerEnter(Collider other) { if (other.tag == tag) { Part part = other.GetComponentInParent <Part>(); if (part == null || part.separated) { return; } HandController grabbedHand = part.grabbedBy; if (grabbedHand == null || grabbedHand.state != HandController.State.Deconstructing) { return; } Part newPart = Instantiate(part); newPart.transform.position = part.transform.position; newPart.transform.rotation = part.transform.rotation; newPart.separated = true; newPart.originJoint.connectedBody = null; Rigidbody rigidbody = newPart.GetComponent <Rigidbody>(); rigidbody.useGravity = true; grabbedHand.Attach(newPart); part.gameObject.SetActive(false); } }
void PickupOrder() { if (pointerState == PointerState.Gaze) { if (!reticleRend.enabled) { reticleRend.enabled = true; } if (fillRndObj.activeSelf) { fillRndPonter.OnPointerExit(); fillRndObj.SetActive(false); } } else if (pointerState == PointerState.Fill) { if (reticleRend.enabled) { reticleRend.enabled = false; } if (!fillRndObj.activeSelf) { fillRndObj.SetActive(true); } fillRndPonter.OnPointerHover(); if (prevState == PointerState.Fill && pointerState == PointerState.Gaze) { if (handCtrl != null && handCtrl.handState == HandState.None && gazedAtObject != null) { // Pick up handCtrl.Pickup(gazedAtObject); } else if (handCtrl != null && handCtrl.handState == HandState.Pick && gazedSpot != Vector3.zero) { // Attach parts handCtrl.Attach(gazedSpot); } } } else { if (reticleRend.enabled) { reticleRend.enabled = false; } if (fillRndObj.activeSelf) { fillRndPonter.OnPointerExit(); fillRndObj.SetActive(false); } } prevState = pointerState; }
void Update() { if (_sockets.Length == 0) { return; } bool allOverlapped = true; foreach (var socket in _sockets) { if (!socket.partOverlapped) { allOverlapped = false; break; } } if (allOverlapped && shouldActivate) { Part part = _sockets[0].partOverlapped; if (part == null) { return; } HandController handController = part.grabbedBy; if (handController == null || handController.state != HandController.State.Constructing) { return; } shouldActivate.gameObject.SetActive(true); shouldActivate.separated = false; shouldActivate.RestoreConnection(); Destroy(part.gameObject); foreach (var socket in _sockets) { socket.partOverlapped = null; } handController.Attach(shouldActivate); } }