public void OnGrabStart(IGrabbable grabbable, CameraInfo cameraInfo, Player player) { if (grabbable is Catapult catapult) { catapult.OnGrabStart(); } }
public void OnServerRelease(IGrabbable grabbable, CameraInfo cameraInfo, Player player) { if (this.Delegate == null) { throw new Exception("No Delegate"); } if (grabbable is Catapult catapult) { // Launch the ball var velocity = catapult.TryGetLaunchVelocity(cameraInfo); if (velocity != null) { catapult.OnLaunch(velocity); this.SlingBall(catapult, velocity); catapult.ReleaseSlingGrab(); this.ReleaseCatapultGrab(catapult.CatapultId); var slingData = new SlingData(catapult.CatapultId, catapult.ProjectileType, velocity); // succeed in launching catapult, notify all clients of the update this.Delegate.ServerDispatchActionToAll(new GameActionType { CatapultRelease = slingData, Type = GameActionType.GActionType.CatapultRelease }); } } }
private void Awake() { _initPos = transform.position; _initRot = transform.rotation; var ren = GetComponent <Renderer>(); var material = ren.material; _grabbable = GetComponent <IGrabbable>(); _grabbable.OnTouched += (grabber, grabbable) => { material.color = Color.red; }; _grabbable.OnUntouched += (grabber, grabbable) => { material.color = Color.white; }; _grabbable.OnBeganGrab += (grabbere, grabbable) => { material.color = Color.blue; }; _grabbable.OnEndedGrab += (grabbere, grabbable) => { material.color = Color.green; }; }
private void StartGrab() { isGrabbing = false; if (isHolding) { return; } foreach (Vector2 direction in Enum.GetValues(typeof(CardinalDirections)).Cast <CardinalDirections>().Select(c => c.AsVector2())) { Vector2 grabPosition = transform.position2D() + direction; Collider2D collide = Physics2D.OverlapPoint(grabPosition); if (collide == null) { continue; } IGrabbable grabbable = collide.GetComponent(typeof(IGrabbable)) as IGrabbable; if (grabbable != null && grabbable.CanGrab()) { stepState.GrabPosition = grabPosition; isGrabbing = true; Rock = ((GameObject)GameObject.Instantiate(RockPrefab, grabPosition, Quaternion.identity)).transform; grabbable.OnGrab(); break; } } }
public static IGrabbable GetCloserAvailableGrabbable(Vector3 position, IGrabbable self = null) { float closer = float.MaxValue; IGrabbable closerOne = null; foreach (var grabbable in Grabbables) { if (grabbable == self) { continue; } float dist = Vector2.Distance(grabbable.transform.position, position); if (dist < closer) { if (grabbable.IsAvailableToGrab()) { closerOne = grabbable; closer = dist; } } } return(closerOne); }
public void OnServerGrab(IGrabbable grabbable, CameraInfo cameraInfo, Player player) { if (grabbable is Catapult catapult) { catapult.ServerGrab(cameraInfo.Ray); } }
private bool CheckRotateRight() { if (null == _leftHandHitResult || PlayerBehavior.MoveDirection.x <= 0.0f) { return(false); } _didRotateRightRaycast = true; if (!Physics.Raycast(_rightHandTransform.position, Quaternion.AngleAxis(90.0f, transform.up) * transform.forward, out var hit, _data.ArmRayLength * 0.5f, _data.RaycastLayerMask, QueryTriggerInteraction.Ignore)) { return(false); } IGrabbable grabbable = hit.transform.GetComponent <IGrabbable>(); if (null == grabbable) { return(false); } if (hit.normal == _leftHandHitResult.Value.normal) { return(false); } _rightHandHitResult = hit; Vector3 offset = (Behavior.Owner.Radius * 2.0f) * transform.forward; Behavior.Owner.ManualAnimator.StartAnimation(Behavior.Owner.Movement.Position + GetSurfaceAttachmentPosition(hit, Behavior.Owner.Radius * hit.normal) - offset, Quaternion.LookRotation(-hit.normal), _data.WrapTimeSeconds); return(true); }
private void UpdateLeftHandRaycasts() { _didLeftHandRaycast = true; _leftHandHitResult = null; RaycastHit hit; if (Physics.Raycast(_leftHandTransform.position, transform.forward, out hit, Controller.ControllerData.ArmRayLength, Controller.ControllerData.CollisionCheckLayerMask, QueryTriggerInteraction.Ignore)) { IGrabbable grabbable = hit.transform.GetComponent <IGrabbable>(); if (null != grabbable) { _leftHandHitResult = hit; } } _didLeftHandHangRaycast = true; _leftHandHangHitResult = null; if (Physics.Raycast(_leftHandTransform.position, transform.up, out hit, Controller.ControllerData.HangRayLength, Controller.ControllerData.CollisionCheckLayerMask, QueryTriggerInteraction.Ignore)) { IGrabbable grabbable = hit.transform.GetComponent <IGrabbable>(); if (null != grabbable) { _leftHandHangHitResult = hit; } } }
private void UpdateRightHandRaycasts() { _didRightHandRaycast = true; _rightHandHitResult = null; if (Physics.Raycast(_rightHandTransform.position, transform.forward, out var hit, _data.ArmRayLength, _data.RaycastLayerMask, QueryTriggerInteraction.Ignore)) { IGrabbable grabbable = hit.transform.GetComponent <IGrabbable>(); if (null != grabbable) { _rightHandHitResult = hit; } } _didRightHandHangRaycast = true; _rightHandHangHitResult = null; if (Physics.Raycast(_rightHandTransform.position, transform.up, out hit, _data.HangRayLength, _data.RaycastLayerMask, QueryTriggerInteraction.Ignore)) { IGrabbable grabbable = hit.transform.GetComponent <IGrabbable>(); if (null != grabbable) { _rightHandHangHitResult = hit; } } }
private void AddGrabbable(IGrabbable grabbable) { if (!_targetGrabbables.Contains(grabbable)) { _targetGrabbables.Add(grabbable); } }
void IGrabReopsitory.Remove(IGrabbable grabbable) { if (_grabbables.Contains(grabbable)) { _grabbables.Remove(grabbable); } }
private void OnCollisionExit2D(Collision2D collision) { if (collision.gameObject.GetComponent <IGrabbable>() != null && !Input.GetKey(KeyCode.E)) // checks if the componenet is with that script and if the key is not being pressed { objectToGrab = null; // null it. } }
bool AttemptGrab(Transform handTransform, out GrabbableData grabbableDataBuffer) { _detectionRay = new Ray(_cameraTransform.position, _cameraTransform.forward); int numberOfHits = Physics.RaycastNonAlloc(_detectionRay, _rayHits, _rayMaxLength, _orbDetectionMask); if (numberOfHits > 0) { IGrabbable hitGrabbable = _rayHits[0].transform.GetComponent <IGrabbable>(); if (hitGrabbable == null) { Debug.LogError("AttemptGrab attempted to pick up something that had no IGrabbable component attached", _rayHits[0].transform); } bool pullIsSuccesful = hitGrabbable.RequestPull(handTransform); if (pullIsSuccesful) { grabbableDataBuffer = new GrabbableData(hitGrabbable, _rayHits[0].transform); return(true); } else { grabbableDataBuffer = null; return(false); } } else { grabbableDataBuffer = null; return(false); } }
void IGrabReopsitory.Add(IGrabbable grabbable) { if (!_grabbables.Contains(grabbable)) { _grabbables.Add(grabbable); } }
private void HandleGrab() { Transform cameraT = Camera.main.transform; Vector3 eyePos = this.transform.position + (Vector3.up * 1.65f); // Approx where the eyes would be // Approx length for ray float rayCastLength = ((cameraT.position - eyePos).magnitude * 1.25f) + interactionDistance; RaycastHit hit; if (Physics.Raycast(cameraT.position, cameraT.forward, out hit, rayCastLength)) { // Return if distance is larger if ((hit.point - eyePos).sqrMagnitude > Mathf.Pow(interactionDistance, 2)) { return; } grabTarget = hit.collider.GetComponentInParent <IGrabbable>(); } if (grabTarget != null) { grabbed = true; grabTarget.SetGrabbed(true); } }
private bool TryGrabGrabbable(IGrabbable grabbable) { var vectorToGrabbable = grabbable.Transform.position - transform.position; vectorToGrabbable.y = 0f; var groundAngleToHitObject = Vector3.Angle(vectorToGrabbable, transform.forward); if (!(groundAngleToHitObject <= _grabConeAngle)) { return(false); } if (grabbable is IPlaceable placeable && !placeable.IsPacked) { return(false); } if (grabbable is IDepositable depositable && depositable.IsDeposited) { if (!depositable.Container.TryWithdrawItem(depositable)) { return(false); } } GrabGrabbable(grabbable); return(true); }
public bool GrabObjectAtPosition(Vector3 position) { bool grabSuccessful = true; if (state == States.HoldingObject) { gameObject.GetComponent <ICanGrab>().FinishedAction(false); // TODO failure reason: already holding object return(false); } grabbedObject = GetGrabbableObjectAtPoint(position); if (grabbedObject == null) { // TODO failure reason, no object to grab grabSuccessful = false; } else { grabbedObject.PickedUp(this); state = States.HoldingObject; } gameObject.GetComponent <ICanGrab>().FinishedAction(grabSuccessful); return(grabSuccessful); }
private void InitializeGrabbableObjects() { _grabbable = Substitute.For <IGrabbable>(); _aGrabbableObject = new GameObject(); _aGrabbableObject.AddComponent <MonoGrabbable>().SetGrabbable(_grabbable); _aGrabbableObject.layer = GrabbableLayer; _anotherGrabbableObject.layer = GrabbableLayer; }
public void OnUpdateGrabStatus(IGrabbable grabbable, CameraInfo cameraInfo) { if (grabbable is Catapult catapult) { catapult.BallVisible = BallVisible.Visible; catapult.OnGrab(cameraInfo); } }
private void GrabGrabbable(IGrabbable grabbable) { _grabSlots.Add(grabbable); grabbable.OnGrab(_playerContext); grabbable.Transform.parent = transform; grabbable.Rigidbody.isKinematic = true; grabbable.GrabCoroutine = StartCoroutine(TweenUtil.EaseTransformToPoint(grabbable.Transform, _grabPivot, _grabEaseModifier, GRAB_PIVOT_SNAP_THRESHOLD)); }
private void Unhover() { if (_hoverGrabbable != null) { TryUntouch(_hoverGrabbable); _hoverGrabbable = null; } }
public GrabbableData(IGrabbable grabbable, Transform transform) { this.grabbable = grabbable; this.transform = transform; combinable = transform.GetComponent <ICombinable>(); canBeCombined = combinable == null ? false : true; shakable = transform.GetComponent <IShakable>(); }
public void Initialize(IGrabbable grabbable) { _grabbable = grabbable; if (!_constraints.ConstraintsAreRelative) { _activeScale = grabbable.Transform.localScale.x; } }
private void OnCollisionEnter2D(Collision2D collision) { IGrabbable grabbableObject = collision.gameObject.GetComponent <IGrabbable>(); // essentially will find any object that the player is collided with and will make it to a grabbable if we allow it to if (grabbableObject != null) { objectToGrab = grabbableObject; // Then hey presto its a grabby thingy and you can move with it. } }
private void Awake() { _grabbable = GetComponent <IGrabbable>(); if (TryGetComponent(out _rigidbody)) { _hasRigidbody = true; _initKinematic = _rigidbody.isKinematic; } }
public void OnRelease() { if (currentGrabItem != null) { currentGrabItem.Release(currentInput); currentGrabItem = null; CallAnimationTrigger?.Invoke("", null); PlayAudio?.Invoke("Release", 0f); } }
private void RemoveGrabbable(IGrabbable grabbable) { if (_targetGrabbables.Contains(grabbable)) { if (!_removeTarget.Contains(grabbable)) { _removeTarget.Add(grabbable); } } }
public void GrabGrabbable(IGrabbable grabbable) { if (CloserGrabbable == null || Carryer != null) { return; } grabbable.Grab(this); anim.SetBool("Holding", true); }
public void Ungrab(IGrabbable grabbable) { IsGrabbed = false; if (_grabbedGrabbables.Contains(grabbable)) { _grabbedGrabbables.Remove(grabbable); } OnUngrab(grabbable); }
public void Grab(IGrabbable grabbable) { IsGrabbed = true; if (!_grabbedGrabbables.Contains(grabbable)) { _grabbedGrabbables.Add(grabbable); } OnGrab(grabbable); }
public virtual void ChildLeaving(IGrabbable grabbable) { Debug.Log("Child leaving top level"); gameObject.SetActive(false); }
public virtual void ChildArrivedAtDestination(IGrabbable grabbable) { Debug.Log("Child leaving top level"); gameObject.SetActive(true); }
public void ChildLeaving(IGrabbable child) { }