BasicAction GetSecondaryAction(InteractableRaw thisInteractable, InteractorRaw interactor)
        {
            BasicAction action = null;

            switch (secondary)
            {
            case SecondGrab.None:
                action = new NothingAction(thisInteractable, interactor);
                break;

            case SecondGrab.Switch:
                action = new SwitchAction(thisInteractable, interactor);
                break;

            case SecondGrab.Scale:
                break;

            case SecondGrab.LookAt:
                var updateType = followType == FollowType.Transform ? UpdateEvents.BeforeRender : UpdateEvents.FixedUpdate;
                action = new LookAtAction(thisInteractable, interactor, ((FollowAction)grab.grabbedObjects[0].action).offset, true, updateType);
                break;
            }

            return(action);
        }
        public Transform CreateOffset(InteractorRaw interactor)
        {
            var grabPoint = new GameObject($"GrabPoint [{attach.ToString()}]").transform;

            grabPoint.parent = transform;

            switch (attach)
            {
            case AttachType.Origin:
                grabPoint.localPosition = Vector3.zero;
                grabPoint.localRotation = Quaternion.identity;
                break;

            case AttachType.ConstantOffset:
                grabPoint.localPosition = constPosOffset;
                grabPoint.localRotation = constRotOffset;
                break;

            case AttachType.GrabOffset:
                grabPoint.position = interactor.transform.position;
                grabPoint.rotation = interactor.transform.rotation;
                break;
            }

            return(grabPoint);
        }
            public void NotifyGrab(InteractorRaw interactor)
            {
                if (!interactor)
                {
                    return;
                }

                if (grabbedObjects.Count == 0)
                {
                }
                BasicAction grabTypeAction = null;

                //Utils.CleanInteractions.CleanInteracableTouching(interactor, ref parent.touch.touchedObjects);
                if (grabbedObjects.Count < 1)
                {
                    grabTypeAction = parent.PrimaryActionEvent(parent, interactor);
                }
                else                //bool canGrab
                if (grabbedObjects.Count == 1)
                {
                    grabTypeAction = parent.SecondaryActionEvent(parent, interactor);
                }

                if (grabTypeAction != null)
                {
                    grabbedObjects.Add(new GrabData(interactor, parent, grabTypeAction));

                    parent.Grabbed?.Invoke(interactor);

                    GrabProccess();
                }
            }
 public GrabData(InteractorRaw _hand, InteractableRaw _interactable, BasicAction _action)
 {
     interactor         = _hand;
     interactable       = _interactable;
     action             = _action;
     kinematicOnRelease = interactable.mainRigidbody.isKinematic;
     gravityOnRelease   = interactable.mainRigidbody.useGravity;
 }
            int GetUngrabindex(InteractorRaw interactor = null)
            {
                int index = -1;

                if (interactor != null)
                {
                    for (int i = 0; i < grabbedObjects.Count; i++)
                    {
                        if (interactor == grabbedObjects[i].interactor)
                        {
                            index = i;
                            break;
                        }
                    }
                }
                else
                {
                    index = grabbedObjects.Count - 1;
                }

                return(index);
            }
            public void NotifyUnGrab(InteractorRaw interactor = null)
            {
                if (grabbedObjects.Count == 0)
                {
                    return;
                }

                int removeIndex = GetUngrabindex(interactor);

                if (removeIndex == -1)
                {
                    return;
                }


                if (grabbedObjects.Count == 1)                 //if last hand is leaving
                {
                    UnGrabProcess();
                }

                grabbedObjects[removeIndex].Destroy();


                grabbedObjects.RemoveAt(removeIndex);

                if (grabbedObjects.Count >= 1)
                {
                    CascadeActions();
                }

                parent.UnGrabbed?.Invoke(interactor);


                if (handsGrabbing < 0)
                {
                    Debug.LogError("Too many ungrabs " + interactor, parent);
                }
            }
Exemple #7
0
        public virtual BasicAction GetDrivePrimaryAction(InteractableRaw thisInteractable, InteractorRaw interactor)
        {
            //return base.GetPrimaryAction(interactor);
            Transform offset = thisInteractable.CreateOffset(interactor);

            //if (driveType == DriveTypes.Directional)
            //	switch (thisInteractable.followType)
            //	{
            //		case FollowType.Transform:
            //			return new DirectionalTransformDriveAction(this, thisInteractable, interactor, offset);
            //		case FollowType.Rigidbody:
            //			return new DirectionalRigidbodyDriveAction(this, thisInteractable, interactor, offset);
            //		case FollowType.Joint:
            //			return new DirectionalDriveJointAction(this, thisInteractable.mainRigidbody, interactor, offset);
            //	}
            //else if (driveType == DriveTypes.Rotational)
            //	switch (thisInteractable.followType)
            //	{
            //		case FollowType.Transform:
            //			return new RotationalTransformDriveAction(this, thisInteractable, interactor, offset);
            //		case FollowType.Rigidbody:
            //			break;
            //		case FollowType.Joint:
            //			break;
            //	}

            return(null);
        }
        public virtual BasicAction GetPrimaryAction(InteractableRaw thisInteractable, InteractorRaw interactor)
        {
            Transform offset = thisInteractable.CreateOffset(interactor);

            switch (thisInteractable.followType)
            {
            case FollowType.Transform:
                if (!thisInteractable.preciseRotate)
                {
                    return(new GrabFollowTransformAction(thisInteractable, interactor, offset));
                }
                else
                {
                    return(new GrabFollowTransformPosDifRotAction(thisInteractable, interactor, offset));
                }

            case FollowType.Rigidbody:
                if (!thisInteractable.preciseRotate)
                {
                    return(new GrabFollowVelocityAction(thisInteractable, interactor, offset));
                }
                else
                {
                    return(new GrabFollowRigidbodyForceAtPointAction(thisInteractable, interactor, offset));
                }

            case FollowType.Joint:
                return(new GrabFollowJointAction(thisInteractable, interactor, offset));
            }
            return(null);
        }
 public void UnGrab(InteractorRaw interactor)
 => interactor.UnGrab(this);
 public void Grab(InteractorRaw interactor)
 => interactor.Grab(this);