Exemplo n.º 1
0
    void Update()
    {
        float minX = img.GetPixelAdjustedRect().width / 2;
        float maxX = Screen.width - minX;

        float minY = img.GetPixelAdjustedRect().height / 2;
        float maxY = Screen.height - minY;

        Vector2 pos = Camera.main.WorldToScreenPoint(target.position);


        if (Vector3.Dot((target.position - transform.position), transform.forward) < 0)
        {
            if (pos.x < Screen.width / 2)
            {
                pos.x = maxX;
            }
            else
            {
                pos.x = minX;
            }
        }

        pos.x = Mathf.Clamp(pos.x, minX, maxX);
        pos.y = Mathf.Clamp(pos.y, minY, maxY);

        img.transform.position = pos;
    }
Exemplo n.º 2
0
        private void Generate()
        {
            // Image width and height
            Rect rect   = image.GetPixelAdjustedRect();
            int  width  = (int)(rect.width / scale);
            int  height = (int)(rect.height / scale);

            //Debug.Log($"{width} {height}");

            // Create a vector of pixels
            Color[] pixels = new Color[width * height];

            // Texture to show on screen, to be randomly created
            Texture2D texture = new Texture2D(width, height);

            // Generate scenario
            scenarioConfig.Generate(pixels, width, height);

            // Set and apply texture pixels
            texture.SetPixels(pixels);
            texture.Apply();

            // Place texture in image
            image.texture = texture;
        }
Exemplo n.º 3
0
    public override Vector2 GetCoords(Vector2 position)
    {
        Vector2 point;

#if CURVEDUI
        if (curvedUI != null)
        {
            Camera activeCamera = image.canvas.renderMode == RenderMode.ScreenSpaceOverlay ? Camera.main : image.canvas.worldCamera;
            if (!curvedUI.RaycastToCanvasSpace(activeCamera.ScreenPointToRay(position), out point))
            {
                return(Vector2.zero);
            }
            Vector3 worldPoint = image.canvas.transform.localToWorldMatrix.MultiplyPoint(point);
            point = image.rectTransform.worldToLocalMatrix.MultiplyPoint(worldPoint);
        }
        else
        {
#endif
        if (!RectTransformUtility.RectangleContainsScreenPoint(image.rectTransform, position, worldCamera))
        {
            return(Vector2.zero);
        }
        RectTransformUtility.ScreenPointToLocalPointInRectangle(image.rectTransform, position, worldCamera, out point);
#if CURVEDUI
    }
#endif
        Rect rect = image.GetPixelAdjustedRect();

        Vector2 size = (rect.max - point);
        size.x = size.x / rect.size.x;
        size.y = size.y / rect.size.y;

        Vector2 r = new Vector2((size.x - .5f), (size.y - .5f));

        int countX = map.width / OnlineMapsUtils.tileSize;
        int countY = map.height / OnlineMapsUtils.tileSize;

        double px, py;
        map.GetTilePosition(out px, out py);

        px -= countX * r.x;
        py += countY * r.y;

        map.projection.TileToCoordinates(px, py, map.zoom, out px, out py);
        return(new Vector2((float)px, (float)py));
    }
Exemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        HomeWaypointHolder.SetActive(true);

        // To stick waypoint in screen
        float minX = HomeWaypointIndicator.GetPixelAdjustedRect().width / 3.5f;
        float maxX = Screen.width - minX;

        float minY = HomeWaypointIndicator.GetPixelAdjustedRect().height / 3.5f;
        float maxY = Screen.height - minY;

        // Cheese position
        Vector2 PositionHome = Camera.main.WorldToScreenPoint(HomeOnMap.position + Offset);

        PositionHome.x = Mathf.Clamp(PositionHome.x, minX, maxX);
        PositionHome.y = Mathf.Clamp(PositionHome.y, minY, maxY);

        HomeWaypointIndicator.transform.position = PositionHome;
    }
Exemplo n.º 5
0
    void Update()
    {
        if (Cheese.activeInHierarchy == true)
        {
            CheeseWaypointHolder.SetActive(true);

            // To stick waypoint in screen
            float minX = CheeseWaypointIndicator.GetPixelAdjustedRect().width / 3.5f;
            float maxX = Screen.width - minX;

            float minY = CheeseWaypointIndicator.GetPixelAdjustedRect().height / 3.5f;
            float maxY = Screen.height - minY;

            // Cheese position
            Vector2 PositionCheese = Camera.main.WorldToScreenPoint(CheeseOnMap.position + Offset);

            PositionCheese.x = Mathf.Clamp(PositionCheese.x, minX, maxX);
            PositionCheese.y = Mathf.Clamp(PositionCheese.y, minY, maxY);

            CheeseWaypointIndicator.transform.position = PositionCheese;
        }
        else
        {
            CheeseWaypointHolder.SetActive(false);
        }

        if (EnemyEquipped1.activeInHierarchy == true)
        {
            Enemy1WaypointHolder.SetActive(true);

            // To stick waypoint in screen
            float minX = EnemyEquipped1WaypointIndicator.GetPixelAdjustedRect().width / 3.5f;
            float maxX = Screen.width - minX;

            float minY = EnemyEquipped1WaypointIndicator.GetPixelAdjustedRect().height / 3.5f;
            float maxY = Screen.height - minY;

            // Cheese position
            Vector2 PositionCheese = Camera.main.WorldToScreenPoint(EnemyEquipped1Position.position + Offset);

            PositionCheese.x = Mathf.Clamp(PositionCheese.x, minX, maxX);
            PositionCheese.y = Mathf.Clamp(PositionCheese.y, minY, maxY);

            EnemyEquipped1WaypointIndicator.transform.position = PositionCheese;
        }
        else
        {
            Enemy1WaypointHolder.SetActive(false);
        }

        if (EnemyEquipped2.activeInHierarchy == true)
        {
            Enemy2WaypointHolder.SetActive(true);

            // To stick waypoint in screen
            float minX = EnemyEquipped2WaypointIndicator.GetPixelAdjustedRect().width / 3.5f;
            float maxX = Screen.width - minX;

            float minY = EnemyEquipped2WaypointIndicator.GetPixelAdjustedRect().height / 3.5f;
            float maxY = Screen.height - minY;

            // Cheese position
            Vector2 PositionCheese = Camera.main.WorldToScreenPoint(EnemyEquipped2Position.position + Offset);

            PositionCheese.x = Mathf.Clamp(PositionCheese.x, minX, maxX);
            PositionCheese.y = Mathf.Clamp(PositionCheese.y, minY, maxY);

            EnemyEquipped2WaypointIndicator.transform.position = PositionCheese;
        }
        else
        {
            Enemy2WaypointHolder.SetActive(false);
        }

        if (EnemyEquipped3.activeInHierarchy == true)
        {
            Enemy3WaypointHolder.SetActive(true);

            // To stick waypoint in screen
            float minX = EnemyEquipped3WaypointIndicator.GetPixelAdjustedRect().width / 3.5f;
            float maxX = Screen.width - minX;

            float minY = EnemyEquipped3WaypointIndicator.GetPixelAdjustedRect().height / 3.5f;
            float maxY = Screen.height - minY;

            // Cheese position
            Vector2 PositionCheese = Camera.main.WorldToScreenPoint(EnemyEquipped3Position.position + Offset);

            PositionCheese.x = Mathf.Clamp(PositionCheese.x, minX, maxX);
            PositionCheese.y = Mathf.Clamp(PositionCheese.y, minY, maxY);

            EnemyEquipped3WaypointIndicator.transform.position = PositionCheese;
        }
        else
        {
            Enemy3WaypointHolder.SetActive(false);
        }
    }
    private void OnPreCull()
    {
        if (IsReadyToRender)
        {
            int depthbit, aasetting;
            RenderTextureFormat    format;
            RenderTextureReadWrite readwrite;
            Rect rect = renderRawImage.GetPixelAdjustedRect();
            int  w = (int)rect.width, h = (int)rect.height;

            //change the texture format here, if you need another behaviour
            if (sceneCamera.allowHDR)
            {
                format = RenderTextureFormat.DefaultHDR;
            }
            else
            {
                format = RenderTextureFormat.Default;
            }

            //MSAA is impossible with deferred rendering
            if (sceneCamera.renderingPath == RenderingPath.DeferredLighting || sceneCamera.renderingPath == RenderingPath.DeferredShading)
            {
                aasetting = 1;
            }
            else
            {
                aasetting = Mathf.Max(QualitySettings.antiAliasing, 1);
            }

            switch (cprt.renderTextureDepthBits)
            {
            case CPRT.RenderTextureDepthBitCount.Depth16:
                depthbit = 16;
                break;

            case CPRT.RenderTextureDepthBitCount.Depth32:
                depthbit = 32;
                break;

            case CPRT.RenderTextureDepthBitCount.DepthStencil24:
            default:
                depthbit = 24;
                break;
            }

            if (QualitySettings.activeColorSpace == ColorSpace.Gamma)
            {
                readwrite = RenderTextureReadWrite.sRGB;
            }
            else
            {
                readwrite = RenderTextureReadWrite.Linear;
            }

            //release previous render texture if needed
            ReleaseTempTexture();

            //actual Render Texture creation
            tempRT            = RenderTexture.GetTemporary(w, h, depthbit, format, readwrite, aasetting);
            tempRT.filterMode = FilterMode.Point;

            //setting the UI Image texture
            renderRawImage.texture = tempRT;

            //render the scene into the target texture
            sceneCamera.enabled = true;
            if (cprt.isActiveAndEnabled)
            {
                cprt.RenderToTexture(tempRT);
            }
            else
            {
                sceneCamera.targetTexture = tempRT;
                sceneCamera.Render();
            }
            sceneCamera.enabled = false;
        }
    }
Exemplo n.º 7
0
    private void Update()
    {
        if (GameManager.Instance.dome.Upgrading)
        {
            return;
        }

        compassImage.uvRect = new Rect(GameManager.Instance.dome.domeCamera.transform.localEulerAngles.y / 360f, 0, 1, 1);

        for (int i = _targets.Count - 1; i >= 0; i--)
        {
            Target target = _targets[i];
            if (target.target == null)
            {
                // this target no longer exists - remove unused elements
                if (target.blip != null)
                {
                    Destroy(target.blip);
                }
                if (target.vectorLine != null)
                {
                    VectorLine.Destroy(ref target.vectorLine);
                }
                _targets.RemoveAt(i);
            }
            else
            {
                if (radarType == RadarType.SimpleLine)
                {
                    if (target.vectorLine == null)
                    {
                        target.vectorLine = VectorLine.SetRay3D(Color.white, target.target.transform.position, Vector3.down * 50f);
                    }

                    target.vectorLine.points3 = new List <Vector3>()
                    {
                        target.target.transform.position, target.target.transform.position + (Vector3.down * 50f)
                    };
                    target.vectorLine.Draw3D();
                }
                else if (radarType == RadarType.Spaceship)
                {
                    // calculate the scaled position relative to the size of our radar
                    Vector3 radarPos = new Vector3(
                        model.localScale.x / (GameManager.Instance.worldRadius / target.target.transform.position.x),
                        model.localScale.y / (GameManager.Instance.worldRadius / target.target.transform.position.y),
                        model.localScale.z / (GameManager.Instance.worldRadius / target.target.transform.position.z)
                        );

                    if (target.blip == null)
                    {
                        target.blip = Instantiate(blipPrefab, blipParent);
                        target.blip.GetComponent <Renderer>().material.color = target.colour;
                        target.line = target.blip.GetComponent <LineRenderer>();
                        target.line.material.color = target.colour;
                    }

                    // set the blips position
                    target.blip.transform.localPosition = radarPos;

                    // adjust the length of the line renderer
                    float lineY = (radarPos.y * GameManager.Instance.worldRadius) / 2f;
                    target.line.SetPosition(1, new Vector3(0f, -lineY, 0f));
                }
                else if (radarType == RadarType.Compass)
                {
                    Vector3 a  = Vector3.zero;
                    Vector3 b  = new Vector3(target.target.transform.position.x, 0, target.target.transform.position.z);
                    Vector3 lt = Vector3.MoveTowards(Vector3.zero, GameManager.Instance.dome.domeCamera.transform.forward * 10f, 10f);
                    lt.y = 0;
                    Vector3 f = lt - Vector3.zero;

                    float angle = Vector3.Angle(b - a, f);
                    if (angle < 90)
                    {
                        if (target.blip == null)
                        {
                            target.blip = Instantiate(blipPrefab, blipParent);

                            // if we've got a bird identifier installed, use the correct icon
                            if (identifierInstalled && target.icon != null)
                            {
                                target.blip.GetComponent <Image>().sprite = target.icon;
                                target.blip.GetComponent <Image>().SetNativeSize();
                            }

                            target.upDownArrows    = new Transform[2];
                            target.upDownArrows[0] = target.blip.transform.GetChild(0);
                            target.upDownArrows[1] = target.blip.transform.GetChild(1);
                        }

                        float width = compassImage.GetPixelAdjustedRect().width / 2f;
                        float multi = Mathf.InverseLerp(0, 90, angle);
                        float value = AngleDir(f, b - a, Vector3.up);
                        float x     = (width * multi) * value;
                        target.blip.transform.localPosition = new Vector2(x, 0);

                        // set colour based on distance
                        float dist = Vector3.Distance(GameManager.Instance.dome.transform.position, target.target.transform.position);
                        float gv   = 1 - Mathf.InverseLerp(0, GameManager.Instance.worldRadius, dist);
                        target.blip.GetComponent <Image>().color = gradient.Evaluate(gv);
                        target.blip.transform.localScale         = Vector3.one * scaleCurve.Evaluate(gv);

                        // display up or down indicators if neccessary
                        Vector3 toTarget = (target.target.transform.position - GameManager.Instance.dome.transform.position).normalized;
                        float   va       = Vector3.Angle(GameManager.Instance.dome.domeCamera.transform.forward, toTarget);
                        float   sign     = Mathf.Sign(Vector3.Dot(GameManager.Instance.dome.domeCamera.transform.right, Vector3.Cross(GameManager.Instance.dome.domeCamera.transform.forward, toTarget)));
                        bool    up       = va * sign < 0;
                        bool    show     = va > 17f && !identifierInstalled;
                        target.upDownArrows[0].gameObject.SetActive(up && show);
                        target.upDownArrows[1].gameObject.SetActive(!up && show);
                    }
                    else if (target.blip)
                    {
                        Destroy(target.blip);
                    }
                }
            }
        }

        if (radarType == RadarType.Spaceship)
        {
            // rotate the radar camera about center point to match the main camera's angle
            float angle = GameManager.Instance.dome.domeCamera.transform.localEulerAngles.y - cam.transform.localEulerAngles.y;
            cam.transform.RotateAround(model.transform.position, Vector3.up, angle);
        }
    }