private int FindFreeLane(WordGameObjectCtrl wordCtrl) { // get a random lane randomLane = Mathf.FloorToInt(Random.Range(0, 2.99f)); freeLane = -1; // if the time in the lane is to close then check other two lanes and break when you find a free lane if (wordCtrl.hitTime - lanesTimes[randomLane] < songData.minimumTimeDifferenceInLane) { int nextLane = 0; for (int i = 1; i < 3; i++) { nextLane = (randomLane + i) % 3; if (wordCtrl.hitTime - lanesTimes[nextLane] >= songData.minimumTimeDifferenceInLane) { freeLane = nextLane; return(freeLane); } } // if no lane is free find one with lowest time if (freeLane == -1) { float _min = Mathf.Min(lanesTimes); int minIndex = System.Array.IndexOf(lanesTimes, _min); freeLane = minIndex; } } else { freeLane = randomLane; } return(freeLane); }
void RegisterWordHit(ClickAreaCtrl cArea, WordGameObjectCtrl wrd) { if (wrd.isFake) { //Debug.Log("FAKE HIT"); ScoreCtrl.FakeClick(); UIEventManager.FakeWordHitEvent(); return; } hitFX = PoolManager.SpawnObject(successWordHitFX); HitWordFX hitWordFX = hitFX.GetComponent <HitWordFX>(); isPerfect = Mathf.Abs(currentAudioTime - wrd.hitTime) < Config.CLICK_PERFECT_TIME_OFFSET; if (isPerfect) { hitWordFX.perfect = true; } else { hitWordFX.perfect = false; } GameLogger.AddTap(wrd.hitTime, currentAudioTime, wrd.wordData.text); hitFX.transform.position = cArea.gameObject.transform.position; hitWordFX.runAnim(); ScoreCtrl.WordHit(wrd.orderIndex, currentAudioTime, wrd.hitTime, isPerfect); }
void Update() { if (!audioSource) { return; } if (!audioSource.isPlaying) { return; } currentAudioTime = audioSource.timeSamples / sampleRate; if (currentAudioTime >= nextShowTime && listIndex < wordsCtrlList.Count) { currentWord = wordsCtrlList[listIndex]; currentWord.gameObject.SetActive(true); listIndex++; if (listIndex < wordsCtrlList.Count - 1) { nextShowTime = wordsCtrlList[listIndex].showTime; } } //moving foreach (WordGameObjectCtrl word in wordsCtrlList) { if (word.gameObject.activeSelf) { rangeTime = word.hitTime - word.showTime; percentTime = (currentAudioTime - word.showTime) / rangeTime; if (word.isClicked != true) { newY = (distanceOnScreen - (distanceOnScreen * percentTime)) + endPozitionOnScreen; //xPozitions[word.wordData.index] word.gameObject.transform.localPosition = Camera.main.ScreenToWorldPoint(new Vector3(xPozitions[word.xPositionIndex], newY, 10)); } else { word.gameObject.transform.localPosition = Vector3.Lerp(word.startPosition, word.endPosition, percentTime); } if (currentAudioTime >= word.hitTime) { word.textMesh.color = new Color(255, 0, 255); } if (percentTime >= 1 && !word.holdGraphicTweening) { word.StartHoldTween(); } } } CheckTouches(); }
void OnTriggerEnter2D(Collider2D coll) { if (coll.gameObject.tag == "WordCollider") { wordCtrl = coll.gameObject.GetComponent <WordGameObjectCtrl>(); if (!colliders.Contains(wordCtrl)) { colliders.Add(wordCtrl); } } }
void OnTriggerExit2D(Collider2D coll) { if (coll.gameObject.tag == "WordCollider") { wordCtrl = coll.gameObject.GetComponent <WordGameObjectCtrl>(); if (!wordCtrl.isClicked && !wordCtrl.isFake) { ScoreCtrl.WordMiss(); } if (colliders.Contains(wordCtrl)) { colliders.Remove(wordCtrl); } } }
public WordGameObjectCtrl GetCollidingWord() { if (colliders.Count > 0) { for (int i = 0; i < colliders.Count; i++) { wgCtrl = colliders[i]; if (!wgCtrl.isClicked) { wgCtrl.isClicked = true; return(wgCtrl); } } return(null); } else { return(null); } }
void CheckTouches() { if (Input.touchCount < 1) { return; } foreach (Touch touch in Input.touches) { if (touch.phase == TouchPhase.Began) { RaycastHit2D hitInfo = Physics2D.Raycast(cam.ScreenToWorldPoint(touch.position), Vector2.zero); if (hitInfo) { GameObject recipient = hitInfo.transform.gameObject; if (recipient.tag == "ClickArea") { clickAreaCtrl = recipient.GetComponent <ClickAreaCtrl>(); wgCollidingCtrl = clickAreaCtrl.GetCollidingWord(); // returns a word if it is not clicked already if (wgCollidingCtrl != null) { RegisterWordHit(clickAreaCtrl, wgCollidingCtrl); if (wgCollidingCtrl.wordData.duration > 0.0) { clickAreaCtrl.StartHolding(touch.fingerId, (float)wgCollidingCtrl.wordData.duration, currentAudioTime); } } else { // empty click. kill streak //RegisterWordMiss(clickAreaCtrl); RegisterEmptyClick(); } } } } if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled) { foreach (ClickAreaCtrl caCtrl in clickAreas) { if (touch.fingerId == caCtrl.fingerIdDown) { //Debug.Log("STOP HOLDING " + caCtrl.gameObject.name + " fid =" +caCtrl.fingerIdDown+ " WITH FINGER ID "+ touch.fingerId); float timePressed = currentAudioTime - caCtrl.startHoldTime; //Debug.Log("HODING FOR : " + timePressed + " ["+caCtrl.durationToHold+"]"); caCtrl.fingerIdDown = 100; caCtrl.startHoldTime = 0; caCtrl.durationToHold = 0; caCtrl.StopParticles(); } } } if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Stationary) { foreach (ClickAreaCtrl caCtrl in clickAreas) { if (caCtrl.fingerIdDown != 100 && caCtrl.durationToHold != 0) { ScoreCtrl.AddHoldPoints(caCtrl.wordCtrl.hitTime, caCtrl.startHoldTime, caCtrl.durationToHold, currentAudioTime); } } } } }