Exemplo n.º 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);
       *         }*/
 }
        //public void AddInfoText(Transform target, Transform indicator, string _eye)
        //{
        //    switch (_eye)
        //    {
        //        case "LeftEye":
        //            GameObject cl = Instantiate(CanvasL, indicator);
        //            cl.transform.localPosition = Vector3.zero;
        //            cl.GetComponent<TextUIName>().GetName(target.name);
        //            break;
        //            //return;
        //        case "RightEye":
        //            GameObject cr = Instantiate(CanvasR, indicator);
        //            cr.transform.localPosition = Vector3.zero;
        //            cr.GetComponent<TextUIName>().GetName(target.name);
        //            break;
        //    }
        //    //(GameObject)Instantiate()
        //}



        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);
            }



            //throw new System.NotImplementedException();
        }
 protected abstract void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, float multiplr, int id = 0);
Exemplo n.º 4
0
        protected override void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, int id = 0)
        {
            Vector3 pCam   = Camera.main.transform.position;
            Vector3 pPlane = indicatorsParentObj.transform.position;
            //change pPlane according to Z of arrow
            Ray zRay = new Ray(pPlane, pCam - pPlane);

            pPlane = zRay.GetPoint(-0.001f * id);
            //plane to draw things
            Plane plane = new Plane(Vector3.Normalize(pCam - pPlane), pPlane);

            //raycast line to target
            if (HiddenGameManager.Instance.catHide || HiddenGameManager.Instance.holdVG)
            {                                          ////////////////If the target is NULL
                arrowIndicator.arrow.SetActive(false); //Hide the Arrow
            }



            else
            {                                         /////////////If the target is there
                arrowIndicator.arrow.SetActive(true); //Show the arrow
                Vector3 pTarget   = arrowIndicator.target.transform.position + arrowIndicator.indicator.targetOffset;
                Ray     rToTarget = new Ray(pCam, pTarget - pCam);
                Vector3 hitPoint; //Point in plane where target hits raycasting camera.
                float   distance;
                if (plane.Raycast(rToTarget, out distance))
                {
                    hitPoint = rToTarget.GetPoint(distance);
                    if (Vector3.Distance(pPlane, hitPoint) > radius)
                    {
                        //offscreen
                        arrowIndicator.onScreen = false;
                        Ray rToArrow = new Ray(pPlane, hitPoint - pPlane); //create a ray pointing to the hitPoint
                        if (degreeRestirct)
                        {                                                  ////////if the toggle from Angle control is on - Yebai
                            Vector3 targetDir = Camera.main.transform.TransformDirection(Vector3.up);
                            targetDir = Vector3.ProjectOnPlane(targetDir, plane.normal);
                            float controlledAngle = Vector3.SignedAngle(rToArrow.direction, targetDir, pPlane - pCam);
                            Debug.Log(controlledAngle);
                            arrowIndicator.arrow.transform.position = rToArrow.GetPoint(radius);
                        }
                        else
                        {////Do the normal thing - Yebai
                            arrowIndicator.arrow.transform.position = rToArrow.GetPoint(radius);
                        }
                    }
                    else
                    {
                        //inscreen
                        arrowIndicator.onScreen = true;
                        arrowIndicator.arrow.transform.position = hitPoint;
                    }
                    //We do angle stuff in local space *GLOBAL SPACE
                    Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                    Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                    // plPlane local pos is 0,0 but maybe we move the plane?
                    //Apply Head rotation angle
                    float angle = (90 - Camera.main.transform.localEulerAngles.z) * Mathf.Deg2Rad;

                    if ((arrowIndicator.onScreen && arrowIndicator.indicator.onScreenRotates) || (!arrowIndicator.onScreen && arrowIndicator.indicator.offScreenRotates))
                    {
                        angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                    }
                    arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);

                    //Debug some lines
                    if (enableDebug)
                    {
                        Utils.DrawPlane(Vector3.Normalize(pCam - pPlane), pPlane, radius);
                        Debug.DrawRay(rToTarget.origin, rToTarget.direction);
                        Debug.DrawLine(pCam, hitPoint, Color.white);
                        Debug.DrawLine(hitPoint, pPlane, Color.magenta);
                    }
                }
                else
                {
                    rToTarget = new Ray(pTarget, pCam - pTarget);
                    if (plane.Raycast(rToTarget, out distance))
                    {
                        hitPoint = rToTarget.GetPoint(distance);
                        Ray rToArrow = new Ray(pPlane, hitPoint - pPlane);
                        arrowIndicator.arrow.transform.position = rToArrow.GetPoint(-radius);
                        arrowIndicator.onScreen = false;

                        Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                        Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                        float   angle      = (90 - Camera.main.transform.localEulerAngles.z) * Mathf.Deg2Rad;
                        if (arrowIndicator.indicator.offScreenRotates)
                        {
                            angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                        }
                        arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);
                    }
                    else
                    {
                        //target-cast is parallel to the plane, using the last indicator position is fine.
                    }
                }
            }
        }
        protected override void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, int id = 0)
        {
            Vector3 pCam   = Camera.main.transform.position;
            Vector3 pPlane = indicatorsParentObj.transform.position;
            //change pPlane according to Z of arrow
            Ray zRay = new Ray(pPlane, pCam - pPlane);

            pPlane = zRay.GetPoint(-0.001f * id);
            //plane to draw things
            Plane plane = new Plane(Vector3.Normalize(pCam - pPlane), pPlane);
            //raycast line to target

            Vector3 pTarget   = arrowIndicator.target.transform.position + arrowIndicator.indicator.targetOffset;
            Ray     rToTarget = new Ray(pCam, pTarget - pCam);
            Vector3 hitPoint;             //Point in plane where target hits raycasting camera.
            float   distance;

            if (plane.Raycast(rToTarget, out distance))
            {
                hitPoint = rToTarget.GetPoint(distance);
                if (Vector3.Distance(pPlane, hitPoint) > radius)
                {
                    //offscreen
                    arrowIndicator.onScreen = false;
                    Ray rToArrow = new Ray(pPlane, hitPoint - pPlane);
                    arrowIndicator.arrow.transform.position = rToArrow.GetPoint(radius);
                }
                else
                {
                    //inscreen
                    arrowIndicator.onScreen = true;
                    arrowIndicator.arrow.transform.position = hitPoint;
                }
                //We do angle stuff in local space *GLOBAL SPACE
                Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                // plPlane local pos is 0,0 but maybe we move the plane?
                //Apply Head rotation angle
                float angle = (90 - Camera.main.transform.localEulerAngles.z) * Mathf.Deg2Rad;

                if ((arrowIndicator.onScreen && arrowIndicator.indicator.onScreenRotates) || (!arrowIndicator.onScreen && arrowIndicator.indicator.offScreenRotates))
                {
                    angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                }
                arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);

                //Debug some lines
                if (enableDebug)
                {
                    Utils.DrawPlane(Vector3.Normalize(pCam - pPlane), pPlane, radius);
                    Debug.DrawRay(rToTarget.origin, rToTarget.direction);
                    Debug.DrawLine(pCam, hitPoint, Color.white);
                    Debug.DrawLine(hitPoint, pPlane, Color.magenta);
                }
            }
            else
            {
                rToTarget = new Ray(pTarget, pCam - pTarget);
                if (plane.Raycast(rToTarget, out distance))
                {
                    hitPoint = rToTarget.GetPoint(distance);
                    Ray rToArrow = new Ray(pPlane, hitPoint - pPlane);
                    arrowIndicator.arrow.transform.position = rToArrow.GetPoint(-radius);
                    arrowIndicator.onScreen = false;

                    Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                    Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                    float   angle      = (90 - Camera.main.transform.localEulerAngles.z) * Mathf.Deg2Rad;
                    if (arrowIndicator.indicator.offScreenRotates)
                    {
                        angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                    }
                    arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);
                }
                else
                {
                    //target-cast is parallel to the plane, using the last indicator position is fine.
                }
            }
        }
Exemplo n.º 6
0
        protected override void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, float multiplr, 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);
        }
        //public override void AddInfo(ArrowIndicatorVRDoubleEyes arrowIndicatorsVRDoubleEyes, Transform target, Transform parentFrame, int infoID, string eye)
        //{
        //    if (infoID >= targetInfos.Length)
        //    {
        //        Debug.LogError("TargetInfo ID not valid. Check Off Screen Indicator TargetInfo list.");
        //        return;
        //    }



        //    //if (!ExistsIndicator(target))
        //    //{
        //    //    ArrowIndicatorVRDoubleEyes newArrowIndicator = new ArrowIndicatorVRDoubleEyes();
        //    //    newArrowIndicator.target = target;
        //    //    //newArrowIndicator.indicator = indicators[indicatorID];
        //    //    newArrowIndicator.indicatorID = indicatorID;
        //    //    //Debug.Log(newArrowIndicator.indicator.targetOffset);
        //    //    newArrowIndicator.arrow = new GameObject();
        //    //    newArrowIndicator.arrow.transform.SetParent(indicatorsParentObj.transform);
        //    //    newArrowIndicator.arrow.name = "indicator" + target.name;
        //    //    newArrowIndicator.VR_scale = new Vector3(indicatorScale, indicatorScale, indicatorScale);
        //    //    newArrowIndicator.arrow.transform.localScale = newArrowIndicator.VR_scale;

        //    //    newArrowIndicator.arrow.layer = LayerMask.NameToLayer(eye);

        //    //    //newArrowIndicator.arrow.layer=
        //    //    newArrowIndicator.arrow.AddComponent<SpriteRenderer>();
        //    //    newArrowIndicator.arrow.GetComponent<SpriteRenderer>().sprite = newArrowIndicator.indicator.offScreenSprite;
        //    //    newArrowIndicator.arrow.GetComponent<SpriteRenderer>().color = newArrowIndicator.indicator.offScreenColor;
        //    //    if (!newArrowIndicator.indicator.showOffScreen)
        //    //    {
        //    //        newArrowIndicator.arrow.SetActive(false);
        //    //    }
        //    //    newArrowIndicator.onScreen = false;
        //    //    arrowIndicators.Add(newArrowIndicator);
        //    //}
        //    //else
        //    //{
        //    //    Debug.LogWarning("Target already added: " + target.name);
        //    //}

        //    throw new System.NotImplementedException();
        //}


        protected override void UpdateIndicatorPosition(ArrowIndicator arrowIndicator, float multiplr, int id = 0)
        {
            Vector3 pCam   = RaycastRoot.transform.position;
            Vector3 pPlane = indicatorsParentObj.transform.position;
            Ray     zRay   = new Ray(pPlane, pCam - pPlane);

            pPlane = zRay.GetPoint(-0.001f * id);
            Plane plane = new Plane(Vector3.Normalize(pCam - pPlane), pPlane);


            //Vector3 pTarget = arrowIndicator.target.transform.position+arrowIndicator.indicator.targetOffset;
            Vector3 pTarget   = arrowIndicator.target.transform.position;
            Ray     rToTarget = new Ray(pCam, pTarget - pCam);
            Vector3 hitPoint;


            //DISTANCE
            float distance;



            if (plane.Raycast(rToTarget, out distance))
            {
                hitPoint = rToTarget.GetPoint(distance);
                if (Vector3.Distance(pPlane, hitPoint) > radius)
                {
                    arrowIndicator.onScreen = false;
                    Ray rToArrow = new Ray(pPlane, hitPoint - pPlane);
                    arrowIndicator.arrow.transform.position = rToArrow.GetPoint(radius);
                }
                else
                {
                    arrowIndicator.onScreen = true;
                    //float disoffset;
                    //disoffset = 1f - (2.000f / distance);
                    //arrowIndicator.arrow.transform.position = hitPoint;
                    //arrowIndicator.arrow.transform.position = hitPoint + arrowIndicator.indicator.targetOffset;

                    //arrowIndicator.arrow.transform.position = hitPoint + arrowIndicator.indicator.targetOffset * disoffset * eyeCamera.stereoSeparation;
                    arrowIndicator.arrow.transform.position = hitPoint + arrowIndicator.indicator.targetOffset * distance * 0.005f;
                }

                Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                float   angle      = (90 - RaycastRoot.transform.localEulerAngles.z) * Mathf.Deg2Rad;

                if ((arrowIndicator.onScreen && arrowIndicator.indicator.onScreenRotates) || (!arrowIndicator.onScreen && arrowIndicator.indicator.offScreenRotates))
                {
                    angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                }
                arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);

                //Debug some lines
                if (enableDebug)
                {
                    Utils.DrawPlane(Vector3.Normalize(pCam - pPlane), pPlane, radius);
                    Debug.DrawRay(rToTarget.origin, rToTarget.direction);
                    Debug.DrawLine(pCam, hitPoint, Color.white);
                    Debug.DrawLine(hitPoint, pPlane, Color.magenta);
                    Debug.DrawLine(RaycastRoot.transform.position, pTarget);
                }


                //check DISTANCE
            }
            else
            {
                rToTarget = new Ray(pTarget, pCam - pTarget);
                if (plane.Raycast(rToTarget, out distance))
                {
                    hitPoint = rToTarget.GetPoint(distance);
                    Ray rToArrow = new Ray(pPlane, hitPoint - pPlane);
                    arrowIndicator.arrow.transform.position = rToArrow.GetPoint(-radius);
                    arrowIndicator.onScreen = false;

                    Vector3 plPlane    = indicatorsParentObj.transform.localPosition;
                    Vector3 plHitPoint = arrowIndicator.arrow.transform.localPosition;
                    float   angle      = (90 - RaycastRoot.transform.localEulerAngles.z) * Mathf.Deg2Rad;
                    if (arrowIndicator.indicator.offScreenRotates)
                    {
                        angle = Mathf.Atan2(plHitPoint.y - plPlane.y, plHitPoint.x - plPlane.x);
                    }
                    arrowIndicator.arrow.transform.localEulerAngles = new Vector3(0, 0, angle * Mathf.Rad2Deg - 90);
                }
                else
                {
                    //target-cast is parallel to the plane, using the last indicator position is fine.
                }
            }



            //throw new System.NotImplementedException();
        }