Ejemplo n.º 1
0
    public void HandleTriggerDown(object sender, ClickedEventArgs e)
    {
        if (touchedObj == null || !inUse)
        {
            return;                             // not possible but just double check
        }
        // if not in stretch mode
        if (!inStretchMode)
        {
            // enter stretch mode!
            inStretchMode = true;
            stretchObj    = touchedObj;
            originalScale = stretchObj.transform.localScale;

            // if thing is currently been grabbed
            if (m_CurrentInteractible.IsGrabbing)
            {
                if (toScaleUp == 1)
                {
                    initialControllersDistance = (pointyPoint.position - m_CurrentInteractible.GrabbedPos).sqrMagnitude;
                }
                else
                {
                    initialControllersDistance = (pointyPointShrink.position - m_CurrentInteractible.GrabbedPos).sqrMagnitude;
                }

                // remote the joint attached to other controller
                if (m_CurrentInteractible.Joint)
                {
                    stretchObj.GetComponent <Rigidbody> ().isKinematic = true;
                    m_CurrentInteractible.RemoveJoint();
                }
            }
        }
        DeviceVibrate();
    }
Ejemplo n.º 2
0
    public void HandleTriggerDown(object sender, ClickedEventArgs e)
    //public void HandleTriggerDown(GameObject sender)
    {
//		if(m_inSelfScalingMode && otherController.InSelfScalingSupportMode)
//		{
//			originalScale = player.localScale;
//			initialControllersDistance = (attachPoint.position - otherController.attachPoint.position).sqrMagnitude;
//			return;
//		}

        if (!inUse)
        {
            return;
        }
        else
        {
            hand.OnDown();
        }

        if (touchedObj == null)
        {
            return;                             // not possible but just double check
        }
        // if haven't grab anything && not in stretch mode
        if (!grabSomething && !inStretchMode)
        {
            // if already been grabbed
            if (m_CurrentInteractible.IsGrabbing)
            {
                // enter stretch mode!
                inStretchMode = true;
                stretchObj    = touchedObj;
                originalScale = stretchObj.transform.localScale;

                initialControllersDistance = (attachPoint.position - m_CurrentInteractible.GrabbedPos).sqrMagnitude;
                //Debug.Log (gameObject.name + "starts stretching!");
                DeviceVibrate();

                // remote the joint attached to other controller
                if (m_CurrentInteractible.Joint)
                {
                    stretchObj.GetComponent <Rigidbody> ().isKinematic = true;
                    m_CurrentInteractible.RemoveJoint();
                }
            }
            else
            {
                // be grabbed!
                m_CurrentInteractible.Down(gameObject);
                m_CurrentInteractible.grabbedPoint = attachPoint.position;

                // Grab in PHYSICS way if has rigidbody
                if (m_CurrentInteractible.TheRigidbody)                  //if (m_CurrentInteractible.HasRigidbody)
                {
                    Debug.Log("to grab r_body");
                    // set the kinematic false (if it is) so can be controlled by joint
                    if (m_CurrentInteractible.IsKinematic)
                    {
                        Debug.Log("to grab IsKinematic");
                        m_CurrentInteractible.IsKinematic = false;
                    }
                    Debug.Log("add joint");
                    // add fixed joint
                    m_CurrentInteractible.AddJoint(attachPoint);
                }
                else                 // or NON-PHYSICS(hierarchy way)
                {
                    stickerParent = touchedObj.transform.parent;
                    touchedObj.transform.parent = gameObject.transform;
                }

                grabSomething = true;
                DeviceVibrate();
            }
        }
    }