IEnumerator LitBlocks() { List <BlockBehavior> matchedCombinedBlocks = new List <BlockBehavior>(); // random order for (int i = 0; i < blocks.Count; i++) { BlockBehavior currBlock = blocks[i].GetComponent <BlockBehavior>(); if (currBlock.blockState.value == BlockStates.matched) { // skip the combined block for the last moment // only add either purple or yellow if (currBlock.isCombinedBlock) { if (currBlock.blockColor == BlockColors.purple) { matchedCombinedBlocks.Add(currBlock); } continue; } if (isServer) { currBlock.RpcFinaleParticles(); } yield return(new WaitForSeconds(0.1f)); if (isServer) { currBlock.RpcFinale(); } yield return(new WaitForSeconds(0.2f)); } } // combined block goes last! if (matchedCombinedBlocks != null && matchedCombinedBlocks.Count > 0) { for (int i = 0; i < matchedCombinedBlocks.Count; i++) { if (isServer) { matchedCombinedBlocks[i].RpcFinaleParticles(); } yield return(new WaitForSeconds(0.1f)); if (isServer) { matchedCombinedBlocks[i].RpcFinale(); } yield return(new WaitForSeconds(0.2f)); } } yield return(new WaitForSeconds(1f)); if (isServer) { hasFinaleDone = true; } }
public void OnMatch() { blockState.value = BlockStates.matched; isMatchable = false; curGlow = rend.material.GetFloat("_MKGlowPower"); curTexGlow = rend.material.GetFloat("_MKGlowTexStrength"); audioSource.PlayOneShot(matchSound); if (col) { col.enabled = false; } if (matchableSlot) { matchableSlot.slotState = SlotStates.idle; matchableSlot.isMatched = true; matchableSlot.matchedBlock = this; } Debug.Log("match"); // combined block clean up if (isCombinedBlock) { // we turn off the client block at all if (!isServer) { // enable server block Renderer[] rends = pairBlock.GetComponentsInChildren <Renderer>(); for (int i = 0; i < rends.Length; i++) { if (!rends[i].enabled) { rends[i].enabled = true; } } // disable self rend.enabled = false; childRenderer.enabled = false; } pairBlock = null; } UIController.Instance.SetSnackbarText("match, slot: " + matchableSlot + " / slot state: " + matchableSlot.slotState); }
void FindOtherCombinedBlock() { Debug.Log("there is no pair block, try to find one"); UIController.Instance.SetSnackbarText("there is no pair block, try to find one"); for (int i = 0; i < combinedBlockBehaviors.Count; i++) { BlockBehavior currentBlock = combinedBlockBehaviors[i]; // skip self if (currentBlock == this) { continue; } if (currentBlock.blockState.value == BlockStates.grabbed) { pairBlock = currentBlock; UIController.Instance.SetSnackbarText("pair found: " + pairBlock); return; } } }
void Update() { if (!isLocalPlayer) { return; } if (GameManager.Instance.gamestate == GameStates.play) { // now able to play Ray ray = new Ray(Camera.main.transform.position, Camera.main.transform.forward); RaycastHit hit; if (playerState == PlayerStates.match) { playerState = PlayerStates.idle; } // release if (playerState == PlayerStates.grab && !isTouching) { // if the slot is close enough, match the block with the slot if (currentBlock.isMatchable) { playerState = PlayerStates.match; currentBlock.OnMatch(); UIController.Instance.SetSnackbarText("match! " + currentBlock.gameObject); Debug.Log("match"); CmdRequestToAddScore(); return; } playerState = PlayerStates.release; UIController.Instance.SetSnackbarText("release! " + currentBlock.gameObject); currentBlock.OnRelease(); currentBlock = null; Debug.Log("release"); return; } // when hover, if you touch, then grab if (playerState == PlayerStates.hover && isTouching) { playerState = PlayerStates.grab; currentBlock.OnGrab(); // UIController.Instance.SetSnackbarText("grab! " + currentBlock.gameObject); // Debug.Log("grab"); return; } // touching? if (Input.touchCount > 0) { if (Input.GetTouch(0).phase == TouchPhase.Ended || Input.GetTouch(0).phase == TouchPhase.Canceled) { isTouching = false; } else { isTouching = true; } } else { isTouching = false; } if (Physics.Raycast(ray, out hit, hoverDistance)) { // check if the block is interactable GameObject temp = hit.collider.gameObject; if (playerState == PlayerStates.grab || playerState == PlayerStates.release) { return; } if ((currentBlock == null || currentBlock.gameObject != temp) && temp.GetComponent <NetworkIdentity>().hasAuthority) { if (currentBlock != null && currentBlock.gameObject != temp) { if (currentBlock.blockState.value == BlockStates.hovered) { currentBlock.OnIdle(); } } currentBlock = temp.GetComponent <BlockBehavior>(); playerState = PlayerStates.hover; currentBlock.OnHover(); // UIController.Instance.SetSnackbarText("hovering! " + currentBlock.name); // Debug.Log("hover"); } } else if (playerState != PlayerStates.idle && playerState != PlayerStates.grab) // not hitting anything { if (currentBlock) { currentBlock.OnIdle(); } currentBlock = null; playerState = PlayerStates.idle; // UIController.Instance.SetSnackbarText("idling! not hovering anything or non-interactable block!"); // Debug.Log("idle"); } Debug.DrawRay(Camera.main.transform.position, Camera.main.transform.forward); } }