CompassPro.cs 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. namespace CompassNavigatorPro {
  6. public enum COMPASS_STYLE {
  7. Angled = 0,
  8. Rounded = 1,
  9. Celtic_White = 2,
  10. Celtic_Black = 3
  11. }
  12. public enum WORLD_MAPPING_MODE {
  13. LimitedToBarWidth = 0,
  14. CameraFustrum = 1,
  15. Full180Degrees = 2,
  16. Full360Degrees = 3
  17. }
  18. public enum UPDATE_INTERVAL {
  19. NumberOfFrames,
  20. Time,
  21. Continuous,
  22. Scripting
  23. }
  24. public partial class CompassPro : MonoBehaviour {
  25. #region Public properties
  26. [SerializeField]
  27. Camera _cameraMain;
  28. public Camera cameraMain {
  29. get {
  30. if (_cameraMain == null) {
  31. _cameraMain = Camera.main;
  32. if (_cameraMain == null) {
  33. _cameraMain = FindObjectOfType<Camera> ();
  34. }
  35. }
  36. return _cameraMain;
  37. }
  38. set {
  39. if (_cameraMain != value) {
  40. _cameraMain = value;
  41. needUpdateBarContents = true;
  42. }
  43. }
  44. }
  45. [SerializeField]
  46. UPDATE_INTERVAL _updateInterval = UPDATE_INTERVAL.NumberOfFrames;
  47. public UPDATE_INTERVAL updateInterval {
  48. get { return _updateInterval; }
  49. set {
  50. if (value != _updateInterval) {
  51. _updateInterval = value;
  52. isDirty = true;
  53. }
  54. }
  55. }
  56. [SerializeField]
  57. int _updateIntervalFrameCount = 60;
  58. public int updateIntervalFrameCount {
  59. get { return _updateIntervalFrameCount; }
  60. set {
  61. if (value != _updateIntervalFrameCount) {
  62. _updateIntervalFrameCount = value;
  63. isDirty = true;
  64. }
  65. }
  66. }
  67. [SerializeField]
  68. float _updateIntervalTime = 0.2f;
  69. public float updateIntervalTime {
  70. get { return _updateIntervalTime; }
  71. set {
  72. if (value != _updateIntervalTime) {
  73. _updateIntervalTime = value;
  74. isDirty = true;
  75. }
  76. }
  77. }
  78. [SerializeField]
  79. COMPASS_STYLE _style = COMPASS_STYLE.Celtic_White;
  80. public COMPASS_STYLE style {
  81. get { return _style; }
  82. set {
  83. if (value != _style) {
  84. _style = value;
  85. UpdateCompassBarAppearance ();
  86. isDirty = true;
  87. }
  88. }
  89. }
  90. [SerializeField]
  91. [Range (0, 360)]
  92. float _northDegrees = 0f;
  93. /// <summary>
  94. /// Gets or sets the North position
  95. /// </summary>
  96. public float northDegrees {
  97. get { return _northDegrees; }
  98. set {
  99. if (value != _northDegrees) {
  100. _northDegrees = value;
  101. needUpdateBarContents = true;
  102. isDirty = true;
  103. }
  104. }
  105. }
  106. [SerializeField]
  107. float _visibleDistance = 500f;
  108. /// <summary>
  109. /// Gets or sets the maximum distance to a POI so it's visible in the compass bar.
  110. /// </summary>
  111. public float visibleDistance {
  112. get { return _visibleDistance; }
  113. set {
  114. if (value != _visibleDistance) {
  115. _visibleDistance = value;
  116. isDirty = true;
  117. }
  118. }
  119. }
  120. [SerializeField]
  121. float _nearDistance = 75f;
  122. /// <summary>
  123. /// Gets or sets the distance to a POI where the icon will start to grow as player approaches.
  124. /// </summary>
  125. public float nearDistance {
  126. get { return _nearDistance; }
  127. set {
  128. if (value != _nearDistance) {
  129. _nearDistance = value;
  130. isDirty = true;
  131. }
  132. }
  133. }
  134. [SerializeField]
  135. float _visitedDistance = 25f;
  136. /// <summary>
  137. /// 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.
  138. /// </summary>
  139. public float visitedDistance {
  140. get { return _visitedDistance; }
  141. set {
  142. if (value != _visitedDistance) {
  143. _visitedDistance = value;
  144. isDirty = true;
  145. }
  146. }
  147. }
  148. [SerializeField]
  149. float _gizmoScale = 0.25f;
  150. /// <summary>
  151. /// Gets or sets the gizmo scale during playmode.
  152. /// </summary>
  153. public float gizmoScale {
  154. get { return _gizmoScale; }
  155. set {
  156. if (value != _gizmoScale) {
  157. _gizmoScale = value;
  158. isDirty = true;
  159. }
  160. }
  161. }
  162. [SerializeField]
  163. float _alpha = 1.0f;
  164. /// <summary>
  165. /// 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).
  166. /// </summary>
  167. public float alpha {
  168. get { return _alpha; }
  169. set {
  170. if (value != _alpha) {
  171. _alpha = value;
  172. UpdateCompassBarAlpha ();
  173. isDirty = true;
  174. }
  175. }
  176. }
  177. [SerializeField]
  178. bool _autoHide = false;
  179. /// <summary>
  180. /// If no POIs are below the visible distance param, hide the compass bar
  181. /// </summary>
  182. public bool autoHide {
  183. get { return _autoHide; }
  184. set {
  185. if (value != _autoHide) {
  186. _autoHide = value;
  187. isDirty = true;
  188. }
  189. }
  190. }
  191. [SerializeField]
  192. float _fadeDuration = 2.0f;
  193. /// <summary>
  194. /// Sets the duration for any alpha change.
  195. /// </summary>
  196. public float fadeDuration {
  197. get { return _fadeDuration; }
  198. set {
  199. if (value != _fadeDuration) {
  200. _fadeDuration = value;
  201. isDirty = true;
  202. }
  203. }
  204. }
  205. [SerializeField]
  206. bool _alwaysVisibleInEditMode = true;
  207. /// <summary>
  208. /// Set this value to true to make the compass bar always visible in Edit Mode (ignores alpha property while editing).
  209. /// </summary>
  210. public bool alwaysVisibleInEditMode {
  211. get { return _alwaysVisibleInEditMode; }
  212. set {
  213. if (value != _alwaysVisibleInEditMode) {
  214. _alwaysVisibleInEditMode = value;
  215. UpdateCompassBarAlpha ();
  216. isDirty = true;
  217. }
  218. }
  219. }
  220. [SerializeField]
  221. float _verticalPosition = 0.97f;
  222. /// <summary>
  223. /// Distance in % of the screen from the bottom edge of the screen.
  224. /// </summary>
  225. public float verticalPosition {
  226. get { return _verticalPosition; }
  227. set {
  228. if (value != _verticalPosition) {
  229. _verticalPosition = value;
  230. UpdateCompassBarAppearance ();
  231. isDirty = true;
  232. }
  233. }
  234. }
  235. [SerializeField]
  236. float _bendAmount = 0f;
  237. /// <summary>
  238. /// Bending amount
  239. /// </summary>
  240. public float bendFactor {
  241. get { return _bendAmount; }
  242. set {
  243. if (value != _bendAmount) {
  244. _bendAmount = value;
  245. if (_bendAmount == 0) {
  246. _verticalPosition = 0.94f;
  247. }
  248. UpdateCompassBarAppearance ();
  249. isDirty = true;
  250. }
  251. }
  252. }
  253. [SerializeField]
  254. float _width = 0.65f;
  255. /// <summary>
  256. /// Width of the compass bar in % of the screen width.
  257. /// </summary>
  258. public float width {
  259. get { return _width; }
  260. set {
  261. if (value != _width) {
  262. _width = value;
  263. UpdateCompassBarAppearance ();
  264. UpdateHalfWindsAppearance ();
  265. isDirty = true;
  266. }
  267. }
  268. }
  269. [SerializeField]
  270. float _edgeFadeOutWidth = 0;
  271. /// <summary>
  272. /// Width of the edge fade out
  273. /// </summary>
  274. public float edgeFadeOutWidth {
  275. get { return _edgeFadeOutWidth; }
  276. set {
  277. if (value != _edgeFadeOutWidth) {
  278. _edgeFadeOutWidth = value;
  279. UpdateCompassBarAppearance ();
  280. isDirty = true;
  281. }
  282. }
  283. }
  284. [SerializeField]
  285. float _edgeFadeOutStart = 0;
  286. /// <summary>
  287. /// Start of the edge fade out
  288. /// </summary>
  289. public float edgeFadeOutStart {
  290. get { return _edgeFadeOutStart; }
  291. set {
  292. if (value != _edgeFadeOutStart) {
  293. _edgeFadeOutStart = value;
  294. UpdateCompassBarAppearance ();
  295. isDirty = true;
  296. }
  297. }
  298. }
  299. [SerializeField]
  300. float _endCapsWidth = 54f;
  301. /// <summary>
  302. /// Width of the end caps for the compass bar.
  303. /// </summary>
  304. public float endCapsWidth {
  305. get { return _endCapsWidth; }
  306. set {
  307. if (value != _endCapsWidth) {
  308. _endCapsWidth = value;
  309. UpdateCompassBarAppearance ();
  310. needUpdateBarContents = true;
  311. isDirty = true;
  312. }
  313. }
  314. }
  315. [SerializeField]
  316. bool _showCardinalPoints = true;
  317. /// <summary>
  318. /// Whether cardinal points (N, W, S, E) should be visible in the compass bar
  319. /// </summary>
  320. public bool showCardinalPoints {
  321. get { return _showCardinalPoints; }
  322. set {
  323. if (value != _showCardinalPoints) {
  324. _showCardinalPoints = value;
  325. needUpdateBarContents = true;
  326. isDirty = true;
  327. }
  328. }
  329. }
  330. [SerializeField]
  331. bool _showOrdinalPoints = false;
  332. /// <summary>
  333. /// Whether intercadinal (or ordinal) points (NE, NW, SW, SE) should be visible in the compass bar
  334. /// </summary>
  335. public bool showOrdinalPoints {
  336. get { return _showOrdinalPoints; }
  337. set {
  338. if (value != _showOrdinalPoints) {
  339. _showOrdinalPoints = value;
  340. needUpdateBarContents = true;
  341. isDirty = true;
  342. }
  343. }
  344. }
  345. [SerializeField]
  346. float _cardinalPointsVerticalOffset = 0;
  347. /// <summary>
  348. /// Optional vertical offset for compass cardinal/ordinal points
  349. /// </summary>
  350. public float cardinalPointsVerticalOffset {
  351. get { return _cardinalPointsVerticalOffset; }
  352. set {
  353. if (value != _cardinalPointsVerticalOffset) {
  354. _cardinalPointsVerticalOffset = value;
  355. needUpdateBarContents = true;
  356. isDirty = true;
  357. }
  358. }
  359. }
  360. [SerializeField]
  361. bool _showHalfWinds = false;
  362. /// <summary>
  363. /// Whether bar ticks should be visible
  364. /// </summary>
  365. public bool showHalfWinds {
  366. get { return _showHalfWinds; }
  367. set {
  368. if (value != _showHalfWinds) {
  369. _showHalfWinds = value;
  370. needUpdateBarContents = true;
  371. isDirty = true;
  372. }
  373. }
  374. }
  375. [SerializeField, Range (0.1f, 1f)]
  376. float _halfWindsHeight = 0.33f;
  377. /// <summary>
  378. /// The compass bar ticks height.
  379. /// </summary>
  380. public float halfWindsHeight {
  381. get { return _halfWindsHeight; }
  382. set {
  383. if (value != _halfWindsHeight) {
  384. _halfWindsHeight = value;
  385. UpdateHalfWindsAppearance ();
  386. isDirty = true;
  387. }
  388. }
  389. }
  390. [SerializeField, Range (1f, 5f)]
  391. float _halfWindsWidth = 1f;
  392. /// <summary>
  393. /// The compass bar ticks width.
  394. /// </summary>
  395. public float halfWindsWidth {
  396. get { return _halfWindsWidth; }
  397. set {
  398. if (value != _halfWindsWidth) {
  399. _halfWindsWidth = value;
  400. UpdateHalfWindsAppearance ();
  401. isDirty = true;
  402. }
  403. }
  404. }
  405. [SerializeField]
  406. Color _halfWindsTintColor = new Color (1f, 1f, 1f, 0.5f);
  407. /// <summary>
  408. /// The compass bar ticks tint color.
  409. /// </summary>
  410. public Color halfWindsTintColor {
  411. get { return _halfWindsTintColor; }
  412. set {
  413. if (value != _halfWindsTintColor) {
  414. _halfWindsTintColor = value;
  415. UpdateHalfWindsAppearance ();
  416. isDirty = true;
  417. }
  418. }
  419. }
  420. [SerializeField]
  421. float _labelHotZone = 0.01f;
  422. /// <summary>
  423. /// The distance from the center of the compass bar where a POI label can be shown.
  424. /// </summary>
  425. public float labelHotZone {
  426. get { return _labelHotZone; }
  427. set {
  428. if (value != _labelHotZone) {
  429. _labelHotZone = value;
  430. isDirty = true;
  431. }
  432. }
  433. }
  434. [SerializeField]
  435. float _maxIconSize = 1.15f;
  436. /// <summary>
  437. /// Maximum icon size. Icons grow or shrinks in the compass bar depending on distance.
  438. /// </summary>
  439. public float maxIconSize {
  440. get { return _maxIconSize; }
  441. set {
  442. if (value != _maxIconSize) {
  443. _maxIconSize = value;
  444. isDirty = true;
  445. }
  446. }
  447. }
  448. [SerializeField]
  449. float _minIconSize = 0.5f;
  450. /// <summary>
  451. /// Minimum icon size. Icons grow or shrinks in the compass bar depending on distance.
  452. /// </summary>
  453. public float minIconSize {
  454. get { return _minIconSize; }
  455. set {
  456. if (value != _minIconSize) {
  457. _minIconSize = value;
  458. isDirty = true;
  459. }
  460. }
  461. }
  462. [SerializeField]
  463. float _scaleInDuration = 0.3f;
  464. /// <summary>
  465. /// Duration for the poi's icon scaling effect when it appears on the compass bar
  466. /// </summary>
  467. public float scaleInDuration {
  468. get { return _scaleInDuration; }
  469. set {
  470. if (value != _scaleInDuration) {
  471. _scaleInDuration = value;
  472. isDirty = true;
  473. }
  474. }
  475. }
  476. [SerializeField]
  477. WORLD_MAPPING_MODE _worldMappingMode = WORLD_MAPPING_MODE.CameraFustrum;
  478. /// <summary>
  479. /// 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.
  480. /// </summary>
  481. public WORLD_MAPPING_MODE worldMappingMode {
  482. get { return _worldMappingMode; }
  483. set {
  484. if (value != _worldMappingMode) {
  485. _worldMappingMode = value;
  486. needUpdateBarContents = true;
  487. isDirty = true;
  488. }
  489. }
  490. }
  491. [SerializeField]
  492. float _textVerticalPosition = -30;
  493. /// <summary>
  494. /// Vertical offset for the text of POIs when visited for first time
  495. /// </summary>
  496. public float textVerticalPosition {
  497. get { return _textVerticalPosition; }
  498. set {
  499. if (value != _textVerticalPosition) {
  500. _textVerticalPosition = value;
  501. UpdateTextAppearanceEditMode ();
  502. isDirty = true;
  503. }
  504. }
  505. }
  506. [SerializeField]
  507. float _textScale = 0.2f;
  508. /// <summary>
  509. /// Scaling applied to text
  510. /// </summary>
  511. public float textScale {
  512. get { return _textScale; }
  513. set {
  514. if (value != _textScale) {
  515. _textScale = value;
  516. UpdateTextAppearanceEditMode ();
  517. isDirty = true;
  518. }
  519. }
  520. }
  521. [SerializeField]
  522. bool _textRevealEnabled = true;
  523. /// <summary>
  524. /// Enabled text revealing effect when discovering a POI for the first time
  525. /// </summary>
  526. public bool textRevealEnabled {
  527. get { return _textRevealEnabled; }
  528. set {
  529. if (value != _textRevealEnabled) {
  530. _textRevealEnabled = value;
  531. isDirty = true;
  532. }
  533. }
  534. }
  535. [SerializeField]
  536. float _textRevealDuration = 0.5f;
  537. /// <summary>
  538. /// Duration of the text reveal
  539. /// </summary>
  540. public float textRevealDuration {
  541. get { return _textRevealDuration; }
  542. set {
  543. if (value != _textRevealDuration) {
  544. _textRevealDuration = value;
  545. isDirty = true;
  546. }
  547. }
  548. }
  549. [SerializeField]
  550. float _textRevealLetterDelay = 0.05f;
  551. /// <summary>
  552. /// Delay in appearance of each letter during a text reveal
  553. /// </summary>
  554. public float textRevealLetterDelay {
  555. get { return _textRevealLetterDelay; }
  556. set {
  557. if (value != _textRevealLetterDelay) {
  558. _textRevealLetterDelay = value;
  559. isDirty = true;
  560. }
  561. }
  562. }
  563. [SerializeField]
  564. float _textDuration = 5f;
  565. /// <summary>
  566. /// Duration of the text on screen before fading out
  567. /// </summary>
  568. public float textDuration {
  569. get { return _textDuration; }
  570. set {
  571. if (value != _textDuration) {
  572. _textDuration = value;
  573. isDirty = true;
  574. }
  575. }
  576. }
  577. [SerializeField]
  578. float _textFadeOutDuration = 2f;
  579. /// <summary>
  580. /// Duration of the text fade out
  581. /// </summary>
  582. public float textFadeOutDuration {
  583. get { return _textFadeOutDuration; }
  584. set {
  585. if (value != _textFadeOutDuration) {
  586. _textFadeOutDuration = value;
  587. isDirty = true;
  588. }
  589. }
  590. }
  591. [SerializeField]
  592. bool _textShadowEnabled = true;
  593. /// <summary>
  594. /// Shows a drop shadow under the text
  595. /// </summary>
  596. public bool textShadowEnabled {
  597. get { return _textShadowEnabled; }
  598. set {
  599. if (value != _textShadowEnabled) {
  600. _textShadowEnabled = value;
  601. if (!Application.isPlaying) {
  602. UpdateTextAppearanceEditMode ();
  603. }
  604. isDirty = true;
  605. }
  606. }
  607. }
  608. [SerializeField]
  609. Font _textFont;
  610. /// <summary>
  611. /// Font for the text
  612. /// </summary>
  613. public Font textFont {
  614. get {
  615. if (_textFont == null) {
  616. _textFont = Resources.Load<Font> ("CNPro/Fonts/Vollkorn-Regular");
  617. }
  618. return _textFont;
  619. }
  620. set {
  621. if (value != _textFont) {
  622. _textFont = value;
  623. UpdateTextAppearanceEditMode ();
  624. isDirty = true;
  625. }
  626. }
  627. }
  628. [SerializeField]
  629. float _titleVerticalPosition = 18f;
  630. /// <summary>
  631. /// Vertical offset for the title of the (visited/known) centered POI in the compass bar
  632. /// </summary>
  633. public float titleVerticalPosition {
  634. get { return _titleVerticalPosition; }
  635. set {
  636. if (value != _titleVerticalPosition) {
  637. _titleVerticalPosition = value;
  638. UpdateTitleAppearanceEditMode ();
  639. isDirty = true;
  640. }
  641. }
  642. }
  643. [SerializeField]
  644. float _titleScale = 0.1f;
  645. /// <summary>
  646. /// Scaling applied to title
  647. /// </summary>
  648. public float titleScale {
  649. get { return _titleScale; }
  650. set {
  651. if (value != _titleScale) {
  652. _titleScale = value;
  653. UpdateTitleAppearanceEditMode ();
  654. isDirty = true;
  655. }
  656. }
  657. }
  658. [SerializeField]
  659. Font _titleFont;
  660. /// <summary>
  661. /// Font for the title
  662. /// </summary>
  663. public Font titleFont {
  664. get {
  665. if (_titleFont == null) {
  666. _titleFont = Resources.Load<Font> ("CNPro/Fonts/Actor-Regular");
  667. }
  668. return _titleFont;
  669. }
  670. set {
  671. if (value != _titleFont) {
  672. _titleFont = value;
  673. UpdateTitleAppearanceEditMode ();
  674. isDirty = true;
  675. }
  676. }
  677. }
  678. [SerializeField]
  679. bool _titleShadowEnabled = true;
  680. /// <summary>
  681. /// Shows a drop shadow under the title
  682. /// </summary>
  683. public bool titleShadowEnabled {
  684. get { return _titleShadowEnabled; }
  685. set {
  686. if (value != _titleShadowEnabled) {
  687. _titleShadowEnabled = value;
  688. if (!Application.isPlaying) {
  689. UpdateTitleAppearanceEditMode ();
  690. }
  691. isDirty = true;
  692. }
  693. }
  694. }
  695. [SerializeField]
  696. bool _use3Ddistance = false;
  697. /// <summary>
  698. /// Check whether 3D distance should be computed instead of planar X/Z distance.
  699. /// </summary>
  700. public bool use3Ddistance {
  701. get { return _use3Ddistance; }
  702. set {
  703. if (value != _use3Ddistance) {
  704. _use3Ddistance = value;
  705. isDirty = true;
  706. }
  707. }
  708. }
  709. [SerializeField]
  710. float _sameAltitudeThreshold = 3f;
  711. /// <summary>
  712. /// Minimum difference in altitude from camera to show "above" or "below"
  713. /// </summary>
  714. public float sameAltitudeThreshold {
  715. get { return _sameAltitudeThreshold; }
  716. set {
  717. if (value != _sameAltitudeThreshold) {
  718. _sameAltitudeThreshold = value;
  719. isDirty = true;
  720. }
  721. }
  722. }
  723. [SerializeField]
  724. bool _showDistance = false;
  725. /// <summary>
  726. /// Whether the distance in meters should be shown next to the title
  727. /// </summary>
  728. public bool showDistance {
  729. get { return _showDistance; }
  730. set {
  731. if (value != _showDistance) {
  732. _showDistance = value;
  733. isDirty = true;
  734. }
  735. }
  736. }
  737. [SerializeField]
  738. string _showDistanceFormat = "F1";
  739. /// <summary>
  740. /// 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.
  741. /// This string format corresponds with the available options for ToString(format) method of C#.
  742. /// </summary>
  743. public string showDistanceFormat {
  744. get { return _showDistanceFormat; }
  745. set {
  746. if (value != _showDistanceFormat) {
  747. _showDistanceFormat = value;
  748. isDirty = true;
  749. }
  750. }
  751. }
  752. [SerializeField]
  753. AudioClip _visitedDefaultAudioClip;
  754. /// <summary>
  755. /// 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.
  756. /// </summary>
  757. public AudioClip visitedDefaultAudioClip {
  758. get { return _visitedDefaultAudioClip; }
  759. set {
  760. if (value != _visitedDefaultAudioClip) {
  761. _visitedDefaultAudioClip = value;
  762. isDirty = true;
  763. }
  764. }
  765. }
  766. [SerializeField]
  767. AudioClip _beaconDefaultAudioClip;
  768. /// <summary>
  769. /// Default audio clip to play when a POI beacon is shown (see manual for more info about POI beacons).
  770. /// </summary>
  771. public AudioClip beaconDefaultAudioClip {
  772. get { return _beaconDefaultAudioClip; }
  773. set {
  774. if (value != _beaconDefaultAudioClip) {
  775. _beaconDefaultAudioClip = value;
  776. isDirty = true;
  777. }
  778. }
  779. }
  780. [SerializeField]
  781. AudioClip _heartbeatDefaultAudioClip;
  782. /// <summary>
  783. /// 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.
  784. /// </summary>
  785. public AudioClip heartbeatDefaultAudioClip {
  786. get { return _heartbeatDefaultAudioClip; }
  787. set {
  788. if (value != _heartbeatDefaultAudioClip) {
  789. _heartbeatDefaultAudioClip = value;
  790. isDirty = true;
  791. }
  792. }
  793. }
  794. [SerializeField]
  795. bool _dontDestroyOnLoad;
  796. /// <summary>
  797. /// Preserves compass bar between scene changes
  798. /// </summary>
  799. public bool dontDestroyOnLoad {
  800. get { return _dontDestroyOnLoad; }
  801. set {
  802. if (value != _dontDestroyOnLoad) {
  803. _dontDestroyOnLoad = value;
  804. isDirty = true;
  805. }
  806. }
  807. }
  808. #endregion
  809. #region Events
  810. /// <summary>
  811. /// Event fired when this POI is visited.
  812. /// </summary>
  813. public Action<CompassProPOI> OnPOIVisited;
  814. /// <summary>
  815. /// Event fired when the POI appears in the compass bar (gets near than the visible distance)
  816. /// </summary>
  817. public Action<CompassProPOI> OnPOIVisible;
  818. /// <summary>
  819. /// Event fired when POI disappears from the compass bar (gets farther than the visible distance)
  820. /// </summary>
  821. public Action<CompassProPOI> OnPOIHide;
  822. /// <summary>
  823. /// Event fired when mouse enters an icon on the miniMap
  824. /// </summary>
  825. public Action<CompassProPOI> OnPOIMiniMapIconMouseEnter;
  826. /// <summary>
  827. /// Event fired when mouse exits an icon on the miniMap
  828. /// </summary>
  829. public Action<CompassProPOI> OnPOIMiniMapIconMouseExit;
  830. /// <summary>
  831. /// Event fired when button is pressed on an icon on the miniMap
  832. /// </summary>
  833. public Action<CompassProPOI> OnPOIMiniMapIconMouseDown;
  834. /// <summary>
  835. /// Event fired when button is released on an icon on the miniMap
  836. /// </summary>
  837. public Action<CompassProPOI> OnPOIMiniMapIconMouseUp;
  838. /// <summary>
  839. /// Event fired when an icon is clicked on the minimap
  840. /// </summary>
  841. public Action<CompassProPOI> OnPOIMiniMapIconMouseClick;
  842. #endregion
  843. #region Public API
  844. /// <summary>
  845. /// Gets a reference to the Compass API.
  846. /// </summary>
  847. public static CompassPro instance {
  848. get {
  849. if (_instance == null) {
  850. _instance = FindObjectOfType<CompassPro> ();
  851. }
  852. return _instance;
  853. }
  854. }
  855. /// <summary>
  856. /// Call this to force a refresh of contents
  857. /// </summary>
  858. public void Refresh () {
  859. needUpdateBarContents = true;
  860. }
  861. /// <summary>
  862. /// Used to add a POI to the compass. Returns false if POI is already registered.
  863. /// </summary>
  864. public bool POIRegister (CompassProPOI newPOI) {
  865. for (int k = 0; k < icons.Count; k++) {
  866. if (icons [k].poi == newPOI) {
  867. return false;
  868. }
  869. }
  870. CompassActiveIcon newIcon = new CompassActiveIcon (newPOI);
  871. icons.Add (newIcon);
  872. return true;
  873. }
  874. /// <summary>
  875. /// Returns whether the POI is currently registered.
  876. /// </summary>
  877. public bool POIisRegistered (CompassProPOI poi) {
  878. for (int k = 0; k < icons.Count; k++) {
  879. if (icons [k].poi.id == poi.id) {
  880. return true;
  881. }
  882. }
  883. return false;
  884. }
  885. /// <summary>
  886. /// Call this method to remove a POI from the compass.
  887. /// </summary>
  888. public void POIUnregister (CompassProPOI newPOI) {
  889. for (int k = 0; k < icons.Count; k++) {
  890. if (icons [k].poi == newPOI) {
  891. if (icons [k].rectTransform != null && icons [k].rectTransform.gameObject != null)
  892. DestroyImmediate (icons [k].rectTransform.gameObject);
  893. icons.RemoveAt (k);
  894. break;
  895. }
  896. }
  897. }
  898. /// <summary>
  899. /// Shows given POI as gizmo in the scene and makes its icon always visible in the compass bar
  900. /// </summary>
  901. public void POIFocus (CompassProPOI existingPOI) {
  902. for (int k = 0; k < icons.Count; k++) {
  903. if (icons [k].poi == existingPOI) {
  904. icons [k].poi.showPlayModeGizmo = true;
  905. icons [k].poi.clampPosition = true;
  906. } else if (icons [k].poi != null) {
  907. icons [k].poi.showPlayModeGizmo = false;
  908. icons [k].poi.clampPosition = false;
  909. }
  910. }
  911. }
  912. /// <summary>
  913. /// Clears all gizmos and unfocus any focused POI.
  914. /// </summary>
  915. public void POIBlur () {
  916. for (int k = 0; k < icons.Count; k++) {
  917. if (icons [k].poi != null) {
  918. icons [k].poi.showPlayModeGizmo = false;
  919. icons [k].poi.clampPosition = false;
  920. }
  921. }
  922. }
  923. /// <summary>
  924. /// Show a light beacon over the specified POI.
  925. /// </summary>
  926. public void POIShowBeacon (CompassProPOI existingPOI, float duration, float horizontalScale = 1f) {
  927. POIShowBeacon (existingPOI, duration, horizontalScale, 1f, Color.white);
  928. }
  929. /// <summary>
  930. /// Show a light beacon over the specified POI.
  931. /// </summary>
  932. public void POIShowBeacon (CompassProPOI existingPOI, float duration, float horizontalScale, float intensity, Color tintColor) {
  933. Transform beacon = existingPOI.transform.Find ("POIBeacon");
  934. if (beacon != null)
  935. return;
  936. GameObject beaconObj = Instantiate (Resources.Load<GameObject> ("CNPro/Prefabs/POIBeacon"));
  937. beaconObj.name = "POIBeacon";
  938. beaconObj.hideFlags = HideFlags.DontSave;
  939. beacon = beaconObj.transform;
  940. beacon.localScale = new Vector3 (beacon.localScale.x * horizontalScale, beacon.localScale.y, beacon.localScale.z);
  941. beacon.position = existingPOI.transform.position + Misc.Vector3up * beacon.transform.localScale.y * 0.5f;
  942. beacon.SetParent (existingPOI.transform, true);
  943. BeaconAnimator anim = beacon.gameObject.GetComponent<BeaconAnimator> ();
  944. anim.duration = duration;
  945. anim.tintColor = tintColor;
  946. anim.intensity = intensity;
  947. if (audioSource != null) {
  948. if (existingPOI.beaconAudioClip != null) {
  949. audioSource.PlayOneShot (existingPOI.beaconAudioClip);
  950. } else if (_beaconDefaultAudioClip != null) {
  951. audioSource.PlayOneShot (_beaconDefaultAudioClip);
  952. }
  953. }
  954. }
  955. /// <summary>
  956. /// Show a light beacon over all non-visited POIs for duration in seconds and with optional custom horizontal scale for the bright cylinder.
  957. /// </summary>
  958. public void POIShowBeacon (float duration, float horizontalScale = 1f) {
  959. POIShowBeacon (duration, horizontalScale, 1f, Color.white);
  960. }
  961. /// <summary>
  962. /// Show a light beacon over all non-visited POIs for duration in seconds and with optional custom horizontal scale for the bright cylinder.
  963. /// </summary>
  964. public void POIShowBeacon (float duration, float horizontalScale, float intensity, Color tintColor) {
  965. for (int k = 0; k < icons.Count; k++) {
  966. CompassActiveIcon icon = icons [k];
  967. if (icon == null || icon.poi.isVisited || !icon.poi.isVisible)
  968. continue;
  969. POIShowBeacon (icon.poi, duration, horizontalScale, intensity, tintColor);
  970. }
  971. }
  972. /// <summary>
  973. /// Initiates a fade in effect with duration in seconds.
  974. /// </summary>
  975. public void FadeIn (float duration) {
  976. fadeDuration = duration;
  977. fadeStartTime = Time.time;
  978. prevAlpha = canvasGroup.alpha;
  979. alpha = 1f;
  980. }
  981. /// <summary>
  982. /// Initiates a fade out effect with duration in seconds.
  983. /// </summary>
  984. public void FadeOut (float duration) {
  985. fadeDuration = duration;
  986. fadeStartTime = Time.time;
  987. prevAlpha = canvasGroup.alpha;
  988. alpha = 0f;
  989. }
  990. public void ShowAnimatedText (string text) {
  991. StartCoroutine (AnimateDiscoverText (text));
  992. }
  993. public Canvas canvas {
  994. get {
  995. return _canvas;
  996. }
  997. }
  998. #endregion
  999. }
  1000. }