1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- namespace CompassNavigatorPro {
- public enum COMPASS_STYLE {
- Angled = 0,
- Rounded = 1,
- Celtic_White = 2,
- Celtic_Black = 3
- }
- public enum WORLD_MAPPING_MODE {
- LimitedToBarWidth = 0,
- CameraFustrum = 1,
- Full180Degrees = 2,
- Full360Degrees = 3
- }
- public enum UPDATE_INTERVAL {
- NumberOfFrames,
- Time,
- Continuous,
- Scripting
- }
- public partial class CompassPro : MonoBehaviour {
- #region Public properties
- [SerializeField]
- Camera _cameraMain;
- public Camera cameraMain {
- get {
- if (_cameraMain == null) {
- _cameraMain = Camera.main;
- if (_cameraMain == null) {
- _cameraMain = FindObjectOfType<Camera> ();
- }
- }
- return _cameraMain;
- }
- set {
- if (_cameraMain != value) {
- _cameraMain = value;
- needUpdateBarContents = true;
- }
- }
- }
- [SerializeField]
- UPDATE_INTERVAL _updateInterval = UPDATE_INTERVAL.NumberOfFrames;
- public UPDATE_INTERVAL updateInterval {
- get { return _updateInterval; }
- set {
- if (value != _updateInterval) {
- _updateInterval = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- int _updateIntervalFrameCount = 60;
- public int updateIntervalFrameCount {
- get { return _updateIntervalFrameCount; }
- set {
- if (value != _updateIntervalFrameCount) {
- _updateIntervalFrameCount = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _updateIntervalTime = 0.2f;
- public float updateIntervalTime {
- get { return _updateIntervalTime; }
- set {
- if (value != _updateIntervalTime) {
- _updateIntervalTime = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- COMPASS_STYLE _style = COMPASS_STYLE.Celtic_White;
- public COMPASS_STYLE style {
- get { return _style; }
- set {
- if (value != _style) {
- _style = value;
- UpdateCompassBarAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- [Range (0, 360)]
- float _northDegrees = 0f;
- /// <summary>
- /// Gets or sets the North position
- /// </summary>
- public float northDegrees {
- get { return _northDegrees; }
- set {
- if (value != _northDegrees) {
- _northDegrees = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _visibleDistance = 500f;
- /// <summary>
- /// Gets or sets the maximum distance to a POI so it's visible in the compass bar.
- /// </summary>
- public float visibleDistance {
- get { return _visibleDistance; }
- set {
- if (value != _visibleDistance) {
- _visibleDistance = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _nearDistance = 75f;
- /// <summary>
- /// Gets or sets the distance to a POI where the icon will start to grow as player approaches.
- /// </summary>
- public float nearDistance {
- get { return _nearDistance; }
- set {
- if (value != _nearDistance) {
- _nearDistance = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _visitedDistance = 25f;
- /// <summary>
- /// Gets or sets the minimum distance required to consider a POI as visited. Once the player gets near this POI below this distance, the POI will be marked as visited.
- /// </summary>
- public float visitedDistance {
- get { return _visitedDistance; }
- set {
- if (value != _visitedDistance) {
- _visitedDistance = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _gizmoScale = 0.25f;
- /// <summary>
- /// Gets or sets the gizmo scale during playmode.
- /// </summary>
- public float gizmoScale {
- get { return _gizmoScale; }
- set {
- if (value != _gizmoScale) {
- _gizmoScale = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _alpha = 1.0f;
- /// <summary>
- /// The alpha (transparency) of the compass bar. Setting this value will make the bar shift smoothly from current alpha to the new value (see fadeDuration).
- /// </summary>
- public float alpha {
- get { return _alpha; }
- set {
- if (value != _alpha) {
- _alpha = value;
- UpdateCompassBarAlpha ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _autoHide = false;
- /// <summary>
- /// If no POIs are below the visible distance param, hide the compass bar
- /// </summary>
- public bool autoHide {
- get { return _autoHide; }
- set {
- if (value != _autoHide) {
- _autoHide = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _fadeDuration = 2.0f;
- /// <summary>
- /// Sets the duration for any alpha change.
- /// </summary>
- public float fadeDuration {
- get { return _fadeDuration; }
- set {
- if (value != _fadeDuration) {
- _fadeDuration = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _alwaysVisibleInEditMode = true;
- /// <summary>
- /// Set this value to true to make the compass bar always visible in Edit Mode (ignores alpha property while editing).
- /// </summary>
- public bool alwaysVisibleInEditMode {
- get { return _alwaysVisibleInEditMode; }
- set {
- if (value != _alwaysVisibleInEditMode) {
- _alwaysVisibleInEditMode = value;
- UpdateCompassBarAlpha ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _verticalPosition = 0.97f;
- /// <summary>
- /// Distance in % of the screen from the bottom edge of the screen.
- /// </summary>
- public float verticalPosition {
- get { return _verticalPosition; }
- set {
- if (value != _verticalPosition) {
- _verticalPosition = value;
- UpdateCompassBarAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _bendAmount = 0f;
- /// <summary>
- /// Bending amount
- /// </summary>
- public float bendFactor {
- get { return _bendAmount; }
- set {
- if (value != _bendAmount) {
- _bendAmount = value;
- if (_bendAmount == 0) {
- _verticalPosition = 0.94f;
- }
- UpdateCompassBarAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _width = 0.65f;
- /// <summary>
- /// Width of the compass bar in % of the screen width.
- /// </summary>
- public float width {
- get { return _width; }
- set {
- if (value != _width) {
- _width = value;
- UpdateCompassBarAppearance ();
- UpdateHalfWindsAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _edgeFadeOutWidth = 0;
- /// <summary>
- /// Width of the edge fade out
- /// </summary>
- public float edgeFadeOutWidth {
- get { return _edgeFadeOutWidth; }
- set {
- if (value != _edgeFadeOutWidth) {
- _edgeFadeOutWidth = value;
- UpdateCompassBarAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _edgeFadeOutStart = 0;
- /// <summary>
- /// Start of the edge fade out
- /// </summary>
- public float edgeFadeOutStart {
- get { return _edgeFadeOutStart; }
- set {
- if (value != _edgeFadeOutStart) {
- _edgeFadeOutStart = value;
- UpdateCompassBarAppearance ();
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- float _endCapsWidth = 54f;
- /// <summary>
- /// Width of the end caps for the compass bar.
- /// </summary>
- public float endCapsWidth {
- get { return _endCapsWidth; }
- set {
- if (value != _endCapsWidth) {
- _endCapsWidth = value;
- UpdateCompassBarAppearance ();
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- bool _showCardinalPoints = true;
- /// <summary>
- /// Whether cardinal points (N, W, S, E) should be visible in the compass bar
- /// </summary>
- public bool showCardinalPoints {
- get { return _showCardinalPoints; }
- set {
- if (value != _showCardinalPoints) {
- _showCardinalPoints = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _showOrdinalPoints = false;
- /// <summary>
- /// Whether intercadinal (or ordinal) points (NE, NW, SW, SE) should be visible in the compass bar
- /// </summary>
- public bool showOrdinalPoints {
- get { return _showOrdinalPoints; }
- set {
- if (value != _showOrdinalPoints) {
- _showOrdinalPoints = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _cardinalPointsVerticalOffset = 0;
- /// <summary>
- /// Optional vertical offset for compass cardinal/ordinal points
- /// </summary>
- public float cardinalPointsVerticalOffset {
- get { return _cardinalPointsVerticalOffset; }
- set {
- if (value != _cardinalPointsVerticalOffset) {
- _cardinalPointsVerticalOffset = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- bool _showHalfWinds = false;
- /// <summary>
- /// Whether bar ticks should be visible
- /// </summary>
- public bool showHalfWinds {
- get { return _showHalfWinds; }
- set {
- if (value != _showHalfWinds) {
- _showHalfWinds = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
-
- [SerializeField, Range (0.1f, 1f)]
- float _halfWindsHeight = 0.33f;
- /// <summary>
- /// The compass bar ticks height.
- /// </summary>
- public float halfWindsHeight {
- get { return _halfWindsHeight; }
- set {
- if (value != _halfWindsHeight) {
- _halfWindsHeight = value;
- UpdateHalfWindsAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField, Range (1f, 5f)]
- float _halfWindsWidth = 1f;
- /// <summary>
- /// The compass bar ticks width.
- /// </summary>
- public float halfWindsWidth {
- get { return _halfWindsWidth; }
- set {
- if (value != _halfWindsWidth) {
- _halfWindsWidth = value;
- UpdateHalfWindsAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- Color _halfWindsTintColor = new Color (1f, 1f, 1f, 0.5f);
- /// <summary>
- /// The compass bar ticks tint color.
- /// </summary>
- public Color halfWindsTintColor {
- get { return _halfWindsTintColor; }
- set {
- if (value != _halfWindsTintColor) {
- _halfWindsTintColor = value;
- UpdateHalfWindsAppearance ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _labelHotZone = 0.01f;
- /// <summary>
- /// The distance from the center of the compass bar where a POI label can be shown.
- /// </summary>
- public float labelHotZone {
- get { return _labelHotZone; }
- set {
- if (value != _labelHotZone) {
- _labelHotZone = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _maxIconSize = 1.15f;
- /// <summary>
- /// Maximum icon size. Icons grow or shrinks in the compass bar depending on distance.
- /// </summary>
- public float maxIconSize {
- get { return _maxIconSize; }
- set {
- if (value != _maxIconSize) {
- _maxIconSize = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _minIconSize = 0.5f;
- /// <summary>
- /// Minimum icon size. Icons grow or shrinks in the compass bar depending on distance.
- /// </summary>
- public float minIconSize {
- get { return _minIconSize; }
- set {
- if (value != _minIconSize) {
- _minIconSize = value;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- float _scaleInDuration = 0.3f;
- /// <summary>
- /// Duration for the poi's icon scaling effect when it appears on the compass bar
- /// </summary>
- public float scaleInDuration {
- get { return _scaleInDuration; }
- set {
- if (value != _scaleInDuration) {
- _scaleInDuration = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- WORLD_MAPPING_MODE _worldMappingMode = WORLD_MAPPING_MODE.CameraFustrum;
- /// <summary>
- /// Set this value to true to consider the width of the bar equal to the width of the viewport so the angle is not reduced.
- /// </summary>
- public WORLD_MAPPING_MODE worldMappingMode {
- get { return _worldMappingMode; }
- set {
- if (value != _worldMappingMode) {
- _worldMappingMode = value;
- needUpdateBarContents = true;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textVerticalPosition = -30;
- /// <summary>
- /// Vertical offset for the text of POIs when visited for first time
- /// </summary>
- public float textVerticalPosition {
- get { return _textVerticalPosition; }
- set {
- if (value != _textVerticalPosition) {
- _textVerticalPosition = value;
- UpdateTextAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textScale = 0.2f;
- /// <summary>
- /// Scaling applied to text
- /// </summary>
- public float textScale {
- get { return _textScale; }
- set {
- if (value != _textScale) {
- _textScale = value;
- UpdateTextAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- bool _textRevealEnabled = true;
- /// <summary>
- /// Enabled text revealing effect when discovering a POI for the first time
- /// </summary>
- public bool textRevealEnabled {
- get { return _textRevealEnabled; }
- set {
- if (value != _textRevealEnabled) {
- _textRevealEnabled = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textRevealDuration = 0.5f;
- /// <summary>
- /// Duration of the text reveal
- /// </summary>
- public float textRevealDuration {
- get { return _textRevealDuration; }
- set {
- if (value != _textRevealDuration) {
- _textRevealDuration = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textRevealLetterDelay = 0.05f;
- /// <summary>
- /// Delay in appearance of each letter during a text reveal
- /// </summary>
- public float textRevealLetterDelay {
- get { return _textRevealLetterDelay; }
- set {
- if (value != _textRevealLetterDelay) {
- _textRevealLetterDelay = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textDuration = 5f;
- /// <summary>
- /// Duration of the text on screen before fading out
- /// </summary>
- public float textDuration {
- get { return _textDuration; }
- set {
- if (value != _textDuration) {
- _textDuration = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- float _textFadeOutDuration = 2f;
- /// <summary>
- /// Duration of the text fade out
- /// </summary>
- public float textFadeOutDuration {
- get { return _textFadeOutDuration; }
- set {
- if (value != _textFadeOutDuration) {
- _textFadeOutDuration = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _textShadowEnabled = true;
- /// <summary>
- /// Shows a drop shadow under the text
- /// </summary>
- public bool textShadowEnabled {
- get { return _textShadowEnabled; }
- set {
- if (value != _textShadowEnabled) {
- _textShadowEnabled = value;
- if (!Application.isPlaying) {
- UpdateTextAppearanceEditMode ();
- }
- isDirty = true;
- }
- }
- }
- [SerializeField]
- Font _textFont;
- /// <summary>
- /// Font for the text
- /// </summary>
- public Font textFont {
- get {
- if (_textFont == null) {
- _textFont = Resources.Load<Font> ("CNPro/Fonts/Vollkorn-Regular");
- }
- return _textFont;
- }
- set {
- if (value != _textFont) {
- _textFont = value;
- UpdateTextAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- float _titleVerticalPosition = 18f;
- /// <summary>
- /// Vertical offset for the title of the (visited/known) centered POI in the compass bar
- /// </summary>
- public float titleVerticalPosition {
- get { return _titleVerticalPosition; }
- set {
- if (value != _titleVerticalPosition) {
- _titleVerticalPosition = value;
- UpdateTitleAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- float _titleScale = 0.1f;
- /// <summary>
- /// Scaling applied to title
- /// </summary>
- public float titleScale {
- get { return _titleScale; }
- set {
- if (value != _titleScale) {
- _titleScale = value;
- UpdateTitleAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- Font _titleFont;
- /// <summary>
- /// Font for the title
- /// </summary>
- public Font titleFont {
- get {
- if (_titleFont == null) {
- _titleFont = Resources.Load<Font> ("CNPro/Fonts/Actor-Regular");
- }
- return _titleFont;
- }
- set {
- if (value != _titleFont) {
- _titleFont = value;
- UpdateTitleAppearanceEditMode ();
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _titleShadowEnabled = true;
- /// <summary>
- /// Shows a drop shadow under the title
- /// </summary>
- public bool titleShadowEnabled {
- get { return _titleShadowEnabled; }
- set {
- if (value != _titleShadowEnabled) {
- _titleShadowEnabled = value;
- if (!Application.isPlaying) {
- UpdateTitleAppearanceEditMode ();
- }
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _use3Ddistance = false;
- /// <summary>
- /// Check whether 3D distance should be computed instead of planar X/Z distance.
- /// </summary>
- public bool use3Ddistance {
- get { return _use3Ddistance; }
- set {
- if (value != _use3Ddistance) {
- _use3Ddistance = value;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- float _sameAltitudeThreshold = 3f;
- /// <summary>
- /// Minimum difference in altitude from camera to show "above" or "below"
- /// </summary>
- public float sameAltitudeThreshold {
- get { return _sameAltitudeThreshold; }
- set {
- if (value != _sameAltitudeThreshold) {
- _sameAltitudeThreshold = value;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- bool _showDistance = false;
- /// <summary>
- /// Whether the distance in meters should be shown next to the title
- /// </summary>
- public bool showDistance {
- get { return _showDistance; }
- set {
- if (value != _showDistance) {
- _showDistance = value;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- string _showDistanceFormat = "F1";
- /// <summary>
- /// The string format for displaying the distance. A value of F0 means "Fixed/Decimal with 0 decimal positions". A value of F1 includes 1 decimal position.
- /// This string format corresponds with the available options for ToString(format) method of C#.
- /// </summary>
- public string showDistanceFormat {
- get { return _showDistanceFormat; }
- set {
- if (value != _showDistanceFormat) {
- _showDistanceFormat = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- AudioClip _visitedDefaultAudioClip;
- /// <summary>
- /// Default audio clip to play when a POI is visited the first time. Note that you can specify a different audio clip in the POI script itself.
- /// </summary>
- public AudioClip visitedDefaultAudioClip {
- get { return _visitedDefaultAudioClip; }
- set {
- if (value != _visitedDefaultAudioClip) {
- _visitedDefaultAudioClip = value;
- isDirty = true;
- }
- }
- }
-
- [SerializeField]
- AudioClip _beaconDefaultAudioClip;
- /// <summary>
- /// Default audio clip to play when a POI beacon is shown (see manual for more info about POI beacons).
- /// </summary>
- public AudioClip beaconDefaultAudioClip {
- get { return _beaconDefaultAudioClip; }
- set {
- if (value != _beaconDefaultAudioClip) {
- _beaconDefaultAudioClip = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- AudioClip _heartbeatDefaultAudioClip;
- /// <summary>
- /// Default audio clip to play for the heartbeat effect. This effect is enabled on each POI and will play a custom sound with variable speed depending on distance.
- /// </summary>
- public AudioClip heartbeatDefaultAudioClip {
- get { return _heartbeatDefaultAudioClip; }
- set {
- if (value != _heartbeatDefaultAudioClip) {
- _heartbeatDefaultAudioClip = value;
- isDirty = true;
- }
- }
- }
- [SerializeField]
- bool _dontDestroyOnLoad;
- /// <summary>
- /// Preserves compass bar between scene changes
- /// </summary>
- public bool dontDestroyOnLoad {
- get { return _dontDestroyOnLoad; }
- set {
- if (value != _dontDestroyOnLoad) {
- _dontDestroyOnLoad = value;
- isDirty = true;
- }
- }
- }
- #endregion
- #region Events
- /// <summary>
- /// Event fired when this POI is visited.
- /// </summary>
- public Action<CompassProPOI> OnPOIVisited;
- /// <summary>
- /// Event fired when the POI appears in the compass bar (gets near than the visible distance)
- /// </summary>
- public Action<CompassProPOI> OnPOIVisible;
- /// <summary>
- /// Event fired when POI disappears from the compass bar (gets farther than the visible distance)
- /// </summary>
- public Action<CompassProPOI> OnPOIHide;
- /// <summary>
- /// Event fired when mouse enters an icon on the miniMap
- /// </summary>
- public Action<CompassProPOI> OnPOIMiniMapIconMouseEnter;
- /// <summary>
- /// Event fired when mouse exits an icon on the miniMap
- /// </summary>
- public Action<CompassProPOI> OnPOIMiniMapIconMouseExit;
- /// <summary>
- /// Event fired when button is pressed on an icon on the miniMap
- /// </summary>
- public Action<CompassProPOI> OnPOIMiniMapIconMouseDown;
- /// <summary>
- /// Event fired when button is released on an icon on the miniMap
- /// </summary>
- public Action<CompassProPOI> OnPOIMiniMapIconMouseUp;
- /// <summary>
- /// Event fired when an icon is clicked on the minimap
- /// </summary>
- public Action<CompassProPOI> OnPOIMiniMapIconMouseClick;
- #endregion
- #region Public API
- /// <summary>
- /// Gets a reference to the Compass API.
- /// </summary>
- public static CompassPro instance {
- get {
- if (_instance == null) {
- _instance = FindObjectOfType<CompassPro> ();
- }
- return _instance;
- }
- }
- /// <summary>
- /// Call this to force a refresh of contents
- /// </summary>
- public void Refresh () {
- needUpdateBarContents = true;
- }
- /// <summary>
- /// Used to add a POI to the compass. Returns false if POI is already registered.
- /// </summary>
- public bool POIRegister (CompassProPOI newPOI) {
- for (int k = 0; k < icons.Count; k++) {
- if (icons [k].poi == newPOI) {
- return false;
- }
- }
- CompassActiveIcon newIcon = new CompassActiveIcon (newPOI);
- icons.Add (newIcon);
- return true;
- }
- /// <summary>
- /// Returns whether the POI is currently registered.
- /// </summary>
- public bool POIisRegistered (CompassProPOI poi) {
- for (int k = 0; k < icons.Count; k++) {
- if (icons [k].poi.id == poi.id) {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// Call this method to remove a POI from the compass.
- /// </summary>
- public void POIUnregister (CompassProPOI newPOI) {
- for (int k = 0; k < icons.Count; k++) {
- if (icons [k].poi == newPOI) {
- if (icons [k].rectTransform != null && icons [k].rectTransform.gameObject != null)
- DestroyImmediate (icons [k].rectTransform.gameObject);
- icons.RemoveAt (k);
- break;
- }
- }
- }
- /// <summary>
- /// Shows given POI as gizmo in the scene and makes its icon always visible in the compass bar
- /// </summary>
- public void POIFocus (CompassProPOI existingPOI) {
- for (int k = 0; k < icons.Count; k++) {
- if (icons [k].poi == existingPOI) {
- icons [k].poi.showPlayModeGizmo = true;
- icons [k].poi.clampPosition = true;
- } else if (icons [k].poi != null) {
- icons [k].poi.showPlayModeGizmo = false;
- icons [k].poi.clampPosition = false;
- }
- }
- }
- /// <summary>
- /// Clears all gizmos and unfocus any focused POI.
- /// </summary>
- public void POIBlur () {
- for (int k = 0; k < icons.Count; k++) {
- if (icons [k].poi != null) {
- icons [k].poi.showPlayModeGizmo = false;
- icons [k].poi.clampPosition = false;
- }
- }
- }
- /// <summary>
- /// Show a light beacon over the specified POI.
- /// </summary>
- public void POIShowBeacon (CompassProPOI existingPOI, float duration, float horizontalScale = 1f) {
- POIShowBeacon (existingPOI, duration, horizontalScale, 1f, Color.white);
- }
- /// <summary>
- /// Show a light beacon over the specified POI.
- /// </summary>
- public void POIShowBeacon (CompassProPOI existingPOI, float duration, float horizontalScale, float intensity, Color tintColor) {
- Transform beacon = existingPOI.transform.Find ("POIBeacon");
- if (beacon != null)
- return;
- GameObject beaconObj = Instantiate (Resources.Load<GameObject> ("CNPro/Prefabs/POIBeacon"));
- beaconObj.name = "POIBeacon";
- beaconObj.hideFlags = HideFlags.DontSave;
- beacon = beaconObj.transform;
- beacon.localScale = new Vector3 (beacon.localScale.x * horizontalScale, beacon.localScale.y, beacon.localScale.z);
- beacon.position = existingPOI.transform.position + Misc.Vector3up * beacon.transform.localScale.y * 0.5f;
- beacon.SetParent (existingPOI.transform, true);
- BeaconAnimator anim = beacon.gameObject.GetComponent<BeaconAnimator> ();
- anim.duration = duration;
- anim.tintColor = tintColor;
- anim.intensity = intensity;
- if (audioSource != null) {
- if (existingPOI.beaconAudioClip != null) {
- audioSource.PlayOneShot (existingPOI.beaconAudioClip);
- } else if (_beaconDefaultAudioClip != null) {
- audioSource.PlayOneShot (_beaconDefaultAudioClip);
- }
- }
- }
- /// <summary>
- /// Show a light beacon over all non-visited POIs for duration in seconds and with optional custom horizontal scale for the bright cylinder.
- /// </summary>
- public void POIShowBeacon (float duration, float horizontalScale = 1f) {
- POIShowBeacon (duration, horizontalScale, 1f, Color.white);
- }
- /// <summary>
- /// Show a light beacon over all non-visited POIs for duration in seconds and with optional custom horizontal scale for the bright cylinder.
- /// </summary>
- public void POIShowBeacon (float duration, float horizontalScale, float intensity, Color tintColor) {
- for (int k = 0; k < icons.Count; k++) {
- CompassActiveIcon icon = icons [k];
- if (icon == null || icon.poi.isVisited || !icon.poi.isVisible)
- continue;
- POIShowBeacon (icon.poi, duration, horizontalScale, intensity, tintColor);
- }
- }
-
- /// <summary>
- /// Initiates a fade in effect with duration in seconds.
- /// </summary>
- public void FadeIn (float duration) {
- fadeDuration = duration;
- fadeStartTime = Time.time;
- prevAlpha = canvasGroup.alpha;
- alpha = 1f;
- }
- /// <summary>
- /// Initiates a fade out effect with duration in seconds.
- /// </summary>
- public void FadeOut (float duration) {
- fadeDuration = duration;
- fadeStartTime = Time.time;
- prevAlpha = canvasGroup.alpha;
- alpha = 0f;
- }
- public void ShowAnimatedText (string text) {
- StartCoroutine (AnimateDiscoverText (text));
- }
- public Canvas canvas {
- get {
- return _canvas;
- }
- }
- #endregion
-
- }
- }
|