OnGrabbed() public method

public OnGrabbed ( ) : void
return void
示例#1
0
    private void GrabObstacle()
    {
        m_Asset.spriteId = m_Asset.GetSpriteIdByName(m_HandGrabbedAssetName);

        if (m_IsGrabbing)
        {
            return;
        }

        m_IsGrabbing = true;

        if (m_HoveringObstacleHandle != null && !m_HoveringObstacleHandle.IsGrabbed && m_GrabbedObstacleJoin == null)
        {
            AudioManager.Instance.PlaySFX(m_SFXGrab);
            AudioManager.Instance.PlayLoopingSFX(m_SFXHoldGrab, 0.4f);

            // Find hit point.
            Vector3      handHitPosition = transform.position - (CameraController.Instance.m_HandCamera.transform.TransformDirection(Vector3.forward) * 2000.0f);
            RaycastHit[] hits            = Physics.SphereCastAll(handHitPosition, (collider as CapsuleCollider).radius, CameraController.Instance.m_HandCamera.transform.TransformDirection(Vector3.forward));

            Vector3 hitPoint = transform.position;
            bool    isHit    = false;
            if (hits.Length > 0)
            {
                foreach (RaycastHit hit in hits)
                {
                    Obstacle obstacle = hit.collider.gameObject.GetComponent <Obstacle>();
                    if (obstacle != null)
                    {
                        hitPoint = hit.point;
                        isHit    = true;
                        break;
                    }
                }
            }

            if (isHit)
            {
                m_GrabbedObstacleHandle = m_HoveringObstacleHandle;
                m_GrabbedObstacleHandle.OnGrabbed();

                GameObject joint = new GameObject("Join");
                joint.transform.position = hitPoint;
                joint.transform.parent   = transform;

                GameUtils.FindAssociatedLevel(transform).m_Malisse.RevertWalkableCollider(m_HoveringObstacleHandle.m_Obstacle.collider);

                m_GrabbedObstacleJoin = joint.AddComponent <HingeJoint>();
                m_GrabbedObstacleJoin.rigidbody.useGravity  = false;
                m_GrabbedObstacleJoin.rigidbody.constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
                m_GrabbedObstacleJoin.connectedBody         = m_HoveringObstacleHandle.m_Obstacle.rigidbody;

                // Move hand.
                m_GoalHeight = GRABBED_OFFSET;
                StopCoroutine("RaiseHand");
                StartCoroutine("RaiseHand");
            }
        }
        else
        {
            AudioManager.Instance.PlaySFX(m_SFXCantGrab);
        }
    }
示例#2
0
    private void GrabObstacle()
    {
        m_Asset.spriteId = m_Asset.GetSpriteIdByName(m_HandGrabbedAssetName);

        if (m_IsGrabbing)
        {
            return;
        }

        m_IsGrabbing = true;

        if (m_HoveringObstacleHandle != null && !m_HoveringObstacleHandle.IsGrabbed && m_GrabbedObstacleJoin == null)
        {
            AudioManager.Instance.PlaySFX(m_SFXGrab);
            AudioManager.Instance.PlayLoopingSFX(m_SFXHoldGrab, 0.4f);

            // Find hit point.
            Vector3 handHitPosition = transform.position - (CameraController.Instance.m_HandCamera.transform.TransformDirection(Vector3.forward) * 2000.0f);
            RaycastHit[] hits = Physics.SphereCastAll(handHitPosition, (collider as CapsuleCollider).radius, CameraController.Instance.m_HandCamera.transform.TransformDirection(Vector3.forward));

            Vector3 hitPoint = transform.position;
            bool isHit = false;
            if (hits.Length > 0)
            {
                foreach (RaycastHit hit in hits)
                {
                    Obstacle obstacle = hit.collider.gameObject.GetComponent<Obstacle>();
                    if (obstacle != null)
                    {
                        hitPoint = hit.point;
                        isHit = true;
                        break;
                    }
                }
            }

            if (isHit)
            {
                m_GrabbedObstacleHandle = m_HoveringObstacleHandle;
                m_GrabbedObstacleHandle.OnGrabbed();

                GameObject joint = new GameObject("Join");
                joint.transform.position = hitPoint;
                joint.transform.parent = transform;

                GameUtils.FindAssociatedLevel(transform).m_Malisse.RevertWalkableCollider(m_HoveringObstacleHandle.m_Obstacle.collider);

                m_GrabbedObstacleJoin = joint.AddComponent<HingeJoint>();
                m_GrabbedObstacleJoin.rigidbody.useGravity = false;
                m_GrabbedObstacleJoin.rigidbody.constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
                m_GrabbedObstacleJoin.connectedBody = m_HoveringObstacleHandle.m_Obstacle.rigidbody;

                // Move hand.
                m_GoalHeight = GRABBED_OFFSET;
                StopCoroutine("RaiseHand");
                StartCoroutine("RaiseHand");
            }
        }
        else
        {
            AudioManager.Instance.PlaySFX(m_SFXCantGrab);
        }
    }