namespace PivecLabs.Minimap { using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using UnityEngine.Video; using System.Linq; public class MapManager : MonoBehaviour { [SerializeField] public bool miniMapshowing; [SerializeField] public bool fullMapshowing; [SerializeField] public bool compassshowing; [SerializeField] public GameObject Compasscanvas; private bool CompassActive = false; [SerializeField] public RawImage CompassImage; [SerializeField] public Text CompassDirectionText; [SerializeField] public KeyCode selectedKey = KeyCode.None; [SerializeField] public GameObject mapPanel; [SerializeField] public GameObject rawImage; [SerializeField] public GameObject mapCanvas; [SerializeField] public GameObject player; [SerializeField] public GameObject overlayCanvas; [SerializeField] public bool rotating; [Range(1, 1500)] [SerializeField] public float cameraSizeM = 20f; [Range(1, 1500)] [SerializeField] public float cameraSizeF = 20f; [Range(1,100)] [SerializeField] private float cameraDistanceM = 30f; [Range(1,60)] [SerializeField] private float cameraDistanceF = 30f; [Range(1,60)] [SerializeField] public float planedistance = 10f; [SerializeField] public enum MAPPOSITION { TopRight, TopLeft, BottomLeft, BottomRight } [SerializeField] public MAPPOSITION mapPosition = MAPPOSITION.TopRight; private float mmwidth; private float mmoffsetx; private float mmoffsety; public GameObject Health; public GameObject Stamina; private RectTransform m_RectTransform; [SerializeField] public bool overlay; [SerializeField] public bool lockMap; [SerializeField] public bool centerMap; [SerializeField] public GameObject mapCenter; [SerializeField] public bool overlayMap; [SerializeField] public bool zoomMap; [SerializeField] public bool dragMap; [SerializeField] [Range(0, 2)] public int dragbutton = 0; [SerializeField] [Range(1, 10)] public int dragspeed = 1; [SerializeField] [Range(1f, 20f)] public float zoomSensitivity = 5.0f; RenderTexture renderTexture; RectTransform rt; RawImage img; private Camera targetCamera; private MapManager fullscreen; private GameObject rotatingFrame; [System.Serializable] public class Marker { public string Tag; public Texture2D Image; } [SerializeField] public List Markers = new List(); [SerializeField] public bool updateMarkersM; [SerializeField] public bool updateMarkersF; [SerializeField] public bool mapMarkersM; [SerializeField] public bool mapMarkersF; [SerializeField] public bool showMarkersM; [SerializeField] public bool showMarkersF; [SerializeField] [Range(0,1)] public float markerSizeM = 0.2f; [SerializeField] [Range(0,4)] public float markerSizeF = 0.2f; private Vector3 markers; [SerializeField] public LayerMask cullingMaskmm = ~0; [SerializeField] public bool occlusionCullingmm = true; [SerializeField] public LayerMask cullingMaskfm = ~0; [SerializeField] public bool occlusionCullingfm = true; [SerializeField] public int markerLayer; void Start() { miniMapshowing = true; ShowMiniMap(); ActualStart(); } public void ActualStart() { if (Compasscanvas != null) { if (compassshowing == true) { Compasscanvas.SetActive(true); CompassActive = true; } else { Compasscanvas.SetActive(false); CompassActive = false; } } } public void ShowBigMap() { if (miniMapshowing == false) { miniMapshowing = true; fullMapshowing = false; if (compassshowing == true) { CompassActive = true; Compasscanvas.SetActive(true); } Health.SetActive(true); Stamina.SetActive(true); ShowMiniMap(); } else { miniMapshowing = false; fullMapshowing = true; if (compassshowing == true) { CompassActive = false; Compasscanvas.SetActive(false); } Health.SetActive(false); Stamina.SetActive(false); ShowFullScreenMap(); } } public void ShowLittleMap(GameObject A) { if (A.activeSelf == true) { A.SetActive(false); } else { A.SetActive(true); } } void Update() { if ((fullMapshowing == true) && (dragMap == true) && (lockMap == true)) { GameObject go = GameObject.Find("MiniMapCamera"); // if (Input.GetMouseButton(dragbutton)) // { // // go.GetComponent().transform.position -= new Vector3(Input.GetAxis("Mouse X") * dragspeed, 0, Input.GetAxis("Mouse Y") * dragspeed); // } } if ((fullMapshowing == true) && (zoomMap == true)) { GameObject go = GameObject.Find("MiniMapCamera"); // go.GetComponent().orthographicSize += Input.GetAxis("Mouse ScrollWheel") * zoomSensitivity; } } void ShowMiniMap() { GameObject go = GameObject.Find("MiniMapCamera"); if (go) { img = null; targetCamera = null; renderTexture = null; Destroy(go.gameObject); } if (renderTexture == null) { rt = (RectTransform)rawImage.transform; renderTexture = new RenderTexture((int)rt.rect.width, (int)rt.rect.height, 32); renderTexture.Create(); } if (img == null) { img = rawImage.gameObject.GetComponent(); img.texture = renderTexture; } if (targetCamera == null) { GameObject cameraMinimap = new GameObject(); cameraMinimap.transform.parent = player.transform; targetCamera = cameraMinimap.AddComponent(); targetCamera.name = "MiniMapCamera"; targetCamera.cullingMask = this.cullingMaskmm; targetCamera.useOcclusionCulling = occlusionCullingmm; targetCamera.enabled = true; targetCamera.allowHDR = false; targetCamera.targetTexture = renderTexture; targetCamera.orthographic = true; targetCamera.nearClipPlane = -500; targetCamera.orthographicSize = cameraSizeM; targetCamera.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + cameraDistanceM, player.transform.position.z); targetCamera.transform.LookAt(player.transform); targetCamera.transform.localRotation = Quaternion.Euler(90.0f,0.0f,0.0f); } if (overlayCanvas != null) { overlayCanvas.GetComponent().alpha = 0.0f; } mapCanvas.GetComponent().alpha = 1.0f; m_RectTransform = mapPanel.GetComponent(); m_RectTransform.localScale += new Vector3(0, 0, 0); mmwidth = m_RectTransform.rect.width; mmoffsetx = 10; mmoffsety = 10; switch (mapPosition) { case MAPPOSITION.BottomLeft: m_RectTransform.anchoredPosition = new Vector3(mmoffsetx, mmoffsety); break; case MAPPOSITION.TopLeft: m_RectTransform.anchoredPosition = new Vector3(mmoffsetx, Screen.height - (mmwidth + mmoffsety)); break; case MAPPOSITION.TopRight: m_RectTransform.anchoredPosition = new Vector3(Screen.width - (mmwidth + mmoffsetx), Screen.height - (mmwidth + mmoffsety)); break; case MAPPOSITION.BottomRight: m_RectTransform.anchoredPosition = new Vector3(Screen.width - (mmwidth + mmoffsetx), mmoffsety); break; } if (updateMarkersM == true) { foreach(GameObject gameObj in Resources.FindObjectsOfTypeAll()) { if(gameObj.name == "MapMarkerImage") { gameObj.transform.localScale = new Vector3(markerSizeM, markerSizeM, markerSizeM); gameObj.SetActive(showMarkersM); } } } targetCamera.orthographicSize = cameraSizeM; if (rotating == false) { mapPanel.GetComponentInChildren().rotating = false; } else { mapPanel.GetComponentInChildren().rotating = true; } } void ShowFullScreenMap() { GameObject go = GameObject.Find("MiniMapCamera"); if (go) { img = null; targetCamera = null; renderTexture = null; Destroy(go.gameObject); } if (renderTexture != null) { renderTexture.Release(); rt = (RectTransform)rawImage.transform; renderTexture = new RenderTexture((int)Screen.width, (int)Screen.height, 32); renderTexture.Create(); } if (img == null) { img = rawImage.gameObject.GetComponent(); img.texture = renderTexture; } m_RectTransform = mapPanel.GetComponent(); m_RectTransform.localScale += new Vector3(0, 0, 0); mmwidth = m_RectTransform.rect.width; mapCanvas.GetComponent().alpha = 0.0f; if (overlay == true && overlayCanvas != null ) { if (overlayMap == true) { overlayCanvas.GetComponent().alpha = 1.0f; } else { overlayCanvas.GetComponent().alpha = 0.0f; } } if (targetCamera == null) { GameObject cameraMinimap = new GameObject(); if (lockMap == false) { cameraMinimap.transform.parent = player.transform; } targetCamera = cameraMinimap.AddComponent(); targetCamera.enabled = true; targetCamera.allowHDR = false; targetCamera.targetTexture = renderTexture; targetCamera.orthographic = true; targetCamera.orthographicSize = cameraSizeF; targetCamera.name = "MiniMapCamera"; targetCamera.cullingMask = this.cullingMaskfm; targetCamera.useOcclusionCulling = occlusionCullingfm; targetCamera.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + cameraDistanceF, player.transform.position.z); targetCamera.transform.localRotation = Quaternion.Euler(90.0f,0.0f,0.0f); targetCamera.transform.LookAt(player.transform); if (centerMap == true) { if (mapCenter != null) targetCamera.transform.position = new Vector3(mapCenter.transform.position.x, mapCenter.transform.position.y + cameraDistanceF, mapCenter.transform.position.z); } } if (updateMarkersF == true) { foreach(GameObject gameObj in Resources.FindObjectsOfTypeAll()) { if(gameObj.name == "MapMarkerImage") { gameObj.transform.localScale = new Vector3(markerSizeF, markerSizeF, markerSizeF); gameObj.SetActive(showMarkersF); } } } } } }