// Update is called once per frame void Update() { Vector3 mousepos = InputWatcher.GetInputPosition(); //Debug.Log (touchDown); if (touchDown) { if (!buttonCheck) { //Debug.Log ("mouse down"); clickTime += Time.deltaTime; //Only allows the dial to spin if the player has been pressing for over a certain amount of time if (spinner && clickTime > clickDelay) { //Probably not the best for dealing with movement on both axis, //also will change code to touch controls once we start testing the game on mobile float angle = Mathf.Atan2(mousepos.y - transform.position.y, mousepos.x - transform.position.x); // (mousepos.y,mousepos.x); float degrees = (Mathf.Rad2Deg * angle); float origDegrees = Mathf.Rad2Deg * originalRot; transform.rotation = Quaternion.Euler(0, 0, (origz + (degrees - origDegrees) * rotScale) % 360); //transform.Rotate(0, 0, Input.GetAxis("Mouse Y") + Input.GetAxis("Mouse X")* multiplier, Space.World); } } } }
public void Update() { if (held) { if (!TouchIsOnMe(InputWatcher.GetInputPosition())) { //BuildDebugConsole.Flash("touch removed from me"); held = false; return; } if (t.TimeElapsedSecs() >= 0.2f) { //BuildDebugConsole.Flash("trying to tap"); held = false; GameEvent tapped = new GameEvent("template_tapped"); tapped.addArgument(this); tapped.addArgument(InputWatcher.GetInputPosition()); EventManager.Instance().RaiseEvent(tapped); Debug.Log("template tapped"); //BuildDebugConsole.Flash("template tapped"); } else { //BuildDebugConsole.Flash(GamePause.paused + "" +t.TimeElapsedSecs()); } } else { //BuildDebugConsole.Flash("not being held down"); } }
// Update is called once per frame void Update() { Vector3 mousepos = InputWatcher.GetInputPosition(); mousepos = new Vector3(mousepos.x - transform.position.x, mousepos.y - transform.position.y, mousepos.z); //Debug.Log (touchDown); if (touchDown) { //Debug.Log ("mouse down"); clickTime += Time.deltaTime; //Only allows the dial to spin if the player has been pressing for over a certain amount of time if (spinner && clickTime > clickDelay) { //Probably not the best for dealing with movement on both axis, //also will change code to touch controls once we start testing the game on mobile float angle = Mathf.Atan2(mousepos.y, mousepos.x); // (mousepos.y,mousepos.x); float degrees = (Mathf.Rad2Deg * angle); float origDegrees = Mathf.Rad2Deg * originalRot; transform.rotation = Quaternion.Euler(0, 0, (origz + (degrees - origDegrees) * rotScale) % 360); //Debug.Log (mousepos.x + ", " + mousepos.y); //Debug.Log ("origz: " + origz + " & degrees: " + degrees + " & origDegrees: " + origDegrees + "\n" +mousepos.x + ", " + mousepos.y); //Debug.Log ("euler: " + transform.rotation.eulerAngles.z); PieceController pc = EditorController.GetFloatingPiece(); if (pc != null) { pc.transform.rotation = transform.rotation; } } } }
public void Update() { if (moving && !externalMovement) { Vector3 inputPos = InputWatcher.GetInputPosition(); transform.position = inputPos - dragPoint; transform.position = new Vector3(transform.position.x, transform.position.y, -1.0f); } }
public void HandleEvent(GameEvent ge) { Vector3 mousepos = InputWatcher.GetInputPosition(); if (ge.type.Equals("mouse_release")) { if (!buttonCheck) { //Stops the dial from spinning more //Only tries to lock if the spinner has a chance of moving if (clickTime > clickDelay) { //Locks position to nearest interval of 60 float rotation = transform.eulerAngles.z; float lockRot = Mathf.Round(rotation / 60) * 60; transform.rotation = Quaternion.Euler(0, 0, lockRot); } } //resets time clickTime = 0; touchDown = false; spinner = false; buttonCheck = false; } else if (ge.type.Equals("mouse_click")) { //Allows the dial to start spinning RaycastHit targetFind; Ray targetSeek = Camera.main.ScreenPointToRay(InputWatcher.GetTouchPosition()); if (Physics.Raycast(targetSeek, out targetFind)) { //sees if ray collided with the start button if (targetFind.collider.gameObject.tag == "Button") { buttonCheck = true; } } if (spinner == false) { originalRot = Mathf.Atan2(mousepos.y, mousepos.x); origz = transform.eulerAngles.z; //Debug.Log ("new original degrees: " + originalRot); } spinner = true; touchDown = true; } }
public void AttachEntry(EnemyListEntryController elec) { moving = true; GameObject go = Instantiate(Resources.Load("Prefabs/EnemyListEntry")) as GameObject; go.transform.SetParent(canvas.transform, false); EnemyListEntryController nelec = go.GetComponent <EnemyListEntryController>(); nelec.ConfigureFromTemplate(elec.GetEnemyTemplate()); floatingEntry = nelec; floatingEntry.floating = true; Vector3 inputPos = InputWatcher.GetInputPosition(); floatingEntry.transform.position = new Vector3(inputPos.x, inputPos.y, -1.0f); }
public void Update() { if (beingHeld) { if (!TouchIsOnMe(InputWatcher.GetInputPosition())) { beingHeld = false; return; } if (holdTimer.TimeElapsedMillis() > 120) { beingHeld = false; WaveEditorController.singleton.AttachEnemy(this); } } }
public void Update() { if (moving) { Vector3 inputPos = InputWatcher.GetInputPosition(); transform.position = inputPos - dragPoint; transform.position = new Vector3(transform.position.x, transform.position.y, -1.0f); /*RectTransform rt = (RectTransform)transform; * Vector3 eulerSave = rt.eulerAngles; * rt.eulerAngles = new Vector3(0f,0f,0f); * boundsmin = rt.TransformPoint(rt.rect.min); * boundsmax = rt.TransformPoint(rt.rect.max); * rt.eulerAngles = eulerSave;*/ } }
public void HandleEvent(GameEvent ge) { Vector3 mousepos = InputWatcher.GetInputPosition(); if (ge.type.Equals("mouse_release")) { //Stops the dial from spinning more spinner = false; //Only tries to lock if the spinner has a chance of moving if (clickTime > clickDelay) { //Locks position to nearest interval of 60 float rotation = transform.eulerAngles.z; float lockRot = Mathf.Round(rotation / 90.0f) * 90; transform.rotation = Quaternion.Euler(0, 0, lockRot); PieceController pc = EditorController.GetFloatingPiece(); if (pc != null) { pc.SetRotation(360 - transform.rotation.eulerAngles.z); } } //resets time clickTime = 0; touchDown = false; } else if (ge.type.Equals("mouse_click")) { //Allows the dial to start spinning if (spinner == false) { float dist = Mathf.Sqrt(((mousepos.x - transform.position.x) * (mousepos.x - transform.position.x)) + ((mousepos.y - transform.position.y) * (mousepos.y - transform.position.y))); if (dist > radius) { return; } originalRot = Mathf.Atan2(mousepos.y - transform.position.y, mousepos.x - transform.position.x); origz = transform.eulerAngles.z; //Debug.Log ("new original degrees: " + originalRot); } spinner = true; touchDown = true; } }
public void Update() { if (!gridloaded) { gridloaded = true; GameObject loader = GameObject.Find("NameHolder"); LoadTower(loader.GetComponent <TowerLoad> ().towerName); Destroy(loader); } if (frameDelay > 0) { frameDelay--; if (frameDelay <= 0) { clearCheckPanel.SetActive(false); } } if (floatingPiece != null && floatingPiece.IsMoving()) { if (sr.vertical) { sr.vertical = false; } } else { if (!sr.vertical) { sr.vertical = true; } } if (finger2down && finger1down) { Vector3 altClickPos = InputWatcher.GetInputPosition(1); Vector3 firstClickPos = InputWatcher.GetInputPosition(); Vector3 direction = altClickPos - firstClickPos; float newAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; float diff = newAngle - twoFingerAngle; floatingPiece.transform.eulerAngles = new Vector3(0, 0, pieceAngle + diff); } }
public void HandleEvent(GameEvent ge) { Vector3 mousepos = InputWatcher.GetInputPosition(); mousepos = new Vector3(mousepos.x - spinPivot.transform.position.x, mousepos.y - spinPivot.transform.position.y, mousepos.z); if (ge.type.Equals("mouse_release")) { //Stops the dial from spinning more spinner = false; //Only tries to lock if the spinner has a chance of moving if (clickTime > clickDelay) { //Locks position to nearest interval of 60 float rotation = transform.eulerAngles.z; float lockRot = Mathf.Round(rotation / lockThreshold) * lockThreshold; transform.rotation = Quaternion.Euler(0, 0, lockRot); menuPosition = (int)lockRot / lockThreshold; if (Child.GetComponent <MenuClickScript>() != null) { Child.GetComponent <MenuClickScript>().menuPosition = menuPosition % menuMax; } /*if(Child.GetComponent<MenuInGame>() != null){ * Child.GetComponent<MenuInGame>().menuPosition = (menuPosition % menuMax) % 4; * }*/ } //resets time clickTime = 0; touchDown = false; } else if (ge.type.Equals("mouse_click")) { //Allows the dial to start spinning if (spinner == false) { originalRot = Mathf.Atan2(mousepos.y, mousepos.x); origz = transform.eulerAngles.z; //Debug.Log ("new original degrees: " + originalRot); } spinner = true; touchDown = true; } }
public void Update() { if (held) { if (!TouchIsOnMe(InputWatcher.GetInputPosition())) { held = false; return; } if (t.TimeElapsedSecs() >= 0.4f) { held = false; GameEvent tapped = new GameEvent("template_tapped"); tapped.addArgument(this); tapped.addArgument(InputWatcher.GetInputPosition()); EventManager.Instance().RaiseEvent(tapped); } } }
public void Update() { if (WaveEditorController.singleton.IsMoving()) { if (!glowIsOn && TouchIsOnMe(InputWatcher.GetInputPosition())) { glowIsOn = true; glow.SetActive(glowIsOn); } if (glowIsOn && !TouchIsOnMe(InputWatcher.GetInputPosition())) { glowIsOn = false; glow.SetActive(glowIsOn); } } else { glowIsOn = false; glow.SetActive(glowIsOn); } }
public void Update() { Vector3 inputPos = InputWatcher.GetInputPosition(); transform.position = new Vector3(inputPos.x, inputPos.y, -1.0f); }
public void Update() { if (eventWaiting) //this waiting stuff is to make sure nothing else is grabbing the player's input before starting on the drag { clickUpdateCycled = true; eventWaiting = false; } else if (clickUpdateCycled) //now we can handle the event { if (!WaveEditorController.singleton.IsMoving()) { if (BossTabController.open) { return; } //go into drag mode dragging = true; RectTransform rt = (RectTransform)leveltrack.transform; initialTrackPos = rt.anchoredPosition.x; Vector3 touchpos = (Vector3)heldEvent.args[0]; //RectTransform canvas = (RectTransform)WaveEditorController.singleton.canvas.transform; Vector3 newpoint = canvas.InverseTransformPoint(new Vector2(touchpos.x, touchpos.y)); initialTouchPos = newpoint.x; } clickUpdateCycled = false; } if (WaveEditorController.singleton.activeWaveFrame != this) { return; //don't do it all over again } if (dragging && snapping) { Debug.Log("NO DRAGGING AND SNAPPING AT THE SAME TIME"); } if (dragging) { //Debug.Log ("dragging"); RectTransform rt = (RectTransform)leveltrack.transform; Vector3 touchpos = InputWatcher.GetInputPosition(); //RectTransform canvas = (RectTransform)WaveEditorController.singleton.canvas.transform; Vector3 newpoint = canvas.InverseTransformPoint(new Vector2(touchpos.x, touchpos.y)); float x = newpoint.x - initialTouchPos; if (initialTrackPos + x > trackbounds) { rt.anchoredPosition = new Vector2(trackbounds, rt.anchoredPosition.y); } else if (initialTrackPos + x < -trackbounds) { rt.anchoredPosition = new Vector2(-trackbounds, rt.anchoredPosition.y); } else { rt.anchoredPosition = new Vector2(initialTrackPos + x, rt.anchoredPosition.y); } } if (snapping) { //Debug.Log ("snapping"); RectTransform rt = (RectTransform)leveltrack.transform; float trackPos = rt.anchoredPosition.x; float distance = snapTarget - trackPos; //distance should always be 412.5 > x > -412.5 //Debug.Log(distance); if (distance > 0) { if (Mathf.Abs(distance) > 200) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 10, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 80) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 9, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 40) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 8, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 20) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 6, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 2.1) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x + 4, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) < 2.1) { rt.anchoredPosition = new Vector2(snapTarget, rt.anchoredPosition.y); snapping = false; } } else { if (Mathf.Abs(distance) > 200) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 10, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 80) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 9, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 40) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 8, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 20) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 6, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) > 2.1) { rt.anchoredPosition = new Vector2(rt.anchoredPosition.x - 4, rt.anchoredPosition.y); } else if (Mathf.Abs(distance) < 2.1) { rt.anchoredPosition = new Vector2(snapTarget, rt.anchoredPosition.y); snapping = false; } } } }
public void HandleEvent(GameEvent ge) { if (BossTabController.open) { return; } if (WaveEditorController.singleton.panelOpen) { return; } if (ge.type.Equals("mouse_click")) { if (snapping || dragging) { return; } canvas = (RectTransform)WaveEditorController.singleton.canvas.transform; RectTransform rt = (RectTransform)transform; Vector3 touchpos = (Vector3)ge.args[0]; Vector3 newpoint = rt.InverseTransformPoint(new Vector2(touchpos.x, touchpos.y)); if (!rt.rect.Contains(new Vector2(newpoint.x, newpoint.y))) { //Debug.Log ("click not on thing"); return; } else { //Debug.Log ("a frame thought it was being clicked"); } eventWaiting = true; heldEvent = ge; } else //it's a mouse release event { if (!dragging) { return; } dragging = false; snapping = true; //Debug.Log("we decided to snap"); //decide which to snap to //swipe distance based float movementThreshold = 200f; Vector3 touchpos = InputWatcher.GetInputPosition(); Vector3 newpoint = canvas.InverseTransformPoint(new Vector2(touchpos.x, touchpos.y)); float distance = newpoint.x - initialTouchPos; if (distance > movementThreshold) { //Debug.Log ("old snap index: " + snapIndex); snapIndex--; //Debug.Log ("new snap index: " + snapIndex); if (snapIndex < 0) { //Debug.Log ("snap index is " + snapIndex + " which is under 0. setting to " + 0); snapIndex = 0; } } else if (distance < -movementThreshold) { //Debug.Log ("old snap index: " + snapIndex); snapIndex++; //Debug.Log ("new snap index: " + snapIndex); if (snapIndex >= thresholds.Length + 1) { //Debug.Log ("snap index is " + snapIndex + " which is over five. setting to " + thresholds.Length); snapIndex = thresholds.Length; } } //absolute position based /*RectTransform rt = (RectTransform)leveltrack.transform; * float trackPos = rt.anchoredPosition.x; * snapIndex = 0; * for(int i = 0; i < thresholds.Length; i++){ * if(trackPos < thresholds[i]){ * snapIndex++; * }else{ * break; * } * }*/ //snapIndex is now the index of the frame to snap to WaveEditorController.singleton.SetActiveFrame(snapIndex); if (snapIndex == 0) { snapTarget = trackbounds; } else { snapTarget = thresholds[snapIndex - 1] - 387.5f; } } }
public void HandleEvent(GameEvent ge) { if (ge.type.Equals("piece_tapped")) { PieceController tappedPiece = (PieceController)ge.args[0]; if (tappedPiece.GetGridLock()) { if (floatingPiece != null) { bool success = grid.TryAddPiece(floatingPiece); if (success) { floatingPiece.SetGridLock(true); floatingPiece = null; } } Activate(tappedPiece); } else { bool success = grid.TryAddPiece(tappedPiece); if (success) { tappedPiece.SetGridLock(true); floatingPiece = null; } } } else if (ge.type.Equals("piece_dropped_on_inventory")) { PieceController piece = (PieceController)ge.args[0]; InventoryAdd(piece); } else if (ge.type.Equals("template_tapped")) { PieceTemplateController tappedPiece = (PieceTemplateController)ge.args[0]; Vector3 loc = (Vector3)ge.args[1]; if (floatingPiece != null) { bool success = grid.TryAddPiece(floatingPiece); if (success) { floatingPiece.SetGridLock(true); floatingPiece = null; } } GameObject go = Instantiate(Resources.Load("Prefabs/ExistingPiece")) as GameObject; go.transform.SetParent(canvas.transform, false); go.transform.position = new Vector3(loc.x, loc.y, go.transform.position.z); PieceController newPiece = go.GetComponent <PieceController>(); newPiece.ConfigureFromJSON(tappedPiece.GetFilename()); newPiece.SetRotation(0); newPiece.SetMoving(true); Activate(newPiece); iwc.RemovePiece(newPiece); //tappedPiece.SetCount(tappedPiece.GetCount()-1); } else if (ge.type.Equals("alt_click")) { if (floatingPiece == null) { return; } if (!finger1down) { return; } Vector3 altClickPos = (Vector3)ge.args[0]; //check if the second click is on one of the rotate buttons float ymax = rotCounterclockwise.rect.y + (rotCounterclockwise.rect.height / 2f); float xmax = rotCounterclockwise.rect.x + (rotCounterclockwise.rect.width / 2f); if (altClickPos.x < xmax && altClickPos.y < ymax) //then you're on the buttons { return; } Vector3 firstClickPos = InputWatcher.GetInputPosition(); Vector3 direction = altClickPos - firstClickPos; twoFingerAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; pieceAngle = floatingPiece.transform.eulerAngles.z; floatingPiece.SetTwoFingerMovement(true); finger2down = true; } else if (ge.type.Equals("alt_release")) { Debug.Log("alt release happened"); if (floatingPiece == null) { return; } if (!finger2down) { return; } if (waitingForOtherFingerToReset) { floatingPiece.SetTwoFingerMovement(false); waitingForOtherFingerToReset = false; } else { waitingForOtherFingerToReset = true; floatingPiece.LockRotation(); } finger2down = false; } else if (ge.type.Equals("mouse_click")) { Vector3 pos = (Vector3)ge.args[0]; if (grid.TouchIsOnMe(pos)) { finger1down = true; } } else if (ge.type.Equals("mouse_release")) { if (floatingPiece == null) { return; } if (waitingForOtherFingerToReset) { floatingPiece.SetTwoFingerMovement(false); waitingForOtherFingerToReset = false; } else { waitingForOtherFingerToReset = true; floatingPiece.LockRotation(); } finger1down = false; } }
public void HandleEvent(GameEvent ge) { Vector3 mousepos = InputWatcher.GetInputPosition(); if (ge.type.Equals("mouse_release")) { if (altspinning) { return; } //Stops the dial from spinning more spinner = false; //Only tries to lock if the spinner has a chance of moving if (clickTime > clickDelay) { //Locks position to nearest interval of 60 LockRotation(); } //resets time clickTime = 0; touchDown = false; } else if (ge.type.Equals("mouse_click")) { if (altspinning) { return; } //Allows the dial to start spinning if (spinner == false) { float dist = Mathf.Sqrt(((mousepos.x - transform.position.x) * (mousepos.x - transform.position.x)) + ((mousepos.y - transform.position.y) * (mousepos.y - transform.position.y))); if (dist > radius) { return; } originalRot = Mathf.Atan2(mousepos.y - transform.position.y, mousepos.x - transform.position.x); origz = transform.eulerAngles.z; //Debug.Log ("new original degrees: " + originalRot); } spinner = true; touchDown = true; } else if (ge.type.Equals("alt_click")) { mousepos = InputWatcher.GetInputPosition(1); if (spinner) { return; } if ((int)ge.args[1] != 1) //second finger only { return; } if (altspinning == false) { float dist = Mathf.Sqrt(((mousepos.x - transform.position.x) * (mousepos.x - transform.position.x)) + ((mousepos.y - transform.position.y) * (mousepos.y - transform.position.y))); if (dist > radius) { return; } originalRot = Mathf.Atan2(mousepos.y - transform.position.y, mousepos.x - transform.position.x); origz = transform.eulerAngles.z; //Debug.Log ("new original degrees: " + originalRot); } altspinning = true; touchDown = true; } else if (ge.type.Equals("alt_release")) { mousepos = InputWatcher.GetInputPosition(1); if (spinner) { return; } if ((int)ge.args[1] != 1) //second finger only { return; } //Stops the dial from spinning more altspinning = false; //Only tries to lock if the spinner has a chance of moving if (clickTime > clickDelay) { //Locks position to nearest interval of 90 LockRotation(); } //resets time clickTime = 0; touchDown = false; } }