Example #1
0
 public void Regrab(Selector selector)
 {
     SetCursor(selector);
     // Lossy scale is correct if object is not skewed by a rotation up the tree.
     obj_world.Set(transform.position, transform.rotation, transform.lossyScale);
     obj_child.Set(obj_world);
     obj_child.TransformUp(cursor);
 }
Example #2
0
        public override void DoGrab(Selector selector, bool state)
        {
            base.DoGrab(selector, state);

            if (state)
            {
                if (grabbing_selector == null)
                {
                    Rigidbody body = GetComponent <Rigidbody>();
                    if (body != null)
                    {
//#if USE_VELOCITY
                        save_useGravity = body.useGravity;
                        body.useGravity = false;
//#else
//                        save_drag = body.drag;
//                        save_angdrag = body.angularDrag;

//                        save_useGravity = body.useGravity;
//                        body.useGravity = true;
//#endif
                        save_isKinematic = body.isKinematic;
                        body.isKinematic = false;
                    }

                    //#if USE_VELOCITY
                    RotationMover mover = gameObject.GetComponent <RotationMover>();
                    if (mover)
                    {
                        Destroy(mover);
                    }
                    //#endif

                    Regrab(selector);

                    grab_loc.Set(cursor);
                    grab_loc.TransformUp(obj_world);

                    grabbing_selector = selector;

                    //grab_evt.Invoke();
                }
            }
            else
            {
                if (grabbing_selector == selector)
                {
                    Rigidbody body = GetComponent <Rigidbody>();
                    if (body != null)
                    {
                        body.useGravity = save_useGravity;

                        body.velocity        = (save_isKinematic) ? Vector3.zero : selector.GetVelocity();
                        body.angularVelocity = (save_isKinematic || dolly_mode) ? Vector3.zero : selector.GetAngularVelocity();
                        //body.angularVelocity = Vector3.zero;

//#if USE_VELOCITY
                        if (dolly_mode && gameObject.GetComponent <RotationMover>() == null)
                        {
                            RotationMover mover = gameObject.AddComponent <RotationMover>();
                            mover.Set(yaw_mode, save_isKinematic);
                        }
                        else
                        {
                            body.isKinematic = save_isKinematic;
                        }
//#else
//                        body.isKinematic = save_isKinematic;
//                        body.drag = save_drag;
//                        body.angularDrag = save_angdrag;
//#endif
                    }

                    grabbing_selector = null;
                    //release_evt.Invoke();
                }
            }
        }