123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697 |
- using System;
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- namespace CompassNavigatorPro {
- public enum MINIMAP_STYLE {
- TornPaper = 0,
- SolidBox = 1,
- SolidCircle = 2,
- Custom = 100
- }
- public enum MINIMAP_LOCATION {
- TopLeft,
- TopCenter,
- TopRight,
- MiddleLeft,
- MiddleCenter,
- MiddleRight,
- BottomLeft,
- BottomCenter,
- BottomRight,
- Custom
- }
- public enum MINIMAP_CAMERA_MODE {
- Perspective = 0,
- Orthographic = 1
- }
- public enum MINIMAP_CAMERA_SNAPSHOT_FREQUENCY {
- Continuous = 0,
- TimeInterval = 1,
- DistanceTravelled = 2
- }
- public partial class CompassPro : MonoBehaviour {
- #region Events
- /// <summary>
- /// Event fired when this POI appears in the Mini-Map.
- /// </summary>
- public Action<CompassProPOI> OnPOIVisibleInMiniMap;
- /// <summary>
- /// Event fired when the POI disappears from the Mini-Map
- /// </summary>
- public Action<CompassProPOI> OnPOIHidesInMiniMap;
- #endregion
- #region Public MiniMap properties
- [SerializeField]
- bool _showMiniMap = false;
- /// <summary>
- /// Show/Hide minimap
- /// </summary>
- public bool showMiniMap {
- get { return _showMiniMap; }
- set {
- if (value != _showMiniMap) {
- _showMiniMap = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- MINIMAP_LOCATION _miniMapLocation = MINIMAP_LOCATION.BottomRight;
- /// <summary>
- /// Minimap screen location
- /// </summary>
- public MINIMAP_LOCATION miniMapLocation {
- get { return _miniMapLocation; }
- set {
- if (value != _miniMapLocation) {
- _miniMapLocation = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- Vector2 _miniMapLocationOffset;
- /// <summary>
- /// Minimap screen location offset
- /// </summary>
- public Vector2 miniMapLocationOffset {
- get { return _miniMapLocationOffset; }
- set {
- if (value != _miniMapLocationOffset) {
- _miniMapLocationOffset = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _miniMapKeepStraight = false;
- /// <summary>
- /// Keep the mini-map oriented to North
- /// </summary>
- public bool miniMapKeepStraight {
- get { return _miniMapKeepStraight; }
- set {
- if (value != _miniMapKeepStraight) {
- _miniMapKeepStraight = value;
- needMiniMapShot = true;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapSize = 0.2f;
- /// <summary>
- /// The screen size of the mini-map
- /// </summary>
- public float miniMapSize {
- get { return _miniMapSize; }
- set {
- if (value != _miniMapSize) {
- _miniMapSize = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- /// <summary>
- /// Where to center the mini map
- /// </summary>
- public Transform miniMapFollow;
- /// <summary>
- /// Optional mini-map mask texture
- /// </summary>
- [SerializeField]
- Sprite _miniMapMaskSprite;
- /// <summary>
- /// The sprite for the mini-map mask
- /// </summary>
- public Sprite miniMapMaskSprite {
- get { return _miniMapMaskSprite; }
- set {
- if (value != _miniMapMaskSprite) {
- _miniMapMaskSprite = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- /// <summary>
- /// Optional mini-map border texture
- /// </summary>
- [SerializeField]
- Texture2D _miniMapBorderTexture;
- /// <summary>
- /// Show/Hide minimap
- /// </summary>
- public Texture2D miniMapBorderTexture {
- get { return _miniMapBorderTexture; }
- set {
- if (value != _miniMapBorderTexture) {
- _miniMapBorderTexture = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- /// <summary>
- /// Style for the mini-map
- /// </summary>
- [SerializeField]
- MINIMAP_STYLE _miniMapStyle = MINIMAP_STYLE.TornPaper;
- /// <summary>
- /// Style of mini-map
- /// </summary>
- public MINIMAP_STYLE miniMapStyle {
- get { return _miniMapStyle; }
- set {
- if (value != _miniMapStyle) {
- _miniMapStyle = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- int _miniMapResolutionNormalSize = 256;
- /// <summary>
- /// The capture resolution when minimap is in full-screen mode.
- /// </summary>
- public int miniMapResolutionNormalSize {
- get { return _miniMapResolutionNormalSize; }
- set {
- if (value != _miniMapResolutionNormalSize) {
- _miniMapResolutionNormalSize = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapFullScreenSize = 0.9f;
- /// <summary>
- /// The percentage of screen size when minimap is in full screen mode.
- /// </summary>
- public float miniMapFullScreenSize {
- get { return _miniMapFullScreenSize; }
- set {
- if (value != _miniMapFullScreenSize) {
- _miniMapFullScreenSize = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _miniMapKeepAspectRatio = true;
- /// <summary>
- /// Keep aspect ration in full screen mode
- /// </summary>
- public bool miniMapKeepAspectRatio {
- get { return _miniMapKeepAspectRatio; }
- set {
- if (value != _miniMapKeepAspectRatio) {
- _miniMapKeepAspectRatio = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _miniMapDisableMainCameraInFullScreen = true;
- /// <summary>
- /// Keep aspect ration in full screen mode
- /// </summary>
- public bool miniMapDisableMainCameraInFullScreen {
- get { return _miniMapDisableMainCameraInFullScreen; }
- set {
- if (value != _miniMapDisableMainCameraInFullScreen) {
- _miniMapDisableMainCameraInFullScreen = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField] MINIMAP_CAMERA_MODE _miniMapCameraMode = MINIMAP_CAMERA_MODE.Orthographic;
- /// <summary>
- /// Mini-map projection mode
- /// </summary>
- public MINIMAP_CAMERA_MODE miniMapCameraMode {
- get { return _miniMapCameraMode; }
- set {
- if (value != _miniMapCameraMode) {
- _miniMapCameraMode = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField] MINIMAP_CAMERA_SNAPSHOT_FREQUENCY _miniMapCameraSnapshotFrequency = MINIMAP_CAMERA_SNAPSHOT_FREQUENCY.DistanceTravelled;
- /// <summary>
- /// How often the mini-map camera will capture the scene
- /// </summary>
- public MINIMAP_CAMERA_SNAPSHOT_FREQUENCY miniMapCameraSnapshotFrequency {
- get { return _miniMapCameraSnapshotFrequency; }
- set {
- if (value != _miniMapCameraSnapshotFrequency) {
- _miniMapCameraSnapshotFrequency = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapCaptureSize = 256f;
- /// <summary>
- /// The orthographic camera size
- /// </summary>
- public float miniMapCaptureSize {
- get { return _miniMapCaptureSize; }
- set {
- if (value != _miniMapCaptureSize) {
- _miniMapCaptureSize = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapSnapshotInterval = 10f;
- /// <summary>
- /// The time interval between minimap camera shots
- /// </summary>
- public float miniMapSnapshotInterval {
- get { return _miniMapSnapshotInterval; }
- set {
- if (value != _miniMapSnapshotInterval) {
- _miniMapSnapshotInterval = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapSnapshotDistance = 10f;
- /// <summary>
- /// The distance interval between minimap camera shots
- /// </summary>
- public float miniMapSnapshotDistance {
- get { return _miniMapSnapshotDistance; }
- set {
- if (value != _miniMapSnapshotDistance) {
- _miniMapSnapshotDistance = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapContrast = 1.02f;
- /// <summary>
- /// Contrast of the mini-map image
- /// </summary>
- public float miniMapContrast {
- get { return _miniMapContrast; }
- set {
- if (value != _miniMapContrast) {
- _miniMapContrast = value;
- miniMapMaterialRefresh = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapBrightness = 1.05f;
- /// <summary>
- /// Brightness of the mini-map image
- /// </summary>
- public float miniMapBrightness {
- get { return _miniMapBrightness; }
- set {
- if (value != _miniMapBrightness) {
- _miniMapBrightness = value;
- miniMapMaterialRefresh = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _miniMapEnableShadows = false;
- /// <summary>
- /// Enables/disables shadow casting when rendering mini-map
- /// </summary>
- public bool miniMapEnableShadows {
- get { return _miniMapEnableShadows; }
- set {
- if (value != _miniMapEnableShadows) {
- _miniMapEnableShadows = value;
- isDirty = true;
- }
- }
- }
- [SerializeField, Range (0, 1)]
- float _miniMapZoomMin = 0.01f;
- /// <summary>
- /// The orthographic minimum size for the camera
- /// </summary>
- public float miniMapZoomMin {
- get { return _miniMapZoomMin; }
- set {
- if (value != _miniMapZoomMin) {
- _miniMapZoomMin = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField, Range (0, 1)]
- float _miniMapZoomMax = 1f;
- /// <summary>
- /// The orthographic maximum size for the camera
- /// </summary>
- public float miniMapZoomMax {
- get { return _miniMapZoomMax; }
- set {
- if (value != _miniMapZoomMax) {
- _miniMapZoomMax = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField, Range (0, 1f)]
- float _miniMapZoomLevel = 0.5f;
- /// <summary>
- /// The current mini-map zoom based on the min/max size (orthographic mode) or altitude (perspective mode)
- /// </summary>
- public float miniMapZoomLevel {
- get { return _miniMapZoomLevel; }
- set {
- if (value != _miniMapZoomLevel) {
- _miniMapZoomLevel = Mathf.Clamp01 (value);
- needMiniMapShot = true;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapCameraMinAltitude = 10;
- /// <summary>
- /// The min distance from the camera to the following target
- /// </summary>
- public float miniMapCameraMinAltitude {
- get { return _miniMapCameraMinAltitude; }
- set {
- if (value != _miniMapCameraMinAltitude) {
- _miniMapCameraMinAltitude = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapCameraMaxAltitude = 100f;
- /// <summary>
- /// The max distance from the camera to the following target
- /// </summary>
- public float miniMapCameraMaxAltitude {
- get { return _miniMapCameraMaxAltitude; }
- set {
- if (value != _miniMapCameraMaxAltitude) {
- _miniMapCameraMaxAltitude = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapCameraHeightVSFollow = 200f;
- /// <summary>
- /// When mini-map is in orthographic projection, an optional height for the camera with respect to the main camera or followed item
- /// </summary>
- public float miniMapCameraHeightVSFollow {
- get { return _miniMapCameraHeightVSFollow; }
- set {
- if (value != _miniMapCameraHeightVSFollow) {
- _miniMapCameraHeightVSFollow = value;
- needUpdateBarContents = true;
- needMiniMapShot = true;
- isDirty = true;
- }
- }
- }
- [SerializeField] int _miniMapLayerMask = -1;
- /// <summary>
- /// The layer mask for the mini-map camera
- /// </summary>
- public int miniMapLayerMask {
- get { return _miniMapLayerMask; }
- set {
- if (value != _miniMapLayerMask) {
- _miniMapLayerMask = value;
- SetupMiniMap ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapIconSize = 0.5f;
- /// <summary>
- /// The size for the icons on the mini-map
- /// </summary>
- public float miniMapIconSize {
- get { return _miniMapIconSize; }
- set {
- if (value != _miniMapIconSize) {
- _miniMapIconSize = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapClampBorder = 0.02f;
- /// <summary>
- /// The distance to the edge for the clamped icons on the minimap
- /// </summary>
- public float miniMapClampBorder {
- get { return _miniMapClampBorder; }
- set {
- if (value != _miniMapClampBorder) {
- _miniMapClampBorder = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _miniMapAlpha = 1.0f;
- /// <summary>
- /// The alpha (transparency) of the mini-map.
- /// </summary>
- public float miniMapAlpha {
- get { return _miniMapAlpha; }
- set {
- if (value != _miniMapAlpha) {
- _miniMapAlpha = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _miniMapShowButtons;
- public bool miniMapShowButtons {
- get { return _miniMapShowButtons; }
- set {
- if (value != _miniMapShowButtons) {
- _miniMapShowButtons = value;
- isDirty = true;
- SetupMiniMap ();
- }
- }
- }
- [SerializeField]
- bool _miniMapIconEvents;
- public bool miniMapIconEvents {
- get { return _miniMapIconEvents; }
- set {
- if (_miniMapIconEvents != value) {
- _miniMapIconEvents = value;
- }
- }
- }
- public void MiniMapZoomIn (float speed = 1f) {
- miniMapZoomLevel += Time.deltaTime * speed;
- }
- public void MiniMapZoomOut (float speed = 1f) {
- miniMapZoomLevel -= Time.deltaTime * speed;
- }
- bool _miniMapZoomState;
- /// <summary>
- /// Sets mini-map in full-screen mode or normal mode
- /// </summary>
- public bool miniMapZoomState {
- get {
- return _miniMapZoomState;
- }
- set {
- if (_miniMapZoomState != value) {
- MiniMapZoomToggle (value);
- }
- }
- }
- /// <summary>
- /// Forces an update of mini-map contents
- /// </summary>
- public void UpdateMiniMapContents () {
- needMiniMapShot = true;
- needUpdateBarContents = true;
- }
- /// <summary>
- /// Returns true if mouse pointer is over the mini-map
- /// </summary>
- /// <returns><c>true</c> if this instance is pointer over mini map; otherwise, <c>false</c>.</returns>
- public bool IsMouseOverMiniMap () {
- if (miniMapUIRootRT == null)
- return false;
- return RectTransformUtility.RectangleContainsScreenPoint (miniMapUIRootRT, Input.mousePosition);
- }
- #endregion
-
- }
- }
|