/// <summary> /// Recover the newest Block inside the RemovedBlockStack /// </summary> public void RecoverLastRemovedBlock(HANDSIDE handSide) { //Stack is empty, can't restore nonexsiting Blocks if (RemovedBlockStack.Count == 0) { return; } //Get the first Block or Structure from the Stack List <BlockSave> blocksToRestore = RemovedBlockStack.Pop(); //Restore the Block or Blocks by loading the BlockSave and add them back to the History foreach (BlockSave blockSave in blocksToRestore) { SaveGameManager.LoadBlock(blockSave); blockPlacingHistory.Add(new HistoryObject(blockSave.guid, blockSave.timeStamp)); } //Connect the Blocks back //TODO: Reset the AcceptCollisionAsConnection to false again foreach (BlockSave blockSave in blocksToRestore) { SaveGameManager.ConnectBlocks(blockSave); } }
/// <summary> /// Ends the pulling of the Marker /// </summary> /// <param name="handSide"></param> public void MarkerPullingEnded(HANDSIDE handSide) { switch (handSide) { case HANDSIDE.HAND_LEFT: if (Vector3.Distance(startPosition, HandLeft.transform.position) < PullThreshold) { BoxDrawer.RemoveBox(); ResetMarker(); } else { } BoxDrawer.ConfigureBoxCollider(currentBoxCollider); break; case HANDSIDE.HAND_RIGHT: if (Vector3.Distance(startPosition, HandRight.transform.position) < PullThreshold) { BoxDrawer.RemoveBox(); ResetMarker(); } BoxDrawer.ConfigureBoxCollider(currentBoxCollider); break; } }
/// <summary> /// Starts the pulling of the Marker, resets the old Marker /// </summary> /// <param name="handSide"></param> public void MarkerPullingStarted(HANDSIDE handSide) { ResetMarker(); BoxDrawer.ActivateBox(); switch (handSide) { case HANDSIDE.HAND_LEFT: startPosition = HandLeft.transform.position; BoxDrawer.SetStartPosition(HandLeft.transform.position); break; case HANDSIDE.HAND_RIGHT: startPosition = HandRight.transform.position; BoxDrawer.SetStartPosition(HandRight.transform.position); break; } }
/// <summary> /// Callback for when right TouchPad is up /// </summary> /// <param name="fromAction"></param> /// <param name="fromSource"></param> private void RightTouchPadUp(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) { switch (CurrentMenuState) { case MenuState.BOTH_CLOSED: { //Check if Teleport TouchPad position was touched if (TouchPadPosition.GetLastAxis(fromSource).y > 0 && TouchPadPosition.GetLastAxis(fromSource).x > leftArraowActivationThreshold && TouchPadPosition.GetLastAxis(fromSource).x < rightArraowActivationThreshold) { OnTeleportUpRight.Invoke(HANDSIDE.HAND_RIGHT); } //Leftside of TouchPad was clicked else if (TouchPadPosition.GetLastAxis(fromSource).x < leftArraowActivationThreshold) { OnLeftArrowClick.Invoke(HANDSIDE.HAND_RIGHT); } //Rightside of the TouchPad was clicked else if (TouchPadPosition.GetLastAxis(fromSource).x > rightArraowActivationThreshold) { OnRightArrowClick.Invoke(HANDSIDE.HAND_RIGHT); } break; } case MenuState.CURRENTLY_PULLING: { //Stop the pulling of marker if (startedPulling == HANDSIDE.HAND_RIGHT) { OnEndMarkerPull.Invoke(HANDSIDE.HAND_RIGHT); startedPulling = HANDSIDE.HAND_NONE; CurrentMenuState = MenuState.BOTH_CLOSED; } break; } } }
//private void ManipulateHistory(SteamVR_Action_Vector2 fromAction, SteamVR_Input_Sources fromSource, Vector2 axis, Vector2 delta) //{ // if (MenuManager.CurrentMenuState == MenuState.BOTH_CLOSED && confirmAction.GetStateDown(fromSource)) // { // if (fromAction.GetAxis(handInput).x < -0.7f) // { // RemoveLastPlacedBlock(); // } // else if (fromAction.GetAxis(handInput).x > 0.7f) // { // RecoverLastRemovedBlock(); // } // } //} /// <summary> /// Removes the newest placed Block or Structure from the scene and saves it in the RemovedBlockStack /// </summary> public void RemoveLastPlacedBlock(HANDSIDE handSide) { //Sort after Timestamp blockPlacingHistory.Sort(); //Set index to the last place of the HistoryList int index = blockPlacingHistory.Count - 1; //No item inside the HistoryList if (index < 0) { return; } //Get the newest TimeStamp from the HistoryList int lastTimeStamp = blockPlacingHistory[index].timeStamp; //List to save HistoryOjects that were placed at the same time as the last HistoryObject in HistoryList List <HistoryObject> lastHistoryObjects = new List <HistoryObject>(); //Search HistoryList for all Objects with same TimeStamp while (index >= 0 && blockPlacingHistory[index].timeStamp == lastTimeStamp) { lastHistoryObjects.Add(blockPlacingHistory[index]); index--; } //Get the actual Block by their Guid, save their values und Remove them form the Scene List <BlockSave> savedBlocks = new List <BlockSave>(); foreach (HistoryObject historyObject in lastHistoryObjects) { savedBlocks.Add(new BlockSave(GetBlockByGuid(historyObject.guid))); RemoveBlock(historyObject.guid); } //Add the saved Block values to the Stack RemovedBlockStack.Push(savedBlocks); }
/// <summary> /// Called while the Marker is pulled, updates the dimensions of the Box while the player pulls /// </summary> /// <param name="handSide"></param> public void MarkerIsPulled(HANDSIDE handSide) { if (!currentBoxCollider.enabled) { currentBoxCollider.enabled = true; } switch (handSide) { case HANDSIDE.HAND_LEFT: BoxDrawer.ConfigureBoxCollider(currentBoxCollider); BoxDrawer.DrawCube(HandLeft.transform.position); break; case HANDSIDE.HAND_RIGHT: BoxDrawer.ConfigureBoxCollider(currentBoxCollider); BoxDrawer.DrawCube(HandRight.transform.position); break; } }
/// <summary> /// Callback for when Right TouchPad was clicked, check if the Marker section of TouchPad was pressed /// </summary> /// <param name="fromAction"></param> /// <param name="fromSource"></param> private void RightTouchPadDown(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource) { //Return if Menu is open or Marker is currently pulled if (CurrentMenuState != MenuState.BOTH_CLOSED || startedPulling != HANDSIDE.HAND_NONE) { return; } //Check if Marker TouchPad position was touched else if (TouchPadPosition.GetLastAxis(fromSource).y < 0 && TouchPadPosition.GetLastAxis(fromSource).x > leftArraowActivationThreshold && TouchPadPosition.GetLastAxis(fromSource).x < rightArraowActivationThreshold) { OnStartMarkerPull.Invoke(HANDSIDE.HAND_RIGHT); startedPulling = HANDSIDE.HAND_RIGHT; CurrentMenuState = MenuState.CURRENTLY_PULLING; } //Check if Teleport TouchPad position was touched else if (TouchPadPosition.GetLastAxis(fromSource).y > 0 && TouchPadPosition.GetLastAxis(fromSource).x > leftArraowActivationThreshold && TouchPadPosition.GetLastAxis(fromSource).x < rightArraowActivationThreshold) { OnTeleportDownRight.Invoke(HANDSIDE.HAND_RIGHT); } }