public static bool TryGrab(Enum _enum, out GameObject _gameObject, bool returnActive = true) { _gameObject = null; if (!_enumDict.TryGetValue(_enum, out _bin)) { return(false); } if (!_bin.Grab(out _gameObject)) { return(false); } if (returnActive) { _gameObject.SetActive(true); } return(true); }
IEnumerator ZoomTo() { while (zoomz) { // print(start); if (FullSreenEffect.color.a < 0.5f) { FullSreenEffect.color += new Color(0, 0, 0, 0.05f); } if (!IsPointerOverUIObject() && Input.touchCount > 0) { // print( "not touching UI "); Touch touch = Input.GetTouch(0); touchPosition = Camera.main.ScreenToWorldPoint(touch.position); Vector2 touchPos = new Vector2(touchPosition.x, touchPosition.y); tp = touchPos; if (touch.phase == TouchPhase.Began) { Vector2 dir = touchPos - oldtouch; GameObject lineclone; if (linebin.Grab(out lineclone)) { lineclone.transform.position = oldtouch; lineclone.transform.rotation = Quaternion.Euler(dir); lineclone.SetActive(true); } else { lineclone = Instantiate(linearprojection, oldtouch, Quaternion.Euler(dir)); } curLine = lineclone; start = false; fingerup = false; } if (fingerup) { Vector2 dir = touchPos - oldtouch; GameObject lineclone; if (linebin.Grab(out lineclone)) { lineclone.transform.position = oldtouch; lineclone.transform.rotation = Quaternion.Euler(dir); lineclone.SetActive(true); } else { lineclone = Instantiate(linearprojection, oldtouch, Quaternion.Euler(dir)); } curLine = lineclone; start = false; fingerup = false; } if (!IsPointerOverUIObject()) { Ray2D ray = new Ray2D(oldtouch, touchPos - oldtouch); float dist = Vector2.Distance(oldtouch, touchPos); Vector2 dir = touchPos - oldtouch;// new Vector2(touchPos.x - transform.position.x , touchPos.y- transform.position.y ); layerMask = (1 << 13); RaycastHit2D hit = Physics2D.Raycast(oldtouch, dir, dist, layerMask); float angle = (Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg) - 90f; curLine.transform.rotation = Quaternion.Euler(0, 0, angle); curLine.GetComponent <SpriteRenderer>().size = new Vector2(18.38f, dist * 30f); if (hit.collider != null)//.tag == "wall" || hit.collider.tag == "spikeyWall") { curLine.GetComponent <SpriteRenderer>().color = new Color(1, 0, 0.009137154f); Vector2 dir2 = new Vector2(hit.collider.transform.position.x, hit.collider.transform.position.y) - hit.point; // print(hit.collider.tag); Debug.DrawRay(oldtouch, dir2, Color.red); Debug.DrawRay(oldtouch, dir, Color.green); clearPath = false; } else { curLine.GetComponent <SpriteRenderer>().color = new Color(1, 1, 1); clearPath = true; Debug.DrawRay(oldtouch, dir, Color.blue); } } if (touch.phase == TouchPhase.Ended) { // print(count + " " + stack); if (clearPath) { zoomqueue.Enqueue(touchPos); count++; if (zoomqueue.Count >= stack) { startTime = Time.time; journeyLength = Vector2.Distance(transform.position, touchPosition); Vector2 dirr = new Vector2(transform.position.x, transform.position.y) - new Vector2(touchPosition.x, touchPosition.y); start = true; } oldtouch = touchPos; } else { linebin.Store(curLine); } fingerup = true; yield return(new WaitForEndOfFrame()); } } if (Input.touchCount == 0) { if (fingerup == false) { if (clearPath) { zoomqueue.Enqueue(tp); count++; if (zoomqueue.Count >= stack) { startTime = Time.time; journeyLength = Vector2.Distance(transform.position, touchPosition); Vector2 dirr = new Vector2(transform.position.x, transform.position.y) - new Vector2(touchPosition.x, touchPosition.y); start = true; } oldtouch = tp; } else { linebin.Store(curLine); } fingerup = true; yield return(new WaitForEndOfFrame()); } } if (start) { if (FullSreenEffect.color.a >= 0.0f) { FullSreenEffect.color -= new Color(0, 0, 0, 0.01f); } else { FullSreenEffect.gameObject.SetActive(false); } float distCovered = (Time.time - startTime) * 20; float fracJourney = distCovered / journeyLength; transform.position = Vector2.Lerp(transform.position, zoomqueue.Peek(), fracJourney); //print(fracJourney); if (fracJourney >= 1) { zoomqueue.Dequeue(); if (zoomqueue.Count == 0) { foreach (GameObject line in GameObject.FindGameObjectsWithTag("line")) { linebin.Store(line); } count = 0; zoomz = false; FullSreenEffect.gameObject.SetActive(false); start = false; zoomqueue.Clear(); stack = 0; yield break; } else { startTime = Time.time; journeyLength = Vector2.Distance(transform.position, zoomqueue.Peek()); } } } yield return(new WaitForFixedUpdate()); } }