Example #1
0
 public override void RemoveIndicator(Transform target)
 {
     if (ExistsIndicator(target))
     {
         ArrowIndicator oldArrowTarget = arrowIndicators.Find(x => x.target == target);
         int            id             = arrowIndicators.FindIndex(x => x.target == target);
         arrowIndicators.RemoveAt(id);
         GameObject.Destroy(oldArrowTarget.arrow);
         ArrowIndicator.Destroy(oldArrowTarget);
     }
     else
     {
         Debug.LogWarning("Target no longer exists: " + target.name);
     }
 }
Example #2
0
        protected override void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, int id = 0)
        {
            Vector3 v2DPos = Camera.main.WorldToScreenPoint(arrowIndicator.target.localPosition + arrowIndicator.indicator.targetOffset);
            float   angle;
            bool    behindCamera;

            Vector3 heading = arrowIndicator.target.position - Camera.main.transform.position;

            behindCamera = (Vector3.Dot(Camera.main.transform.forward, heading) < 0);

            if (v2DPos.x > Screen.width - realBorder || v2DPos.x < realBorder || v2DPos.y > Screen.height - realBorder || v2DPos.y < realBorder || behindCamera)
            {
                //Debug.Log ("OUT OF SCREEN");
                arrowIndicator.onScreen = false;
                //Cut position on the sides
                angle = Mathf.Atan2(v2DPos.y - (Screen.height / 2), v2DPos.x - (Screen.width / 2));
                float xCut, yCut;
                if (v2DPos.x - Screen.width / 2 > 0)
                {
                    //Right side
                    xCut = Screen.width / 2 - realBorder;
                    yCut = xCut * Mathf.Tan(angle);
                }
                else
                {
                    //Left side
                    xCut = -Screen.width / 2 + realBorder;
                    yCut = xCut * Mathf.Tan(angle);
                }
                //Check cut position up and down
                if (yCut > Screen.height / 2 - realBorder)
                {
                    //Up
                    yCut = Screen.height / 2 - realBorder;
                    xCut = yCut / Mathf.Tan(angle);
                }
                if (yCut < -Screen.height / 2 + realBorder)
                {
                    //Down
                    yCut = -Screen.height / 2 + realBorder;
                    xCut = yCut / Mathf.Tan(angle);
                }
                if (behindCamera)
                {
                    xCut = -xCut;
                    yCut = -yCut;
                }
                if (screenScaled)
                {
                    xCut /= screenScaleX;
                    yCut /= screenScaleY;
                }
                arrowIndicator.arrow.transform.localPosition = new Vector3(xCut, yCut, 0);
            }
            else
            {
                //Debug.Log ("INSIDE OF SCREEN");
                arrowIndicator.onScreen = true;
                float xScaled = v2DPos.x - (Screen.width / 2);
                float yScaled = v2DPos.y - (Screen.height / 2);
                if (screenScaled)
                {
                    xScaled /= screenScaleX;
                    yScaled /= screenScaleY;
                }
                arrowIndicator.arrow.transform.localPosition = new Vector3(xScaled, yScaled, 0);
            }

            //rotatearrow
            if ((arrowIndicator.onScreen && arrowIndicator.indicator.onScreenRotates) || (!arrowIndicator.onScreen && arrowIndicator.indicator.offScreenRotates))
            {
                if (behindCamera)
                {
                    angle = Mathf.Atan2(-(v2DPos.y - (Screen.height / 2)), -(v2DPos.x - (Screen.width / 2)));
                }
                else
                {
                    angle = Mathf.Atan2(v2DPos.y - (Screen.height / 2), v2DPos.x - (Screen.width / 2));
                }
            }
            else
            {
                angle = 90 * Mathf.Deg2Rad;
            }
            arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);
        }
Example #3
0
 protected abstract void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, int id = 0);