예제 #1
0
        public PickHandlerTool(PickHandler.DofTypes constrainedDofTypes, Predicate <Event> removePredicate)
        {
            if (removePredicate == null)
            {
                throw new ArgumentNullException("removePredicate", "When to remove callback is null - undefined.");
            }

            ConstrainedDofTypes = constrainedDofTypes;
            m_removePredicate   = removePredicate;
        }
예제 #2
0
        private GameObject TryCreateConstraint(Ray ray, GameObject gameObject, PickHandler.DofTypes constrainedDofs, string gameObjectName)
        {
            if (gameObject == null || gameObject.GetComponentInParent <RigidBody>() == null)
            {
                return(null);
            }

            var result = Utils.Raycast.Intersect(ray, gameObject, true);

            if (!result)
            {
                return(null);
            }

            ConstraintType constraintType = constrainedDofs == PickHandler.DofTypes.Translation ?
                                            ConstraintType.BallJoint :
                                            constrainedDofs == PickHandler.DofTypes.Rotation ?
                                            ConstraintType.AngularLockJoint :
                                            (constrainedDofs & PickHandler.DofTypes.Translation) != 0 && (constrainedDofs & PickHandler.DofTypes.Rotation) != 0 ?
                                            ConstraintType.LockJoint :
                                            ConstraintType.BallJoint;

            GameObject constraintGameObject = Factory.Create(constraintType);

            constraintGameObject.name = gameObjectName;

            Constraint constraint = constraintGameObject.GetComponent <Constraint>();

            constraint.ConnectedFrameNativeSyncEnabled        = true;
            constraint.AttachmentPair.ReferenceObject         = result.Target;
            constraint.AttachmentPair.ReferenceFrame.Position = result.Point;

            constraint.AttachmentPair.ConnectedObject         = null;
            constraint.AttachmentPair.ConnectedFrame.Position = result.Point;

            constraint.AttachmentPair.Synchronized = false;

            return(constraintGameObject);
        }