示例#1
0
    void EndGrab(bool attached, bool hasBomb = false)
    {
        state = State.detached;

        if (hasBomb)
        {
            LaunchBomb();
        }
        else
        {
            rb.isKinematic = false;
            if (!attached)
            {
                // calculate departing velocity
                Vector3 diff  = lastPos - spawn.position;
                Vector3 force = Vector3.ClampMagnitude(diff * grabThrowForceMul, maxThrowForce);
                rb.AddForce(force);
            }
        }

        if (grabed != null)
        {
            grabed.DestoryAnchor();
            grabed = null;
        }

        grabAnimator.SetBool("IsGrabbing", false);
    }
示例#2
0
    private IEnumerator DisableCollider(Grabable grabable)
    {
        yield return(new WaitForSecondsRealtime(2f));

        grabable.GetComponent <BoxCollider>().enabled   = false;
        grabable.GetComponent <Rigidbody>().isKinematic = true;
    }
示例#3
0
	void OnTriggerStay(Collider col) {
		if (grabbing == null && Input.GetButtonDown ("X" + playerMov.getPlayerId().ToString())) {
			Grabable g = col.gameObject.GetComponentInChildren<Grabable> ();
			if (g != null && g.enabled) {
				grabbing = g;
				grabbedRB = grabbing.GetComponentInParent<Rigidbody> ();
                Extingish ext = grabbing.GetComponentInParent<Extingish>();
                if (ext != null) ext.setGrab(true, transform.parent);
                grabbedRB.useGravity = false;
				firstFrame = true;
				holder.rotation = col.transform.rotation;
				grabbedCol = col;
                //grabbedCol.transform.GetComponentInParent<Rigidbody>().detectCollisions = false;
                setColliders(grabbedCol.transform.root, false);
                

                //Physics.IgnoreCollision (grabbedCol, transform.parent.GetComponent<Collider> (), true);
            }
            else {
				LuckTrigger lt = col.gameObject.GetComponentInParent<LuckTrigger> ();
				if (lt != null && lt.activated) {
					lt.resetCallback.Invoke ();
				}
			}
		}
	}
示例#4
0
 private void PickupCallback(bool success)
 {
     if (success)
     {
         if (grabbing != null)
         {
             grabbing.SetPickupState(context.gameObject, disable_collision: !IsServer);
         }
         // Wait until the grab button is released to finish the pick up
         utils.WaitUntilCondition(
             check: () => {
             return(!input_manager.GetUseHold());
         },
             action: () => {
             if (grabbed != null)
             {
                 return;
             }
             grabbed  = grabbing;
             grabbing = null;
         });
     }
     else
     {
         grabbing = null;
     }
     if (grab_timeout_coroutine != null)
     {
         utils.StopCoroutine(grab_timeout_coroutine);
         grab_timeout_coroutine = null;
     }
 }
示例#5
0
    public override bool OnUse(PhysicsProp prop)
    {
        if (!IsOwner)
        {
            return(false);
        }
        Grabable grabable = prop as Grabable;

        if (grabbed == null && grabbing == null)
        {
            Collider grabable_collider = grabable.GetComponent <Collider>();
            float    grabable_height   = grabable_collider.bounds.size.y;
            grabbing = grabable;
            if (IsServer)
            {
                bool success = grabable.Pickup(
                    grabber: context.gameObject,
                    grab_offset: Vector3.up * (0.2f + (player.cc.height / 2f) + (grabable_height / 2f)));
                PickupCallback(success);
            }
            else
            {
                grabable.PickupOnServer(
                    grabber_netId: networkId,
                    grabber_moId: moving_player.GetMovingObjectIndex(),
                    grab_offset: Vector3.up * (0.2f + (player.cc.height / 2f) + (grabable_height / 2f)));
                grab_timeout_coroutine = utils.WaitAndRun(
                    seconds: grab_timeout,
                    action: () => {
                    grabbing = null;
                });
            }
        }
        return(false);
    }
示例#6
0
    private void OnTriggerEnter(Collider other)
    {
        /* this is WRONG!
         * becasuse 1) when it is grabbed, it will continuously vibrate
         * it will not vibrate when touching other objects as intended
         * if (Grab.Instance.UseVibration)
         *  Vibration.Vibrate(100);
         */

        // First, check if it's fingers
        if (other.transform.parent != null && other.transform.parent.parent != null &&
            other.transform.parent.parent.name.StartsWith("Hand_"))
        {
            return;
        }

        // Then make sure not to interact with its parent
        if (other.transform == transform.parent)
        {
            return;
        }

        // Now deal with other objects
        if (Grab.Instance.UseVibration)
        {
            Grabable g = Grab.Instance.GetGrabbingObject();
            if (g != null && g.transform == transform)
            {
                Debug.Log("Vib!!!!!!=================" + other.gameObject.name);
                Vibration.Vibrate(100);
            }
        }
    }
示例#7
0
    private void Update()
    {
        justGrabbed = false;
        invertSymbol.SetActive(false);
        grabTip.SetActive(false);
        releaseTip.SetActive(false);

        RaycastHit hitInfo;

        if (Physics.Raycast(new Ray(transform.position, transform.forward), out hitInfo, 10000, layer))
        {
            invertable = hitInfo.transform.gameObject.GetComponent <Invertable>();
            grabable   = hitInfo.transform.gameObject.GetComponent <Grabable>();
            if (invertable != null)
            {
                if (!playerInput.CoursorFree)
                {
                    invertSymbol.SetActive(true);
                }
                if (Input.GetKeyDown(KeyCode.Mouse0) && !playerInput.CoursorFree)
                {
                    InvertorSlot slot = InvertionManager.Instance.GetFreeInvertorSlot();
                    if (slot != null)
                    {
                        Invertor invertor = new Invertor();
                        slot.TakeSlot(invertor, invertor.Apply(invertable));
                    }
                }
            }

            if (grabable != null && currentGrabable == null)
            {
                grabTip.SetActive(true);
                if (Input.GetKeyDown(KeyCode.F) && !playerInput.CoursorFree)
                {
                    grabable.Grab(grabTransform, 2);
                    currentGrabable = grabable;
                    justGrabbed     = true;
                }
            }
        }

        if (currentGrabable != null)
        {
            releaseTip.SetActive(true);
        }


        if (!justGrabbed && Input.GetKeyDown(KeyCode.F) && currentGrabable != null)
        {
            currentGrabable.Release();
            currentGrabable = null;
        }

        if (currentGrabable != null && currentGrabable.Target != grabTransform)
        {
            currentGrabable = null;
        }
    }
示例#8
0
 private void ThrowCallback(bool success)
 {
     if (grabbed != null)
     {
         grabbed.SetThrownState();
     }
     grabbed = null;
 }
示例#9
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.tag == "Numbers")
     {
         Grabable numberCube = other.GetComponent <Grabable>();
         GameManager.Instance.OnCubeDropped(numberCube.number, numberOnBox);
     }
 }
示例#10
0
 private void OnDeath()
 {
     if (grabableObject != null)
     {
         grabableObject.Drop();
         grabableObject = null;
     }
 }
示例#11
0
    public void OnTriggerExit2D(Collider2D collision)
    {
        Grabable grabable = collision.gameObject.GetComponent <Grabable>();

        if (grabable != null && grabable == this.grabableInRange)
        {
            grabableInRange = null;
        }
    }
示例#12
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        Grabable grabable = collision.gameObject.GetComponent <Grabable>();

        if (grabable != null && grabable.transform.parent == null)
        {
            grabableInRange = grabable;
        }
    }
 public void PickUp(Grabable grabable)
 {
     _carryingObject = grabable;
     //F**k off gravity
     grabable.GetComponent <Rigidbody>().isKinematic = true;
     grabable.GetComponent <BoxCollider>().enabled   = false;
     grabable.gameObject.transform.SetParent(_grabableHook, false);
     grabable.gameObject.transform.position = _grabableHook.position;
     EventManager.Instance.GrabableSpawned(_carryingObject);
 }
示例#14
0
 void Grab(Grabable grabbed)
 {
     if (this.grabbed == null && grabbed.transform.parent == null)
     {
         this.grabbed               = grabbed;
         constructor.Mass          += grabbed.Mass;
         grabbed.transform.parent   = grabTransform;
         grabbed.transform.position = grabTransform.position;
         grabbed.Grab();
     }
 }
示例#15
0
	// Building Events. Some useful information can be gleaned from the building object.

	// A building is snapped when a user is selecting a building and hovers over an empty zone slot.
	// The building is now trying to get to that slot. 
	void buildingSnapEvent(GameObject building)
	{
		Vector3 position = building.transform.position;
		Quaternion rotation = building.transform.rotation;

		Grabable buildingScript = building.GetComponent<Grabable>();
		// GameObject manipulator = buildingScript.getManipulator();
		// GameObject zone = buildingScript.getZone();
		// Vector3? snappedPosition = buildingScript.getSnappedPosition();
		Debug.Log("Building " + building.name + " Snapped.");
	}
示例#16
0
    public void OnTriggerEnter(Collider other)
    {
        if (grabableObject == null)
        {
            Grabable grabable = other.gameObject.GetComponent <Grabable>();

            if (grabable != null)
            {
                grabableObject = grabable;
                grabable.Grab(gameObject);
            }
        }
    }
示例#17
0
 /// <summary>
 /// </summary>
 /// <returns>
 /// </returns>
 /// <remarks>
 /// </remarks>
 private void RocketEnergyCellSteal(Grabable energyCell)
 {
     Debug.Log("Energy cell was stolen!");
     currentEnergyCell = energyCell;
     tool.DropEvent   -= ToolDrop;
     rocketOne.EnergyCellStolenEvent -= RocketEnergyCellSteal;
     rocketTwo.EnergyCellStolenEvent -= RocketEnergyCellSteal;
     rocketOne.EnergyCellPlacedEvent += EnergyCellPlaced;
     rocketTwo.EnergyCellPlacedEvent += EnergyCellPlaced;
     currentEnergyCell.DropEvent     += EnergyCellDrop;
     tool.gameObject.SetActive(false);
     RpcSetToolActive(false);
 }
示例#18
0
    private void Update()
    {
        HandleMovement();

        m_PointedItem?.Highlight(false);
        m_PointedItem = null;

        Ray        ray = new Ray(m_CameraTransform.position, m_CameraTransform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, m_GrabDistance, m_GrabableMask))
        {
            m_PointedItem = hit.collider.GetComponentInParent <Grabable>();
            if (m_PointedItem)
            {
                m_PointedItem.Highlight(true);
            }
        }

        if (Input.GetMouseButtonDown(0) && m_GrabbedItem)
        {
            var gun = m_GrabbedItem.GetComponent <Gun>();
            if (gun)
            {
                gun.Fire();
            }
        }

        if (Input.GetMouseButtonDown(0) && m_PointedItem)
        {
            m_GrabbedItem = m_PointedItem;
            m_GrabbedItem.Highlight(false);
            m_GrabbedItem.Grab(m_GrabHook);
        }

        if (Input.GetMouseButtonDown(1) && m_GrabbedItem)
        {
            m_GrabbedItem.Release();
            m_GrabbedItem = null;
        }

        if (Input.GetKeyDown(KeyCode.E) && hit.collider)
        {
            //Debug.Log(hit.collider.gameObject.name);
            var button = hit.collider.GetComponentInParent <BigButton>();
            if (button)
            {
                button.Push();
            }
        }
    }
示例#19
0
    void FinishRetract()
    {
        grabber.parent = transform.GetChild(0);
        UpdateGrappler(0f);
        lr.enabled = false;

        state = State.detached;

        if (grabed != null)
        {
            grabed.DestoryAnchor();
            grabed = null;
        }
    }
示例#20
0
 private void SetOpen(bool check, Grabable grabable = null)
 {
     if (!reversMode)
     {
         if (check)
         {
             lockObject.SetActive(false);
             lockGlow.material       = greenMat;
             lineRenderer.startColor = Color.green;
             lineRenderer.endColor   = Color.green;
             text.text = "";
             if (grabable != null)
             {
                 grabable.Grab(transform, 0);
             }
         }
         else
         {
             lockObject.SetActive(true);
             lockGlow.material       = redMat;
             lineRenderer.startColor = Color.red;
             lineRenderer.endColor   = Color.red;
             text.text = textRequirement;
         }
     }
     else
     {
         if (check)
         {
             lockGlow.material       = greenMat;
             lineRenderer.startColor = Color.green;
             lineRenderer.endColor   = Color.green;
             text.text = "";
         }
         else
         {
             lockGlow.material       = redMat;
             lineRenderer.startColor = Color.red;
             lineRenderer.endColor   = Color.red;
             if (openWhenHaveObject)
             {
                 text.text = "OBJECT\nMISSING";
             }
             else
             {
                 text.text = "REMOVE\nOBJECT";
             }
         }
     }
 }
示例#21
0
    void FinishRetract()
    {
        grabber.parent = transform.GetChild(0);
        UpdateGrappler(0f);
        lr.enabled = false;

        state = State.detached;

        if (grabed != null)
        {
            grabed.DestoryAnchor();
            grabed = null;
        }

        hand.SetHaptic(HandController.HapticType.retractDone);
    }
示例#22
0
	public void Throw() {
		if (grabbing != null) {
			grabbedRB.velocity = transform.parent.forward * THROW_FORCE;
			grabbedRB.useGravity = true;
			grabbedRB.isKinematic = false;
            Extingish ext = grabbing.GetComponentInParent<Extingish>();
            if (ext != null) ext.setGrab(false, null);

            //grabbedCol.transform.GetComponentInParent<Rigidbody>().detectCollisions = true;
            setColliders(grabbedCol.transform.root, true);

            //Physics.IgnoreCollision (grabbedCol, transform.parent.GetComponent<Collider> (), false);

            grabbing = null;
		}
	}
示例#23
0
    public void OnTriggerEnter(Collider other)
    {
        ScavangerManager scavanger = other.GetComponent <ScavangerManager>();

        if (scavanger != null && scavanger != owner)
        {
            Grabber grabber = scavanger.GetComponent <Grabber>();

            if (grabber.GetGrabbedObject() == tools)
            {
                if (numberOfEnergyCells > 0)
                {
                    Grabable energyCell = Instantiate(energyCellPrefab).GetComponent <Grabable>();
                    NetworkServer.Spawn(energyCell.gameObject);

                    if (EnergyCellStolenEvent != null)
                    {
                        EnergyCellStolenEvent(energyCell);
                    }

                    grabber.Swap(energyCell);
                    numberOfEnergyCells--;
                }
                else
                {
                    grabber.Swap(null);
                }
            }
        }
        else if (scavanger != null)
        {
            Grabber  grabber = scavanger.GetComponent <Grabber>();
            Grabable grabbed = grabber.GetGrabbedObject();
            if (grabbed != null && grabbed.tag == "EnergyCell")
            {
                numberOfEnergyCells++;

                if (EnergyCellPlacedEvent != null)
                {
                    EnergyCellPlacedEvent();
                }

                grabber.Swap(null);
                Destroy(grabbed.gameObject);
            }
        }
    }
示例#24
0
    // Find all Grabable objects and Intersect them
    // Uses "Grabable" tag for selection purposes. This is probably
    // a good place to start profiling for performance improvements.
    void TestAllGrabablesForIntersection()
    {
        GameObject[] grabableObjects   = GameObject.FindGameObjectsWithTag("Grabable");
        Vector3?     intersectionPoint = null;

        Grabable closestGrabable     = null;
        float    closestGrabDistance = float.MaxValue;

        foreach (GameObject grabableObject in grabableObjects)
        {
            Grabable grabable = grabableObject.GetComponent <Grabable>();
            if (grabable == null)
            {
                Debug.Log("Object with tag 'grabable' " + grabableObject.name + " does not have a Grabable component");
                continue;
            }
            intersectionPoint = IntersectsPath(grabableObject.GetComponent <Collider>());
            if (intersectionPoint != null && DistanceToPoint(intersectionPoint.Value) < closestGrabDistance)
            {
                closestGrabDistance = DistanceToPoint(intersectionPoint.Value);
                closestGrabable     = grabable;
            }
        }

        // Short circuit if nothing is changing.
        if (currentPointee == closestGrabable)
        {
            return;
        }

        // If we're no longer pointing to our currentPointee, stop highlighting.
        if (currentPointee != null)
        {
            currentPointee.Unhighlight(this);
            currentPointee = null;
        }

        // If we found anything, highlight it.
        if (closestGrabable != null)
        {
            closestGrabable.Highlight(this);
            currentPointee       = closestGrabable;
            currentPointeeHandle = intersectionPoint.Value;
        }
    }
示例#25
0
    void Drop()
    {
        if (grabbed != null)
        {
            grabbed.transform.parent = null;
            constructor.Mass        -= grabbed.Mass;
            grabbed.Drop();
            Rigidbody2D rigidBody = grabbed.GetComponent <Rigidbody2D>();

            if (rigidBody != null)
            {
                int multiplier = inputMananger.IsRight ? 1 : -1;
                rigidBody.AddForce(new Vector2(multiplier * 1, 2) * throwForce);
            }

            grabbed = null;
        }
    }
示例#26
0
    public Grabable Swap(Grabable grabable)
    {
        Grabable grab = grabableObject;

        grabableObject = grabable;

        if (grabable != null)
        {
            grabable.Grab(gameObject);
        }

        if (grab != null)
        {
            grab.Drop();
        }

        return(grab);
    }
示例#27
0
    private void CheckIfInZone(Grabable grabable)
    {
        if (_alreadyDeleviredGrabables.Contains(grabable) || grabable.Type != InteractableEnum.Koala)
        {
            return;
        }

        if (!gameObject.GetComponent <BoxCollider>().bounds.Contains(grabable.transform.position))
        {
            return;
        }

        _alreadyDeleviredGrabables.Add(grabable);
        grabable.CanBeGrabbedByPlayer = false;
        StartCoroutine(DisableCollider(grabable));
        EventManager.Instance.ProblemSolved(grabable);
        LevelManager.Instance.ProblemSolved(Problem.Animal);
    }
示例#28
0
    private void CheckColliders(Collider[] colliders)
    {
        Invertable invertable;
        Grabable   grabable = null;
        bool       check    = false;

        foreach (var collider in colliders)
        {
            invertable = collider.gameObject.GetComponent <Invertable>();
            grabable   = collider.gameObject.GetComponent <Grabable>();
            if (invertable != null && CheckTags(invertable.GetTags()))
            {
                check = true;
                break;
            }
        }

        SetOpen(check, grabable);
    }
示例#29
0
    void pickup()
    {
        if (Input.GetKeyDown(KeyCode.E))
        {
            int x = Screen.width / 2;
            int y = Screen.height / 2;

            Ray        ray = mainCamera.GetComponent <Camera>().ScreenPointToRay(new Vector3(x, y));
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                Grabable p = hit.collider.GetComponent <Grabable>();
                if (p != null)
                {
                    carrying      = true;
                    carriedObject = p.gameObject;
                    p.GetComponent <Rigidbody>().isKinematic = true;
                }
            }
        }
    }
    public Grabable Drop()
    {
        //Make sure gravity applies to this object
        _carryingObject.GetComponent <Rigidbody>().isKinematic = false;
        _carryingObject.GetComponent <BoxCollider>().enabled   = true;
        //unparent object
        _carryingObject.transform.SetParent(null);
        var oldObject = _carryingObject;

        if (_carryingObject.UsableAction is KoalaAction k)
        {
            k.Sit();
        }
        if (_carryingObject.Type == InteractableEnum.EmptyWaterBucket || _carryingObject.Type == InteractableEnum.FullWaterBucket ||
            _carryingObject.Type == InteractableEnum.Sapling)
        {
            _carryingObject.gameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
        }
        EventManager.Instance.GrabableSpawned(oldObject);
        _carryingObject = _hands;
        return(oldObject);
    }
示例#31
0
    public void RemoveElement(Grabable grabable)
    {
        NavigationElement delete = null;

        foreach (var element in _elements)
        {
            if (element.ParentIsNull || !element.Type)
            {
                continue;
            }
            if (element.Type.Equals(grabable))
            {
                delete = element;
            }
        }

        if (delete)
        {
            _elements.Remove(delete);
            delete.gameObject.SetActive(false);
        }
    }
示例#32
0
 /* make sure you follow the format,
  *  Transform hand,
  *  Grabbable gobj */
 private void Release(Transform hand, Grabable gobj)
 {
     t2.text = "Triggered:" + hand.name + "," + gobj.name;
 }