Ejemplo n.º 1
0
    void Awake()
    {
        MiniMapElement miniMapElement = gameObject.AddComponent <MiniMapElement>();

        if (Random.Range(1, 10) < 5)
        {
            miniMapElement.Init(MiniMapElementIconType.Owner_Tower);
        }
        else
        {
            miniMapElement.Init(MiniMapElementIconType.Enemy_Tower);
        }
    }
Ejemplo n.º 2
0
 public void SetSize()
 {
     size = new Rect(
         localBounds.x / realWorldBounds.x,
         localBounds.y / realWorldBounds.y,
         localBounds.width / realWorldBounds.width,
         localBounds.height / realWorldBounds.height);
     for (var x = 0; x < elements.Length; x++)
     {
         MiniMapElement element = elements[x];
         for (int y = 0; y < element.objAmount; y++)
         {
             element.ModifyLoc(y, Determine2dLoc(element.elementTransform[y].position));
         }
     }
 }
Ejemplo n.º 3
0
        void OnGUI()
        {
            // Saves a lot of processing
#if !UNITY_EDITOR
            useGUILayout = false;
#endif
            // The useGUILayout = false does not honor GUI.depth, this usually breaks when Editor hotswaps the script
            GUI.depth = 0;

            // For Moving around the Camera
            moveCamera = GUI.RepeatButton(localBounds, "") && Input.GetButton("LMB");

            // Draw the Map Background
            if (background != null)
            {
                GUI.DrawTexture(localBounds, background);
            }

            // Draw the Elements on the Map
            for (int x = 0; x < elements.Length; x++)
            {
                MiniMapElement element  = elements[x];
                Vector2        halfSize = new Vector2(element.size.x / 2, element.size.y / 2);
                for (int y = 0; y < element.objAmount; y++)
                {
                    Vector2 loc = element.elementLoc[y];
                    if (element.elementMap[y].display)
                    {
                        GUI.color = element.tints[element.elementFaction[y]];
                        GUI.DrawTexture(
                            new Rect(loc.x - halfSize.x, loc.y - halfSize.y, element.size.x, element.size.y),
                            element.image);
                    }
                }
            }

            // Drawing the fog
            GUI.color = fogColor;
            GUI.DrawTexture(localBounds, fogTexture);
            if (cameraElement.image)
            {
                // Draw the Camera
                GUI.color = cameraElement.tints[0];
                GUI.DrawTexture(cameraLoc, cameraElement.image, ScaleMode.StretchToFill);
            }
        }
Ejemplo n.º 4
0
        void FixedUpdate()
        {
            for (var x = 0; x < elements.Length; x++)
            {
                MiniMapElement element = elements[x];
                for (int y = 0; y < element.objAmount; y++)
                {
                    if (element.elementObj[y] == null)
                    {
                        element.elementObj.RemoveAt(y);
                        element.elementMap.RemoveAt(y);
                        element.elementTransform.RemoveAt(y);
                        element.elementLoc.RemoveAt(y);
                        element.elementFaction.RemoveAt(y);
                        element.objAmount--;
                        y--;
                    }
                }
            }

            for (var x = 0; x < elements.Length; x++)
            {
                MiniMapElement element = elements[x];
                for (int y = 0; y < element.objAmount; y++)
                {
                    if (!element.elementMap[y].isStatic)
                    {
                        element.elementLoc[y] = Determine2dLoc(element.elementTransform[y].position);
                    }
                }
            }

            //Vector2 loc = Determine2dLoc(cam.transform.position);

            RaycastHit hitTopLeft;
            Ray        ray = cam.ScreenPointToRay(new Vector2(0, Screen.height));

            Physics.Raycast(ray, out hitTopLeft, 1000, camZoomLayer);
            RaycastHit hitTopRight;

            ray = cam.ScreenPointToRay(new Vector2(Screen.width, Screen.height));
            Physics.Raycast(ray, out hitTopRight, 1000, camZoomLayer);
            RaycastHit hitBottomRight;

            ray = cam.ScreenPointToRay(new Vector2(Screen.width, 0));
            Physics.Raycast(ray, out hitBottomRight, 1000, camZoomLayer);
            if (hitTopLeft.collider != null && hitTopRight.collider != null && hitBottomRight.collider != null)
            {
                var topLeft     = Determine2dLoc(hitTopLeft.point);
                var topRight    = Determine2dLoc(hitTopRight.point);
                var bottomRight = Determine2dLoc(hitBottomRight.point);
                cameraLoc = new Rect(topLeft.x, topLeft.y, topRight.x - topLeft.x, bottomRight.y - topLeft.y);
            }
            else
            {
                Debug.LogWarning("Minimap could not detect its camera location via ray, check your Cam Zoom Layer");
            }
            if (!moveCamera)
            {
                return;
            }
            cameraController.transform.position = Determine3dLoc(
                cameraController.transform.position.y,
                new Vector2(
                    Input.mousePosition.x,
                    Screen.height - Input.mousePosition.y + cameraLoc.height / 2));
        }
Ejemplo n.º 5
0
    void FixedUpdate()
    {
        for (int x = 0; x < elements.Length; x++)
        {
            for (int y = 0; y < elements[x].objAmount; y++)
            {
                if (elements[x].elementObj[y] == null)
                {
                    elements[x].elementObj.RemoveAt(y);
                    elements[x].elementMap.RemoveAt(y);
                    elements[x].elementTransform.RemoveAt(y);
                    elements[x].elementLoc.RemoveAt(y);
                    elements[x].elementGroup.RemoveAt(y);
                    elements[x].objAmount--;
                    y--;
                }
            }
        }

        for (int x = 0; x < elements.Length; x++)
        {
            for (int y = 0; y < elements[x].objAmount; y++)
            {
                if (!elements[x].elementMap[y].isStatic)
                {
                    elements[x].elementLoc[y] = Determine2dLoc(elements[x].elementTransform[y].position);
                }
            }
        }

        Vector2        loc     = Determine2dLoc(cam.transform.position);
        MiniMapElement details = cameraElement;

        if (details.image)
        {
            GUI.color = details.tints[0];
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(new Vector2(0, Screen.height));
            Physics.Raycast(ray, out hit, 1000, camZoomLayer);
            bool check = true;
            if (hit.collider == null)
            {
                check = false;
            }
            RaycastHit hit2;
            ray = Camera.main.ScreenPointToRay(new Vector2(Screen.width, 0));
            Physics.Raycast(ray, out hit2, 1000, camZoomLayer);
            if (hit2.collider == null)
            {
                check = false;
            }
            if (check)
            {
                lastPoint1 = Determine2dLoc(hit.point);
                lastPoint2 = Determine2dLoc(hit2.point);
            }
            cameraLoc = new Rect(lastPoint1.x, lastPoint1.y, lastPoint2.x - lastPoint1.x, lastPoint2.y - lastPoint1.y);
            if (moveCamera)
            {
                Vector3 pos = Determine3dLoc(new Vector2(Input.mousePosition.x + cameraLoc.width / 4, Screen.height - Input.mousePosition.y + cameraLoc.height / 2));
                cameraController.transform.position = new Vector3(pos.x, cameraController.transform.position.y, pos.z);
            }
        }
    }