void UpdateHolding() { if (!_grabbedObject || !_grabbedObject.gameObject.activeInHierarchy) { UngrabObject(); _state = ImpulseGunState.Idle; } if (_highlighted != null) { MetablastUI.Instance.HudView.ContextMessageView.SetLowPriorityText("Move bioship or Left click to throw " + _highlighted.BiologEntry); } else { MetablastUI.Instance.HudView.ContextMessageView.SetLowPriorityText("Move bioship or Left click to throw object"); } if (GameState.Instance.PauseLevel == PauseLevel.Unpaused && _grabbedObject != null) { if (!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0)) { ThrowObject(); MetablastUI.Instance.HudView.ContextMessageView.SetLowPriorityText(""); } } }
void UpdateGrabbing() { if (!_grabbedObject || !_grabbedObject.gameObject.activeInHierarchy) { UngrabObject(); _state = ImpulseGunState.Idle; return; } if (!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0)) { UngrabObject(); return; } Vector3 offset = enabled ? _cameraController.Camera.transform.forward * 3 : transform.forward * 3; Vector3 targetPosition = transform.TransformPoint(_targetOffset) + offset; Vector3 currentPosition = _grabbedObject.GetComponent <Rigidbody>().worldCenterOfMass; float distance = Vector3.Distance(targetPosition, currentPosition); if (distance < _holdingDistanceThreshold) { HoldObject(_grabbedObject); _state = ImpulseGunState.Holding; } Vector3 pullForce = (targetPosition - currentPosition).normalized; Debug.DrawLine(targetPosition, currentPosition, Color.green); _grabbedObject.GetComponent <Rigidbody>().AddForce(pullForce * _pullForce, ForceMode.Impulse); }
private void ThrowObject() { if (enabled) { _throwingStartTime = Time.time; _state = ImpulseGunState.Throwing; } }
void Awake() { _layerMask = new LayerMask(); _layerMask = 1 << LayerMask.NameToLayer("GrabbableObject"); _controlServices = GetComponent <ControlServices>(); _cameraController = _controlServices.ControlledCamera; _holdObjectFunction = GetComponent <HoldObjectFunction>(); _state = ImpulseGunState.Idle; GameContext.Instance.Player.ImpulseBeamTool = this; }
private void UngrabObject() { if (_grabbedObject) { AnalyticsLogger.Instance.AddLogEntry(new ObjectDroppedLogEntry(GameContext.Instance.Player.UserGuid, _grabbedObject)); _grabbedObject.GetComponent <Rigidbody>().useGravity = _originalGravity; _grabbedObject.GetComponent <Rigidbody>().drag = _originalDrag; _grabbedObject.GetComponent <Rigidbody>().angularDrag = _originalAngularDrag; _state = ImpulseGunState.Idle; if (PlayerDroppedObject != null) { PlayerDroppedObject(_grabbedObject); } _grabbedObject = null; _holdObjectFunction.ReleaseObject(); } }
void UpdateThrowing() { if (!_grabbedObject || !_grabbedObject.gameObject.activeInHierarchy) { UngrabObject(); _state = ImpulseGunState.Idle; } if (Time.time - _throwingStartTime >= _throwingTime || Input.GetMouseButtonUp(0)) { Vector3 direction = _cameraController.Camera.transform.forward; Vector3 force = Vector3.zero; float power = (Time.time - _throwingStartTime) / _throwingTime; power *= power; Rigidbody grabbedObject = _grabbedObject.GetComponent <Rigidbody>(); UngrabObject(); grabbedObject.AddForce(direction * _maximumThrowForce * power, ForceMode.Impulse); } }
void UpdateIdle() { if (!_cameraController.Camera) { return; } Ray ray = _cameraController.Camera.ScreenPointToRay(Input.mousePosition); RaycastHit hitInfo; if (Physics.Raycast(ray, out hitInfo, _maxGrabDistance, _layerMask)) { GameObject hitObject = hitInfo.collider.gameObject; GrabbableObject grabbedObject = hitObject.GetComponent <GrabbableObject>(); ScannableObject scannable = hitObject.GetComponent <ScannableObject>(); if (scannable != _highlighted) { DisableScannedObject(); EnableScannedObject(scannable); } if (!grabbedObject) { DisableScannedObject(); } if (grabbedObject && !EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonDown(0)) { MetablastUI.Instance.HudView.ContextMessageView.SetLowPriorityText(""); GrabObject(grabbedObject, hitInfo.point); _state = ImpulseGunState.Grabbing; } } else { DisableScannedObject(); } }