public bool VictoryChecker(int targetIndex) { if (myIndex - 1 + targetIndex < grid.kuboGrid.Length && myIndex - 1 + targetIndex >= 0) { if (grid.kuboGrid[myIndex - 1 + targetIndex] != null) { if (grid.kuboGrid[myIndex - 1 + targetIndex].cubeOnPosition != null) { if (grid.kuboGrid[myIndex - 1 + targetIndex].cubeType >= CubeTypes.BaseVictoryCube && grid.kuboGrid[myIndex - 1 + targetIndex].cubeType <= CubeTypes.SwitchVictoryCube) { victoryCubeOnPistion = grid.kuboGrid[myIndex - 1 + targetIndex].cubeOnPosition.GetComponent <_CubeBase>(); return(true); } else { return(false); } } else { return(false); } } else { return(false); } } else { return(false); } }
private void CheckForVictory() { //touchingVictory = ProximityChecker(_DirectionCustom.fixedUp, CubeTypes.BaseVictory, CubeLayers.None); touchingVictory = VictoryChecker(_DirectionCustom.LocalScanner(facingDirection)); // flip the bools when the delivery cube loses track of the victory cube if (touchingVictory == false && locked == true) { victoryCubeOnPistion.isPastilleAndIsOn = false; StartCoroutine(victoryCubeTracker.VictoryFX(false)); victoryCubeTracker.ChangeEmoteFace(_EmoteIdleTex); VictoryConditionManager.instance.DecrementVictory(); locked = false; } if (touchingVictory && locked == false) { locked = true; LightShaft.GetComponent <FB_Delivry>().ActivatePSFB(); StartCoroutine(victoryCubeOnPistion.VictoryFX(true)); victoryCubeOnPistion.isPastilleAndIsOn = true; victoryCubeOnPistion.ChangeEmoteFace(victoryCubeOnPistion._EmotePastilleTex); victoryCubeTracker = victoryCubeOnPistion; VictoryConditionManager.instance.IncrementVictory(); PlaySound(); } }
//set the node's information relevant to the cube type, then send the Transform information to the cube void SetCubeInfo(_CubeBase cube, CubeLayers cubeLayers, CubeTypes cubeTypes, bool _static) { cube.myIndex = currentNode.nodeIndex; cube.myCubeType = cubeTypes; cube.myCubeLayer = cubeLayers; cube.isStatic = _static; cube.facingDirection = currentNode.facingDirection; //sets rotation and position according to the values of the relevant node in kuboGrid cube.OnLoadSetTransform(); }
private void PlaceCube(RaycastHit hit) { //get the index of the cube you just hit currentHitCube = hit.collider.gameObject.GetComponent <_CubeBase>(); hitIndex = currentHitCube.myIndex; //calculate where you're placing the new cube CubeOffset(hit.normal); //if the current node doesn't have a cube on it, place a new cube if (currentCube != CubeTypes.None && IndexIsEmpty()) { //create a new Cube and add the CubeObject component to store its index GameObject newCube = Instantiate(SaveAndLoad.instance.cubePrefab); OnPlaceCube(newCube); } }
void SendInfoToCube(_CubeBase cubeBase, CubeTypes cubeType, CubeLayers cubeLayer, bool _static) { //Cube info if (cubeBase.gameObject.GetComponent <_CubeScanner>() != null) { cubeBase.facingDirection = FacingDirection.forward; } cubeBase.myIndex = GetCubeIndex(); cubeBase.isStatic = _static; cubeBase.myCubeLayer = cubeLayer; cubeBase.myCubeType = cubeType; cubeBase.gameObject.transform.position = GetCubePosition(); cubeBase.gameObject.transform.parent = grid.transform; cubeBase.SetRelevantNodeInfo(); }
private void DeleteCube(RaycastHit hit) { //get the index of the cube you just hit currentHitCube = hit.collider.gameObject.GetComponent <_CubeBase>(); hitIndex = currentHitCube.myIndex; moveWeight = 0; //why is this here ? //if there is a cube if (!IndexIsEmpty()) { currentHitCube.ResetCubeInfo(); //reset the grid info Destroy(currentHitCube.gameObject); } grid.placedObjects.Remove(hit.collider.gameObject); //if there are no more gridObjects, redraw the grid if (grid.placedObjects.Count == 0) { grid.RefreshGrid(); } }
private void RotateCube(RaycastHit hit, Vector3 userInputPosition) { currentHitCube = hit.collider.gameObject.GetComponent <_CubeBase>(); hitIndex = currentHitCube.myIndex; Quaternion newRotation; /*if (hitIndex != 0 && hit.collider.gameObject != null) * { * int rotationX = (int)CustomScaler.Scale((int)userInputPosition.x, 0, Camera.main.pixelWidth, -360, 360); * rotationX = rotationX / 10; * * int rotationY = (int)CustomScaler.Scale((int)userInputPosition.y, 0, Camera.main.pixelHeight, -360, 360); * rotationY = rotationY / 10; * * if (rotationX % 9 * rotationDampen == 0) * { * Vector3 rotationVector = new Vector3(rotationX * 10, * hit.collider.gameObject.transform.rotation.y, * hit.collider.gameObject.transform.rotation.z); * * newRotation = Quaternion.Euler(rotationVector); * * Debug.Log(rotationVector); * hit.collider.gameObject.transform.rotation = newRotation; * } * * if (rotationY % 9 * rotationDampen == 0) * { * Vector3 rotationVector = new Vector3(hit.collider.gameObject.transform.rotation.y, * rotationY * 10, * hit.collider.gameObject.transform.rotation.z); * * newRotation = Quaternion.Euler(rotationVector); * * Debug.Log(rotationVector); * hit.collider.gameObject.transform.rotation = newRotation; * } * }*/ if (hitIndex != 0 && hit.collider.gameObject != null) { //increment the enum if it isn't the last one, else reset it to the first if (currentHitCube.facingDirection < FacingDirection.left) { currentHitCube.facingDirection++; } else { currentHitCube.facingDirection = FacingDirection.up; } //returns the coordinates that the cube should adopt according to its enum Vector3 rotationVector = CubeFacingDirection.CubeFacing(currentHitCube.facingDirection); //convert the coordinates to a euler angle newRotation = Quaternion.Euler(rotationVector); //assign the quaternion to the cube's transform hit.collider.gameObject.transform.rotation = newRotation; //set the rotation info in node grid currentHitCube.SetRelevantNodeInfo(); } }
// Start is called before the first frame update public void GameSet() { #region LIST VERSION baseCubeArray = new List <_CubeBase>(); moveCubeArray = new List <_CubeMove>(); elevatorsArray = new List <ElevatorCube>(); baseCube = new List <_CubeBase>(); moveCube = new List <_CubeMove>(); elevators = new List <ElevatorCube>(); foreach (var item in _Grid.instance.kuboGrid) { if (item.cubeOnPosition != null) { _CubeBase baseCube = item.cubeOnPosition.gameObject.GetComponent <_CubeBase>(); _CubeMove cubeMove = item.cubeOnPosition.gameObject.GetComponent <_CubeMove>(); ElevatorCube elevatorCube = item.cubeOnPosition.gameObject.GetComponent <ElevatorCube>(); if (cubeMove != null) { moveCubeArray.Add(cubeMove); } if (baseCube != null) { baseCubeArray.Add(baseCube); } if (elevatorCube != null) { elevatorsArray.Add(elevatorCube); } } } #endregion #region ARRAY VERSION /*elevators.Clear(); * moveCube.Clear(); * baseCube.Clear(); * * Array.Clear(moveCubeArray, 0, moveCubeArray.Length); * Array.Clear(baseCubeArray, 0, baseCubeArray.Length); * Array.Clear(elevatorsArray, 0, elevatorsArray.Length); * * moveCubeArray = FindObjectsOfType<_CubeMove>(); // TODO : DEGEULASSE * baseCubeArray = FindObjectsOfType<_CubeBase>(); * elevatorsArray = FindObjectsOfType<ElevatorCube>(); */ #endregion foreach (ElevatorCube elevator in elevatorsArray) { elevators.Add(elevator); } foreach (_CubeMove cube in moveCubeArray) { moveCube.Add(cube); } foreach (_CubeBase cube in baseCubeArray) { baseCube.Add(cube); } }
// Start is called before the first frame update void Start() { cubeBase = GetComponent <_CubeBase>(); }