public void EndInteraction(WandControlForItems wand) { if (wand == attachedWand) { if (isSnapped) { attachedWand = null; currentlyInteracting = false; Transform parentOfSnappedObj = this.transform.parent; if (parentOfSnappedObj != null) { parentOfSnappedObj.transform.SetParent(null); } // Debug.Log("end split here..check1"); } else { //not snapped objects attachedWand = null; currentlyInteracting = false; this.transform.SetParent(null); // Debug.Log("end split here..check2"); } } }
void Start() { //the model name is selected from MainMenu EnableTheSelectedModel(); if (leftWand == null || rightWand == null) { Debug.LogError("Please assign from inspector, Controller (left) and Controller (right) to the leftWand and rightWand respectively"); } if ((leftWand != null && leftWand.activeSelf) && (rightWand != null && rightWand.activeSelf)) { wandController_Left = leftWand.GetComponent <WandControlForItems> (); wandController_Right = rightWand.GetComponent <WandControlForItems> (); } //Call all methods to setup selected model SaveAllModelData(); // 1 AddComponentsToAllModelObjects(); // 2 }
public void BeginInteraction(WandControlForItems wand) { if (isSnapped) { attachedWand = wand; Transform parentOfSnappedObj = this.transform.parent; if (parentOfSnappedObj != null) { parentOfSnappedObj.transform.SetParent(wand.transform, true); } currentlyInteracting = true; // Debug.Log("after split here..check1"); } else //not snapped objects { attachedWand = wand; this.transform.SetParent(wand.transform, true); currentlyInteracting = true; // Debug.Log("after split here..check2"); } }
void Update() { #region INITIALIZATION if ((leftWand != null && leftWand.activeSelf) && (rightWand != null && rightWand.activeSelf)) { if (wandController_Left == null) { wandController_Left = leftWand.GetComponent <WandControlForItems> (); } if (wandController_Right == null) { wandController_Right = rightWand.GetComponent <WandControlForItems> (); } } #endregion #region ACTIVE_WANDS_CONTROLLER if ((leftWand != null && leftWand.activeSelf) && (rightWand != null && rightWand.activeSelf)) { #region SCALING //When grip buttons are pressed together on controllers, scale up or down model if (wandController_Left.gripButtonPressed == true && wandController_Right.gripButtonPressed == true) { if (mainModelController != null) { //group model here _isScaling = true; mainModelController.GroupModel(); wandController_Left.ChangePointersStatus(false); wandController_Right.ChangePointersStatus(false); mainModelController.ScaleModel(wandController_Left.controllerPosition, wandController_Right.controllerPosition); } } else { if (mainModelController._modelSplitted) { mainModelController.UnGroupModel(); } wandController_Left.ChangePointersStatus(true); wandController_Right.ChangePointersStatus(true); _isScaling = false; } #endregion #region ONE_HAND_UNSNAP //one handed interaction while two objects are already snapped, unsnap them??? /* if (wandController_Left.grabbedObject == true && wandController_Left.interactingItem.GetSnapStatus() == true) * { * //mainModelController.SetObjectSnapStatus(wandController_Left.interactingItem, false); * // mainModelController.SingleObjectHandle(wandController_Left.interactingItem.transform, "Left"); * // mainModelController.EnableDisableIsKinematic(wandController_Left.interactingItem.transform, null, false); * //Debug.Log("for left hand isKinematic set to false"); * } * if (wandController_Right.grabbedObject == true && wandController_Right.interactingItem.GetSnapStatus() == true) * { * //mainModelController.SetObjectSnapStatus(wandController_Right.interactingItem, false); * //mainModelController.SingleObjectHandle(wandController_Right.interactingItem.transform, "Right"); * // mainModelController.EnableDisableIsKinematic(null, wandController_Right.interactingItem.transform, false); * // Debug.Log("for right hand isKinematic set to false"); * }*/ #endregion #region TWO_HAND_SNAP //When both controllers hold some objects and those are dragged closely if (wandController_Left.grabbedObject == true && wandController_Right.grabbedObject == true) { #region CP1_NEW_SNAP if (wandController_Left.interactingItem.GetSnapStatus() == false || wandController_Right.interactingItem.GetSnapStatus() == false) { // if the picked object is not snapped if (mainModelController != null) { if (hasReadObjData == false) { mainModelController.SaveObjectsDataHandles(wandController_Left.interactingItem.transform, wandController_Right.interactingItem.transform); hasReadObjData = true; } // mainModelController.EnableDisableIsKinematic(wandController_Left.interactingItem.transform, wandController_Right.interactingItem.transform, true); mainModelController.DrawABeamBetweenObjects(wandController_Left.interactingItem.transform, wandController_Right.interactingItem.transform); _objectsAreInRange = mainModelController.CheckIFObjectsAreCloser(wandController_Left.interactingItem.transform, wandController_Right.interactingItem.transform); if (_objectsAreInRange) { _refObjectLeft = wandController_Left.interactingItem; _refObjectRight = wandController_Right.interactingItem; //Debug.Log("To snap: " + _refObjectLeft.transform.name + " " + _refObjectRight.transform.name); } else if (!_objectsAreInRange) { _refObjectLeft = null; _refObjectRight = null; } } } #endregion #region CP2_ALREADY_SNAPPED //check if initially any object is snapped and is child of a empty parent with tag "Snapped" //update position of parent transform instead of child object //but compare the new object with the first picked snapped object for relative distance and orientation? else if (wandController_Left.interactingItem.GetSnapStatus() == true || wandController_Right.interactingItem.GetSnapStatus() == true) { if (wandController_Left.interactingItem.GetSnapStatus() == true && wandController_Left.interactingItem.transform.parent != null && wandController_Left.interactingItem.transform.parent.tag.Equals("Snapped")) { //save reference of the touched object but transform the parent Debug.Log("Left object is already snapped"); _refObjectLeft = wandController_Left.interactingItem; } if (wandController_Right.interactingItem.GetSnapStatus() == true && wandController_Right.interactingItem.transform.parent != null && wandController_Right.interactingItem.transform.parent.tag.Equals("Snapped")) { //save reference of the touched object but transform the parent Debug.Log("Right object is already snapped"); _refObjectRight = wandController_Right.interactingItem; } // Transform parent objects position and rotation // ReferenceObject relative distance with the other object in wand which is not snapped yet. // If all conditions are true then snap it too } #endregion } #region CP3_FREE_TO_SNAP else if (wandController_Left.grabbedObject == false && wandController_Right.grabbedObject == false) { //when both objects are set free to be snapped, execute only when 2 objects are in range if (_objectsAreInRange) { if (_refObjectRight != null && _refObjectLeft != null) { Debug.Log("Snap objects; " + _refObjectLeft.transform.name + " " + _refObjectRight.transform.name); mainModelController.WhenCloserSnapObjects(_refObjectLeft.transform, _refObjectRight.transform); mainModelController.SetObjectSnapStatus(_refObjectLeft, true); mainModelController.SetObjectSnapStatus(_refObjectRight, true); mainModelController.SetAsChildOfParent(_refObjectLeft.transform, _refObjectRight.transform); _refObjectLeft = null; _refObjectRight = null; hasReadObjData = false; } _refObjectLeft = null; _refObjectRight = null; hasReadObjData = false; _objectsAreInRange = false; } else { //there exist any line renderer on beam object delete it if (mainModelController != null) { mainModelController.DeleteLineRendererFromBeamObjects(); hasReadObjData = false; _refObjectLeft = null; _refObjectRight = null; _objectsAreInRange = false; } } } #endregion #endregion } #endregion }