private void OnTriggerEnter(Collider other) { bool isOtherColliderHasPieceChildTag = other.CompareTag(TagConstants.TAG_NAME_PLAYER_1_PIECE_CHILD) || other.CompareTag(TagConstants.TAG_NAME_PLAYER_2_PIECE_CHILD); PieceMetadatas pieceMetadatasScript = other.GetComponent <PieceMetadatas>(); if (isOtherColliderHasPieceChildTag && !pieceMetadatasScript.IsSparkling) { PlayerPieceController parentPieceMovementScript = null; parentPieceMovementScript = other.GetComponentInParent <PlayerPieceController>(); if (parentPieceMovementScript == null) { return; } //If the piece is moving if (parentPieceMovementScript.IsMoving) { PieceMetadatas parentPieceMetadatasScript = other.transform.parent.GetComponent <PieceMetadatas>(); Vector3 sparkPosition = new Vector3(this.transform.position.x, other.transform.position.y, other.transform.position.z); GameObject currentSpark = Instantiate(sparkEffects, sparkPosition, sparkEffects.transform.rotation); currentSpark.transform.parent = other.gameObject.transform.parent; pieceMetadatasScript.IsSparkling = true; parentPieceMetadatasScript.IsSparkling = true; } } }
public static bool IsRotationPossible(GameObject objectToRotate) { PieceMetadatas pieceMetadatasScript = PieceUtils.FetchPieceMetadataScript(objectToRotate); List <Vector3> nodes = CalculatePoints(pieceMetadatasScript.MaxRotateAmplitude, objectToRotate); return(!SweepHasHit(nodes)); }
public static GameObject ClonePieceObject(GameObject parentPieceObjectToBeCloned) { PieceMetadatas parentPieceObjectToBeClonedMetaDataScript = FetchPieceMetadataScript(parentPieceObjectToBeCloned); Transform[] childrenTransform = parentPieceObjectToBeCloned.transform .GetComponentsInChildren <Transform>() .Where(child => child.gameObject != parentPieceObjectToBeCloned) .ToArray(); GameObject finalParent = new GameObject(); finalParent.transform.SetPositionAndRotation(parentPieceObjectToBeCloned.transform.position, parentPieceObjectToBeCloned.transform.rotation); foreach (Transform childTransform in childrenTransform) { GameObject child = new GameObject(); child.transform.SetPositionAndRotation(childTransform.position, childTransform.rotation); child.transform.parent = finalParent.transform; } PieceMetadatas finalParentMetaDatas = finalParent.AddComponent <PieceMetadatas>(); finalParentMetaDatas.IsExcentered = parentPieceObjectToBeClonedMetaDataScript.IsExcentered; finalParentMetaDatas.HasSpecificRotationBehaviour = parentPieceObjectToBeClonedMetaDataScript.HasSpecificRotationBehaviour; finalParentMetaDatas.MaxRotateAmplitude = parentPieceObjectToBeClonedMetaDataScript.MaxRotateAmplitude; finalParent.name = "Simulated => " + parentPieceObjectToBeCloned.name; return(finalParent); }
private bool IsPieceValidForPlay() { PieceMetadatas pieceMetadataScript = this.gameObject.GetComponent <PieceMetadatas>(); bool isNotForseeObject = !this.gameObject.CompareTag(TagConstants.TAG_NAME_PLAYER_1_FORESEE_PIECE) || !this.gameObject.CompareTag(TagConstants.TAG_NAME_PLAYER_2_FORESEE_PIECE); bool isPiecePlayable = pieceMetadataScript.IsPieceReady; bool isInDeletingState = GameUtils.FetchPlayersDeletingLinesState(this.OwnerId); return(isNotForseeObject && isPiecePlayable && this.IsMoving && !this.gameObJectRigidBody.isKinematic && !isInDeletingState); }
private void ManageGameFieldObject(GameObject piece, int playerId, Quaternion randomInstanciationRotation, List <Material> randomPieceColor) { PieceMetadatas pieceMetadatas = PieceUtils.FetchPieceMetadataScript(piece); float positionCorrection = 0f; if (pieceMetadatas.IsExcentered) { positionCorrection = 0.5f; } GameObject field = this.PlayersField[playerId]; Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(field.transform.transform.GetChild(0).gameObject); Vector3 instantiatePosition = new Vector3( fieldsize.x / 2 + field.transform.position.x - 0.5f + positionCorrection , 0.5f , fieldsize.z + field.transform.position.z - 1.5f); GameObject instanciatedPiece = Instantiate(piece, instantiatePosition, randomInstanciationRotation); PieceController genericController = null; if (ApplicationUtils.IsTypeComputer(playerId)) { genericController = PieceUtils.FetchPieceComputerPieceControllerScript(instanciatedPiece); } else { genericController = PieceUtils.FetchPiecePlayerPieceControllerScript(instanciatedPiece); } genericController.enabled = true; genericController.OwnerId = playerId; genericController.Field = field; for (int i = 0; i < randomPieceColor.Count; i++) { instanciatedPiece.transform.GetChild(i).GetComponent <MeshRenderer>().material = randomPieceColor[i]; } PieceMetadatas instanciatedPieceMetadataScript = PieceUtils.FetchPieceMetadataScript(instanciatedPiece); instanciatedPieceMetadataScript.IsPieceReady = true; //Update parent piece name and the children too thank to the pieceId this.UpdatePiecesName(instanciatedPiece); this.UpdatePieceChildrenTagName(playerId, instanciatedPiece); this.playersCurrentGamePiece[playerId] = instanciatedPiece; }
private void OnTriggerExit(Collider other) { PieceMetadatas pieceMetadatasScript = other.GetComponent <PieceMetadatas>(); if (pieceMetadatasScript.IsSparkling) { PieceMetadatas parentPieceMetadatasScript = other.GetComponentInParent <PieceMetadatas>(); parentPieceMetadatasScript.IsSparkling = false; GameObject[] effectList = GameObject.FindGameObjectsWithTag(TagConstants.TAG_NAME_SPARKLE_EFFECT); foreach (GameObject effect in effectList) { effect.transform.parent = null; Destroy(effect); } pieceMetadatasScript.IsSparkling = false; } }
private void RotateObject(bool isClockwise) { float yAxeRotation = MovementUtils.rotationAmount; float maxRotationAmount = MovementUtils.rotationMaxValue; PieceMetadatas pieceMetadatas = this.GetComponent <PieceMetadatas>(); if (!isClockwise) { yAxeRotation *= -1; maxRotationAmount *= -1; } yAxeRotation += Mathf.Round(this.transform.rotation.eulerAngles.y); yAxeRotation = Mathf.Clamp(yAxeRotation, MovementUtils.rotationMinValue, maxRotationAmount); if (yAxeRotation == 360f || yAxeRotation == -360f) { yAxeRotation = MovementUtils.rotationMinValue; } /*= Quaternion.Slerp(originRotation, destinationRotation, Mathf.Clamp(Time.time * PieceRotationSpeed, 0f, 1f));*/ this.transform.rotation = Quaternion.AngleAxis(yAxeRotation, Vector3.up); if (pieceMetadatas.HasSpecificRotationBehaviour) { float currentYRotationValue = this.transform.rotation.eulerAngles.y; if (currentYRotationValue == 90f || currentYRotationValue == 270f) { this.transform.position = this.transform.position + (Vector3.right / 2); } else { this.transform.position = this.transform.position + (Vector3.left / 2); } } Instantiate(pieceSwingEffect, this.transform.position, Quaternion.identity); }
public static void SimulateNextRotation(GameObject currentSimulatedObject, bool isClockwise) { PieceMetadatas pieceMetadatas = currentSimulatedObject.GetComponent <PieceMetadatas>(); float maxRotationAmount = 360f; float yAxeRotation = MovementUtils.rotationAmount; if (!isClockwise) { yAxeRotation *= -1; maxRotationAmount *= -1; } yAxeRotation += Mathf.Round(currentSimulatedObject.transform.rotation.eulerAngles.y); yAxeRotation = Mathf.Clamp(yAxeRotation, 0f, maxRotationAmount); if (yAxeRotation == 360f || yAxeRotation == -360f) { yAxeRotation = 0f; } currentSimulatedObject.transform.rotation = Quaternion.AngleAxis(yAxeRotation, Vector3.up); if (pieceMetadatas.HasSpecificRotationBehaviour) { float currentYRotationValue = currentSimulatedObject.transform.rotation.eulerAngles.y; if (currentYRotationValue == 90f || currentYRotationValue == 270f) { currentSimulatedObject.transform.position = currentSimulatedObject.transform.position + (Vector3.right / 2); } else { currentSimulatedObject.transform.position = currentSimulatedObject.transform.position + (Vector3.left / 2); } } }
private bool IsGameObjectOnLine(GameObject targetObject, int lineNumber, int playerId) { int?targetObjectLineNumber = null; String targetTagName = null; if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1) { targetTagName = TagConstants.TAG_NAME_PLAYER_1_FORESEE_PIECE; } else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2) { targetTagName = TagConstants.TAG_NAME_PLAYER_2_FORESEE_PIECE; } if (!targetObject.CompareTag(targetTagName)) { PieceMetadatas targetObjectScriptPieceMetadatas = targetObject.GetComponent <PieceMetadatas>(); targetObjectLineNumber = (int)(targetObjectScriptPieceMetadatas.CurrentPieceLine); } return(targetObjectLineNumber == lineNumber && LayerMask.LayerToName(targetObject.layer).Equals(LayerConstants.LAYER_NAME_DESTROYABLE_PIECE)); }
private void OnTriggerEnter(Collider other) { bool isOtherColliderHasPieceChildTag = other.CompareTag(TagConstants.TAG_NAME_PLAYER_1_PIECE_CHILD) || other.CompareTag(TagConstants.TAG_NAME_PLAYER_2_PIECE_CHILD); //if a piece child collide with something other than the background if (isOtherColliderHasPieceChildTag && this.IsCollisionAccepted()) { bool isThisColliderHasPieceChildTag = this.CompareTag(TagConstants.TAG_NAME_PLAYER_1_PIECE_CHILD) || this.CompareTag(TagConstants.TAG_NAME_PLAYER_2_PIECE_CHILD); PieceController genericParentPieceMovementScript = null; if (other.transform.parent == null && isOtherColliderHasPieceChildTag && this.transform.parent != null && isThisColliderHasPieceChildTag) { genericParentPieceMovementScript = PieceUtils.FetchCurrentlyActivatedPieceControllerScript(this.transform.parent.gameObject); } else { GameObject otherParent = other.transform.parent != null ? other.transform.parent.gameObject : other.transform.gameObject; genericParentPieceMovementScript = PieceUtils.FetchCurrentlyActivatedPieceControllerScript(otherParent); } if (genericParentPieceMovementScript == null) { return; } //If the piece are moving if (genericParentPieceMovementScript.IsMoving) { if (this.IsContactFromBelow(other)) { Rigidbody objectColidingParentRigidBody = other.GetComponentInParent <Rigidbody>(); if (objectColidingParentRigidBody == null) { return; } GameObject gameManagerObject = GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_GAME_MANAGER); GameManager gameManagerScript = gameManagerObject.GetComponent <GameManager>(); genericParentPieceMovementScript.IsMoving = false; objectColidingParentRigidBody.velocity = Vector3.zero; objectColidingParentRigidBody.isKinematic = true; PieceMetadatas parentPieceMetadatasScript = objectColidingParentRigidBody.gameObject.GetComponent <PieceMetadatas>(); if (parentPieceMetadatasScript.IsSparkling) { GameObject[] effectList = GameObject.FindGameObjectsWithTag(TagConstants.TAG_NAME_SPARKLE_EFFECT); foreach (GameObject effect in effectList) { effect.transform.parent = null; Destroy(effect); } PieceMetadatas[] metadataScripts = objectColidingParentRigidBody.gameObject.GetComponentsInChildren <PieceMetadatas>(); foreach (PieceMetadatas metadataScript in metadataScripts) { if (metadataScript.gameObject != objectColidingParentRigidBody.gameObject) { metadataScript.IsSparkling = false; } } parentPieceMetadatasScript.IsSparkling = false; } Instantiate(pieceFallSoundEffect, other.transform.position, Quaternion.identity); this.CorrectPiecePosition(objectColidingParentRigidBody.gameObject); this.UpdateMapDatasForObject(objectColidingParentRigidBody.gameObject, gameManagerScript, genericParentPieceMovementScript.OwnerId); gameManagerScript.CleanUpPieceObject(objectColidingParentRigidBody.gameObject, genericParentPieceMovementScript.OwnerId); gameManagerScript.DestroyObjectLines(genericParentPieceMovementScript.OwnerId); //test for the game over requirements if (gameManagerScript.IsGameOver(genericParentPieceMovementScript.OwnerId)) { gameManagerScript.GameOver(genericParentPieceMovementScript.OwnerId); int winnerId = genericParentPieceMovementScript.OwnerId == (int)PlayerEnum.PlayerId.PLAYER_1 ? (int)PlayerEnum.PlayerId.PLAYER_2 : (int)PlayerEnum.PlayerId.PLAYER_1; if (ApplicationUtils.IsInMultiPlayerMode()) { gameManagerScript.DeclareWinner(winnerId); } return; } if (!gameManagerScript.Restart) { gameManagerScript.PlayersSpawnAuthorisation[genericParentPieceMovementScript.OwnerId] = true; } } } } }