public Vector3 GetRootPositionHit(TouchCover touch) { var cameraPos = noteCamera.ScreenToWorldPoint(touch.position); screenTouchPos.transform.position = cameraPos; return(screenTouchPos.transform.localPosition); }
public override void Press(TouchCover _touchCover) { this.touchCover = _touchCover; if (!isClickable) { return; } isClickable = false; isFinish = true; isMoveComplete = false; if (touchCover != null) { InGameUIController.Instance.CacheTouchForNote(touchCover, this); } MidiPlayer.Instance.PlayPianoNotes(data.notes, InGameUIController.Instance.gameplay.GetSpeedRatio(), true, data.soundDelay); InGameUIController.Instance.gameplay.IncreaseAndShowScore(); InGameUIController.Instance.gameplay.TileFinished(); AchievementHelper.Instance.LogAchievement("totalNoteHit"); //isClickable = false; if (GameConsts.isPlayAuto || InGameUIController.Instance.gameplay.isListenThisSong) { isActiveAuto = true; } blinkEffect.gameObject.SetActive(true); blinkEffect.StartPlayback(); if (!InGameUIController.Instance.gameplay.isListenThisSong) { //Debug.Log("Is listen this song; " + InGameUIController.Instance.gameplay.isListenThisSong); touchKeepEffect.OnTouchDown(gameObject, touchCover); } }
public void ClearCacheTouchForNote(TouchCover touch, NoteMulti multi) { if (dicTouch.ContainsKey(touch.fingerId)) { NoteMulti multiCache = dicTouch[touch.fingerId]; if (multi == multiCache) { dicTouch.Remove(touch.fingerId); } } }
/// <summary> /// Resets the touch. When release of cancel touch /// </summary> /// <param name="touch">Touch.</param> public void ResetTouch(TouchCover touch) { if (dicTouch.ContainsKey(touch.fingerId)) { dicTouch[touch.fingerId].OnKeepTouchEnd(); dicTouch.Remove(touch.fingerId); } if (dicTouchCover.ContainsKey(touch.fingerId)) { dicTouchCover.Remove(touch.fingerId); } }
public void OnTouchDown(GameObject note, TouchCover touch) { //if (note != null) { NoteTouchEffect effectScript = queEffect.Count > 0 ? queEffect.Dequeue() : baseEffectScript.Instantiate(); effectScript.OnTouchDown(noteCamera.ScreenToWorldPoint(touch.position)); if (!dicEffect.ContainsKey(note)) { dicEffect.Add(note, effectScript); } //} }
// Use this for initialization //void Start () { //} //// Update is called once per frame //void Update () { //} public override void Press(TouchCover _touchCover) { if (!isClickable) { return; } InGameUIController.Instance.gameplay.StartGame(); isClickable = false; gameObject.SetActive(false); //EffectWhenFinish (); LevelDataModel level = GameManager.Instance.SessionData.currentLevel; Mio.Utils.AnalyticsHelper.Instance.LogSongstart(level.songData.name); }
public void OnHoldTouch(TouchCover touch) { if (dicTouch.ContainsKey(touch.fingerId)) { NoteMulti multi = dicTouch[touch.fingerId]; //clean up completed touch references if (multi.IsMoveCompleted()) { ResetTouch(touch); } multi.OnKeepTouch(); multi.IncreaseActiveHeight(cacheDeltaMove.y); } }
public override void Press(TouchCover _touchCover) { //this.touchCover = _touchCover; if (!isClickable) { return; } isClickable = false; isFinish = true; InGameUIController.Instance.gameplay.ProcessBonusTile(this); //Debug.Log("goeffect"); DiamondEffectController.Instance.PlayEffect(this.transform.position); EffectWhenFinish(); AchievementHelper.Instance.LogAchievement("pickDiamondInGame"); }
public virtual void Press(TouchCover _touchCover) { this.touchCover = _touchCover; if (!isClickable) { return; } isClickable = false; isFinish = true; //play appropriate sound MidiPlayer.Instance.PlayPianoNotes(data.notes, InGameUIController.Instance.gameplay.GetSpeedRatio(), true, data.soundDelay); InGameUIController.Instance.gameplay.IncreaseAndShowScore(); InGameUIController.Instance.gameplay.TileFinished(); AchievementHelper.Instance.LogAchievement("totalNoteHit"); EffectWhenFinish(); }
public bool CheckGameOver(TouchCover touch) { NoteSimple note = null; Vector3 vec = GetRootPositionHit(touch); //skip first note (which is a special start object) if (vec.y <= startObj.transform.localPosition.y + 480) { return(false); } //start checking from the end of the note list //check for a small bit of tiles only, not to go too far to save calculating time for (int i = 0; i < listNoteActive.Count && i < 6; i++) { float min = listNoteActive[i].transform.localPosition.y; float max = min + listNoteActive[i].height; //check if the touch on background has any tiles with the same Y? if (vec.y >= min && vec.y <= max) { //if yes, check if there is any tile at that exact location? float minX = listNoteActive[i].transform.localPosition.x; float maxX = minX + tileWidth; if (vec.x >= minX && vec.x <= maxX) { //if yes, then the touch is fine, because may be we touch on an used tile //Debug.Log("Touched on background, but saved by note " + note.gameObject.name); return(false); } else { //if not touch on any tiles, meaning the user has missed it note = listNoteActive[i]; break; } } } //if there are no tile next to current touch if (note == null) { //mean the touch is fine return(false); } return(true); }
public void GenerateNoteDie(TouchCover touch) { Vector3 posGenererate = Vector3.zero; float heightGenerate = 480; NoteSimple note = null; Vector3 vec = GetRootPositionHit(touch); posGenererate = vec; for (int i = 0; i < listNoteActive.Count; i++) { float min = listNoteActive[i].transform.localPosition.y; float max = min + listNoteActive[i].height; if (vec.y >= min && vec.y <= max) { note = listNoteActive[i]; } } if (note != null) { int x = (int)(posGenererate.x / tileWidth); posGenererate = note.transform.localPosition; posGenererate.x = x * tileWidth; heightGenerate = note.height; } else { //Should never go to here int x = (int)(vec.x / tileWidth); posGenererate.x = x * tileWidth; heightGenerate = vec.y; } GameObject objDie = GameObject.Instantiate(prefabDie); objDie.transform.parent = lineRoot; objDie.transform.localScale = Vector3.one; objDie.transform.localPosition = posGenererate; objDie.GetComponent <NoteDie>().Setup(heightGenerate); GameObject.Destroy(objDie, 2f); }
public IEnumerator RoutineGameOverByPressWrong(TouchCover touch) { //visualize where the touch gone wrong GenerateNoteDie(touch); MidiPlayer.Instance.PlayPianoNote(PIANO_NOTE_GAME_OVER); yield return(new WaitForSeconds(0.4f)); if (listNoteActive.Count > 1) { Vector3 bottom = GetBottomPosition(); int stopIndex = 0; for (int i = 0; i < listNoteActive.Count; i++) { if (listNoteActive[i].IsClickable()) { stopIndex = i; break; } } //calculate the distance need to move back the camera float yMove = bottom.y - listNoteActive[stopIndex].transform.localPosition.y; Vector3 vecStart = noteCamera.transform.localPosition; Vector3 vecEnd = vecStart; vecEnd.y -= yMove * scale; //reset the last note listNoteActive[stopIndex].ResetClickable(); //move back camera a bit noteCamera.transform.DOLocalMove(vecEnd, 0.5f).SetEase(Ease.OutQuad).Play(); } yield return(new WaitForSeconds(0.8f)); gameplay.ProcessGameOverEvent(); }
public void GameOverByPressWrong(TouchCover touch) { AchievementHelper.Instance.LogAchievement("totalMiss"); gameplay.ChangeStatusToGameOver(); StartCoroutine(RoutineGameOverByPressWrong(touch)); }
public void CacheTouchForNote(TouchCover touch, NoteMulti multi) { dicTouch[touch.fingerId] = multi; }
public void ProcessControlTouch(TouchCover touch) { if (!gameStarted) { return; } if (touch == null) { return; } //Touch Press if (touch.phase == TouchPhase.Began) { Vector2 rayOrigin = noteCamera.ScreenToWorldPoint(touch.position); //check if mouse hit any object? RaycastHit2D hit = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.MainGameMask); if (hit && hit.transform != null) { string hitObjName = hit.transform.name.ToLower(); //start object? if (gameplay.CurrentGameStage != TileMasterGamePlay.GameState.Playing) { if (hitObjName.Contains("start")) { //game start NoteStart noteStart = hit.transform.gameObject.GetComponent <NoteStart>(); if (noteStart != null) { noteStart.Press(touch); } } } //tiles? if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing || gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue || gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay) { if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue) { gameplay.StartGame(); } if (hitObjName.Contains("simple_")) { NoteSimple simple = hit.transform.gameObject.GetComponent <NoteSimple>(); if (simple != null && CanTouchNote(simple)) { simple.Press(touch); } } else if (hitObjName.Contains("multi_")) { NoteMulti multi = hit.transform.gameObject.GetComponent <NoteMulti>(); if (multi != null && CanTouchNote(multi)) { multi.Press(touch); multi.OnShowUIWhenPress(GetRootPositionHit(touch)); } } else if (hitObjName.Contains("bonus")) { NoteBonus bonus = hit.transform.gameObject.GetComponent <NoteBonus>(); if (bonus != null) { bonus.Press(null); } } } } else { //if the touch didn't hit any note, check for hit on background RaycastHit2D bgCheck = Physics2D.Raycast(rayOrigin, Vector2.zero, 100, ProjectConstants.Layers.BackgroundMask); if (bgCheck.transform != null) { if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Playing || gameplay.CurrentGameStage == TileMasterGamePlay.GameState.AutoPlay) { if (CheckGameOver(touch)) { GameOverByPressWrong(touch); } } else if (gameplay.CurrentGameStage == TileMasterGamePlay.GameState.Continue) { gameplay.StartGame(); } } } } // Touch Hold else if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) { OnHoldTouch(touch); } else { ResetTouch(touch); } }
public void OnProcessInputControl() { if (!canTouch) { return; } #if UNITY_EDITOR // in editor simulation one touch TouchCover touch = null; if (!dicTouchCover.TryGetValue(0, out touch)) { touch = new TouchCover(0); dicTouchCover[0] = touch; } bool isUpdate = false; if (Input.GetMouseButtonDown(0)) { //press touch.position = Input.mousePosition; touch.phase = TouchPhase.Began; isUpdate = true; } else if (Input.GetMouseButtonUp(0)) { //release touch.position = Input.mousePosition; touch.phase = TouchPhase.Ended; isUpdate = true; } else if (Input.GetMouseButton(0)) { //hole touch.position = Input.mousePosition; touch.phase = TouchPhase.Stationary; isUpdate = true; } if (isUpdate) { ProcessControlTouch(touch); } #else // for multi-touch on device for (int i = 0; i < Input.touchCount; i++) { TouchCover touch = null; if (!dicTouchCover.TryGetValue(Input.touches[i].fingerId, out touch)) { touch = new TouchCover(Input.touches[i].fingerId); dicTouchCover[Input.touches[i].fingerId] = touch; //++currentTouch; /*if(currentTouch >= 2) {*/ //Debug.Log("================\n Added touch id " + touch.fingerId + " on frame " + framecount); //} } touch.position = Input.touches[i].position; touch.phase = Input.touches[i].phase; ProcessControlTouch(touch); } if (Input.touchCount <= 0) { TouchCover touch = null; if (!dicTouchCover.TryGetValue(0, out touch)) { touch = new TouchCover(0); dicTouchCover[0] = touch; } } #endif }