Esempio n. 1
0
        // protected override
        void Update()
        {
            // base.Update();

            if (!Application.isPlaying) //{
            {
                return;
            }
            // }

            // if (GameManager.isInMainMenuScene)
            //     return;

            if (!GameManager.playerExists)
            {
                return;
            }

            if (!isActive)
            {
                return;
            }

            // Camera playerCamera = GameManager.playerCamera;
            // if (playerCamera == null)
            //     return;


            Actor playerActor = GameManager.playerActor;
            // if (playerActor == null)
            //     return;

            Vector3 playerPos = playerActor.GetPosition();

            baseMapParameters.UpdateMapMarkers(playerPos);


            Vector3 playerFwd = playerActor.GetForward();

            playerFwd.y = 0;

            // Transform t = UIManager.GetMainCamera().transform;

            // if (t != null) {
            // Vector3 playerPos = t.position;
            // Vector3 playerFwd = t.forward;
            // playerFwd.y = 0;

            float playerAngle = Vector3.Angle(playerFwd, Vector3.forward);

            if (Vector3.Angle(playerFwd, Vector3.right) > 90)
            {
                playerAngle *= -1;
            }

            Transform parent = uiCamera.transform.parent;

            parent.position = playerPos + Vector3.up * uiCamera.farClipPlane * .5f;
            parent.rotation = Quaternion.LookRotation(playerFwd);

            float cameraSize = cameraArea * .5f;

            uiCamera.orthographicSize = cameraSize;
            uiCamera.Render();

            Vector2 halfSize = size * .5f;

            for (int i = 0; i < baseMapParameters.mapMarkers.Count; i++)
            {
                MapMarker m = baseMapParameters.mapMarkers[i];

                Vector3 wPos = m.GetMarkerPosition();

                Vector3 lPos = parent.InverseTransformPoint(wPos);

                Vector2 anchorPos_unMoved = new Vector2(lPos.x / cameraSize * halfSize.x, lPos.z / cameraSize * halfSize.y);
                Vector2 anchorPos         = anchorPos_unMoved + halfSize;

                bool markerEnabled = m.alwaysShowMiniMap || (anchorPos.x >= 0 && anchorPos.y >= 0 && anchorPos.x <= size.x && anchorPos.y <= size.y);
                if (m.alwaysShowMiniMap)
                {
                    /*
                     \  |
                     \  x \a|   panel radius
                     \|
                     \|
                     \| cos (a) = panel radius / x
                     \| cos (a) * x = panel radius
                     \| x = panelRadius / cos(a)
                     \|
                     \| max angle before switching hypotenuse calculation to use width:
                     \|
                     \| panel x radius
                     \| _____
                     \  |
                     \    \a|   panel h radius
                     \|
                     \|
                     \| a = maxAngle
                     \| tan (maxAngle) = (panel x radius) / (panel y radius)
                     */
                    float maxAngle = Mathf.Atan(halfSize.x / halfSize.y) * Mathf.Rad2Deg;

                    float adjacentSize = halfSize.y;
                    float angle        = Mathf.Atan2(anchorPos_unMoved.x, anchorPos_unMoved.y) * Mathf.Rad2Deg;
                    angle = angle < 0 ? -angle : angle;
                    angle = angle > (180 - maxAngle) ? 180 - angle : angle;

                    if (angle >= maxAngle)
                    {
                        adjacentSize = halfSize.x;
                        angle        = angle > 90 ? (angle - 90) : (90 - angle);
                    }

                    float hypotenuse = adjacentSize / Mathf.Cos(angle * Mathf.Deg2Rad);

                    anchorPos_unMoved = Vector2.ClampMagnitude(anchorPos_unMoved, hypotenuse);
                    anchorPos         = anchorPos_unMoved + halfSize;
                }

                m.EnableMapMarker(markerEnabled);

                if (markerEnabled)
                {
                    m.rectTransform.anchoredPosition = anchorPos;

                    if (m.showRotation)
                    {
                        if (m.mainGraphic != null)
                        {
                            Vector3 fwd = m.GetMarkerForward();
                            fwd.y = 0;
                            float angle = Vector3.Angle(fwd, Vector3.forward);
                            if (Vector3.Angle(fwd, Vector3.right) > 90)
                            {
                                angle *= -1;
                            }
                            m.mainGraphic.rectTransform.localRotation = Quaternion.Euler(0, 0, -angle + playerAngle);
                        }
                    }
                }
            }
            // }
        }
Esempio n. 2
0
        void Update()
        {
            base.Update();
            if (!Application.isPlaying)
            {
                return;
            }

            if (!isActive)
            {
                return;
            }


            if (!GameManager.playerExists)
            {
                return;
            }


            baseMapParameters.UpdateMapMarkers(GameManager.playerActor.GetPosition());


            zoom -= UIInput.mouseScrollDelta.y * zoomSpeed * Time.deltaTime;
            zoom  = Mathf.Clamp(zoom, 1, maxZoom);

            float z     = 1f / zoom;
            float speed = moveSpeed * Time.deltaTime * z;

            float inputX = UIInput.GetHorizontalAxis();
            float inputY = UIInput.GetVerticalAxis();

            if (unsnapProhibit)
            {
                if (inputX == 0 && inputY == 0 || Time.time - snappedTime >= unsnapTime)
                {
                    unsnapProhibit = false;
                }
                inputX = 0;
                inputY = 0;
            }


            move.x = Mathf.Clamp(move.x + inputX * speed, -.5f, .5f);
            move.y = Mathf.Clamp(move.y + inputY * speed, -.5f, .5f);

            float zOffset = (-0.5f) * z + 0.5f;

            Vector2 move2         = move * 2;
            float   halfMapUI     = mapSize * .5f;
            float   halfMapUIZoom = halfMapUI * zoom;



            for (int k = 0; k < baseMapParameters.mapMarkers.Count; k++)
            {
                // foreach (var k in mapMarkers.Keys) {
                MapMarker m = baseMapParameters.mapMarkers[k];

                Vector3 wPos  = m.GetMarkerPosition();
                Vector2 uiPos = (((new Vector2(wPos.x, wPos.z) - mapCenter) / mapRadius) - move2) * halfMapUIZoom;

                bool markerEnabled = uiPos.x <= halfMapUI && uiPos.x >= -halfMapUI && uiPos.y <= halfMapUI && uiPos.y >= -halfMapUI;
                m.EnableMapMarker(markerEnabled);

                if (markerEnabled && uiPos.sqrMagnitude <= snapDist)
                {
                    if (selectedMarker == null) // && (markerToSelect == null || markerToSelect == currentWaypointMarker)) {
                    // markerToSelect = m;
                    {
                        move += (uiPos / halfMapUI) / 2 * z;
                        uiPos = Vector2.zero;

                        // // move.x += (uiPos.x / halfMapUI)/2 * z;
                        // // move.y += (uiPos.y / halfMapUI)/2 * z;
                        unsnapProhibit = true;
                        snappedTime    = Time.time;
                        SelectMarker(m);
                    }
                }
                else
                {
                    if (selectedMarker == m)
                    {
                        DeselectMarker(m);
                    }
                }

                if (markerEnabled)
                {
                    if (m.showRotation)
                    {
                        if (m.mainGraphic != null)
                        {
                            Vector3 fwd = m.GetMarkerForward();
                            fwd.y = 0;
                            float angle = Vector3.Angle(fwd, Vector3.forward);
                            if (Vector3.Angle(fwd, Vector3.right) > 90)
                            {
                                angle *= -1;
                            }

                            m.mainGraphic.rectTransform.localRotation = Quaternion.Euler(0, 0, -angle);
                        }
                    }
                    m.rectTransform.anchoredPosition = uiPos;
                }
            }

            mapImage.uvRect = new Rect(move.x + zOffset, move.y + zOffset, z, z);

            if (UIInput.GetSubmitDown())
            {
                AddWaypoint(zOffset);
            }
        }
Esempio n. 3
0
        // protected override
        void Update()
        {
            // base.Update();

            if (!Application.isPlaying)
            {
                return;
            }

            if (!GameManager.playerExists)
            {
                return;
            }

            if (!isActive)
            {
                return;
            }

            Actor playerActor = GameManager.playerActor;
            // if (playerActor == null)
            //     return;

            Vector3 playerPos = playerActor.GetPosition();

            baseMapParameters.UpdateMapMarkers(playerPos);



            Vector3 playerFwd = playerActor.GetForward();

            playerFwd.y = 0;
            Vector3 playerRight = Vector3.Cross(playerFwd, Vector3.up);

            // set position of icons based on angle with camera
            // Transform playerTransform = UIManager.GetMainCamera().transform;
            // Vector3 playerPosition = playerTransform.position;
            // Vector3 playerFwd = playerTransform.forward;
            // Vector3 playerRight = playerTransform.right;
            // playerFwd.y = 0;
            // playerRight.y = 0;

            float halfSize = size.x * .5f;

            float maxAngle = angleRange + outOfAngleBuffer;


            for (int i = 0; i < baseMapParameters.mapMarkers.Count; i++)
            {
                MapMarker m = baseMapParameters.mapMarkers[i];

                Vector3 dir = m.GetMarkerPosition() - playerPos;

                float distance = dir.magnitude;

                // angle goes to zero the closer the object is, so close markers dont jump around compass
                float mult = Mathf.Pow(distance / distanceBuffer, distanceBufferSteepness);

                if (mult > 1)
                {
                    mult = 1;
                }

                dir.y = 0;

                float angleWFwd = Vector3.Angle(playerFwd, dir) * mult;

                bool markerEnabled = (angleWFwd <= maxAngle);

                m.EnableMapMarker(markerEnabled);

                if (markerEnabled)
                {
                    float t = angleWFwd / angleRange;
                    if (t > 1)
                    {
                        t = 1;
                    }

                    bool toRight = Vector3.Angle(playerRight, dir) < 90;

                    m.rectTransform.anchoredPosition = new Vector2(t * (toRight ? halfSize : -halfSize), 0);
                }
            }
        }
Esempio n. 4
0
        // protected override
        void Update()
        {
            // base.Update();

            if (!Application.isPlaying)
            {
                return;
            }

            if (!GameManager.playerExists)
            {
                return;
            }

            // if (GameManager.isInMainMenuScene)
            //     return;


            baseMapParameters.UpdateMapMarkers(GameManager.playerActor.GetPosition());


            Camera playerCamera = GameManager.playerCamera;

            if (playerCamera == null)
            {
                return;
            }

            if (!isActive)
            {
                return;
            }

            if (UIMainCanvas.instance == null)
            {
                return;
            }

            float borderOffset = baseMapParameters.markerParameters.iconSize * transform.localScale.x * 2;

            Vector2 fullSize = ((UIMainCanvas.instance.rectTransform.sizeDelta - Vector2.one * borderOffset) / transform.localScale.x);
            Vector2 halfSize = fullSize * .5f;

            for (int i = 0; i < baseMapParameters.mapMarkers.Count; i++)
            {
                MapMarker m        = baseMapParameters.mapMarkers[i];
                Vector3   worldPos = m.GetMarkerPosition();

                Vector3 screenPos = playerCamera.WorldToViewportPoint(worldPos);

                if (screenPos.z < 0)
                {
                    screenPos.x = 1f - screenPos.x;
                    screenPos.y = 0;
                }
                else
                {
                    screenPos.y = Mathf.Clamp01(screenPos.y);
                }

                Vector2 pos = new Vector2(
                    screenPos.x * fullSize.x - halfSize.x,
                    screenPos.y * fullSize.y - halfSize.y
                    );

                /*
                 \  |
                 \  x\a|   panel radius
                 \|
                 \|
                 \| cos (a) = panel radius / x
                 \| cos (a) * x = panel radius
                 \| x = panelRadius / cos(a)
                 \|
                 \| max angle before switching hypotenuse calculation to use width:
                 \|
                 \| panel x radius
                 \| _____
                 \  |
                 \    \a|   panel h radius
                 \|
                 \|
                 \| a = maxAngle
                 \| tan (maxAngle) = (panel x radius) / (panel y radius)
                 */
                float maxAngle = Mathf.Atan(halfSize.x / halfSize.y) * Mathf.Rad2Deg;

                float adjacentSize = halfSize.y;
                float angle        = Mathf.Atan2(pos.x, pos.y) * Mathf.Rad2Deg;
                angle = angle < 0 ? -angle : angle;
                angle = angle > (180 - maxAngle) ? 180 - angle : angle;

                if (angle >= maxAngle)
                {
                    adjacentSize = halfSize.x;
                    angle        = angle > 90 ? (angle - 90) : (90 - angle);
                }

                float hypotenuse = adjacentSize / Mathf.Cos(angle * Mathf.Deg2Rad);


                /*
                 \  |
                 \  x \a| <-panel radius
                 \|
                 \|
                 \| cos (a) = panel radius / x      ->
                 \| cos (a) * x = panel radius      ->
                 \| x = panelRadius / cos(a)
                 */


                // float angle = Mathf.Atan2(pos.x, pos.y) * Mathf.Rad2Deg;
                // angle = angle < 0 ? -angle : angle;
                // angle = angle > 135 ? angle - 90 : angle;


                // float adjacentSize = halfSize.y;
                // if (angle >= 45) {
                //     angle = angle > 90 ? (angle - 90) : (90 - angle);
                //     adjacentSize = halfSize.x;
                // }

                // float hypotenuse = (adjacentSize / Mathf.Cos(angle * Mathf.Deg2Rad));

                pos = Vector2.ClampMagnitude(pos, hypotenuse);
                m.rectTransform.anchoredPosition = pos;
            }
        }