void spellSelected(SpellSelectedEvent selectedSpell) { Debug.Log("UI canvas spell selected"); if (selectedSpell.selected) { //if (selectedSpell.spell.spellType == TempSpell.SpellType.PROJECTILE) //{ this.selectedSpell = selectedSpell.spell.spell; //} } else { this.selectedSpell = null; clearTexture(UITexture); TextureHelper.ApplyTexture(UITexture, SpriteRenderer, new Vector2(0.5f, 0.5f)); } }
// Update is called once per frame void Update() { //TODO: move this to an interaction controller or something, it doesnt need to be here, but it will do for now if (selectedSpell != null) { if (UITexture == null) { Camera cam = Camera.main; double height = (Camera.main.orthographicSize * 2.0); double width = height * Screen.width / Screen.height; UITexture = TextureHelper.MakeTexture((int)width, (int)height, Color.clear); UITexture.filterMode = FilterMode.Point; UITexture.wrapMode = TextureWrapMode.Clamp; SpriteRenderer = GetComponent <SpriteRenderer>(); //DrawLine(UITexture, 0, 0, UITexture.width, UITexture.height, Color.black); TextureHelper.ApplyTexture(UITexture, SpriteRenderer, new Vector2(0.5f, 0.5f)); } Vector2 mousePosition = Input.mousePosition; Vector2 endPoint = mousePosition; endPoint.x /= 3f; endPoint.y /= 3f; if ((int)endPoint.x != lastX || (int)endPoint.y != lastY) { lastX = (int)endPoint.x; lastY = (int)endPoint.y; Vector2 middleScreen; if (castingLocation == Vector2.negativeInfinity) { middleScreen = new Vector2(UITexture.width / 2, UITexture.height / 2); } else { middleScreen = Camera.main.WorldToScreenPoint(castingLocation) / 3f; } //middleScreen = new Vector2(UITexture.width / 2, UITexture.height / 2); float angle = GetAngle(middleScreen, endPoint); //TODO: fix this, just trying to get seperate casting circle to work //List<Vector2> pixelList = castingUI.getPixelList(); //Vector2 startPoint = pixelList[(int)((angle / 360) * pixelList.Count)] + middleScreen; //startPoint.x -= castingUI.GetHalfWidth(); //startPoint.y -= castingUI.GetHalfHeight(); Vector2 direction = (endPoint - middleScreen); Vector2 startPoint = middleScreen; if (fixedLineLength && direction.magnitude > lineLength) { endPoint = startPoint + (direction.normalized * lineLength); } //(direction.normalized * radius) + middleScreen; DrawLine(UITexture, (int)startPoint.x, (int)startPoint.y, (int)endPoint.x, (int)endPoint.y, selectedSpell.color); } } }