You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

866 lines
23 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using CIG;
  6. using CIG.Translation;
  7. using CIG3.ExtensionMethods;
  8. using CIGEnums;
  9. using SUISS.Core;
  10. using SUISS.Scheduling;
  11. using UnityEngine;
  12. namespace SUISSEngine
  13. {
  14. [RequireComponent(typeof(GridTile), typeof(Serializing))]
  15. public class Building : MonoBehaviour
  16. {
  17. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  18. public event Building.TimedBuildingEventHandler ConstructionCompletedEvent;
  19. protected virtual void FireConstructionCompletedEvent(double constructionCompletedTime)
  20. {
  21. if (this.ConstructionCompletedEvent != null)
  22. {
  23. this.ConstructionCompletedEvent(constructionCompletedTime);
  24. }
  25. }
  26. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  27. public event Building.TimedBuildingEventHandler DestroyedEvent;
  28. protected virtual void FireDestroyedEvent(double destroyedTime)
  29. {
  30. if (this.DestroyedEvent != null)
  31. {
  32. this.DestroyedEvent(destroyedTime);
  33. }
  34. }
  35. public virtual Currencies PurchasePrice
  36. {
  37. get
  38. {
  39. return this.initialPurchasePrice;
  40. }
  41. }
  42. public virtual bool IsUnlocked
  43. {
  44. get
  45. {
  46. return true;
  47. }
  48. }
  49. public virtual List<BuildingProperty> ShownProperties
  50. {
  51. get
  52. {
  53. return new List<BuildingProperty>();
  54. }
  55. }
  56. public virtual bool InfoRequiresFrequentRefresh
  57. {
  58. get
  59. {
  60. return false;
  61. }
  62. }
  63. public virtual bool CanSpeedup
  64. {
  65. get
  66. {
  67. return false;
  68. }
  69. }
  70. public virtual ILocalizedString InfoText()
  71. {
  72. UnityEngine.Debug.LogWarning("InfoText should have an override");
  73. return Localization.EmptyLocalizedString;
  74. }
  75. protected virtual void ClickHandler(GameObject target)
  76. {
  77. if (this._state == BuildingState.Demolishing || this._state == BuildingState.WaitingForDemolishing)
  78. {
  79. SingletonMonobehaviour<PopupManager>.Instance.RequestFirstPopup<BuildDemolishPopupState>(delegate(State state)
  80. {
  81. ((BuildDemolishPopupState)state).SwitchTab(BuildDemolishTabs.Demolish);
  82. });
  83. }
  84. }
  85. public BuildingState state
  86. {
  87. get
  88. {
  89. return this._state;
  90. }
  91. protected set
  92. {
  93. if (this._state != value)
  94. {
  95. this._state = value;
  96. }
  97. }
  98. }
  99. public string LocalizationKey
  100. {
  101. get
  102. {
  103. return (!string.IsNullOrEmpty(this.stringReference)) ? this.stringReference : base.name;
  104. }
  105. }
  106. public ILocalizedString LocalName
  107. {
  108. get
  109. {
  110. return Localization.Key(this.LocalizationKey);
  111. }
  112. }
  113. public string CachedName
  114. {
  115. get
  116. {
  117. if (string.IsNullOrEmpty(this.cachedName))
  118. {
  119. this.cachedName = base.name;
  120. }
  121. return this.cachedName;
  122. }
  123. }
  124. public virtual bool HasRoad
  125. {
  126. get
  127. {
  128. return this.hasRoad;
  129. }
  130. protected set
  131. {
  132. if (this.hasRoad != value)
  133. {
  134. this.hasRoad = value;
  135. this.serializing.Serialize();
  136. }
  137. }
  138. }
  139. public int SpotInDestroyQueue
  140. {
  141. get
  142. {
  143. return this.spotInDestroyQueue;
  144. }
  145. }
  146. private Renderer TileRenderer
  147. {
  148. get
  149. {
  150. if (this._tileRenderer == null)
  151. {
  152. this._tileRenderer = this.tile.GetComponent<Renderer>();
  153. }
  154. return this._tileRenderer;
  155. }
  156. }
  157. private Collider2D TileCollider2D
  158. {
  159. get
  160. {
  161. if (this._tileCollider2D == null)
  162. {
  163. this._tileCollider2D = this.tile.GetComponent<Collider2D>();
  164. }
  165. return this._tileCollider2D;
  166. }
  167. }
  168. protected virtual void Awake()
  169. {
  170. this._renderer = base.GetComponent<Renderer>();
  171. this._currencyAnimationSource.Init(this._currencyAnimationObject);
  172. }
  173. protected virtual void OnDestroy()
  174. {
  175. if (SingletonMonobehaviour<Scheduler>.IsAvailable)
  176. {
  177. if (this._defaultBehaviourRoutine != null)
  178. {
  179. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._defaultBehaviourRoutine);
  180. this._defaultBehaviourRoutine = null;
  181. }
  182. if (this._demolishBehaviourRoutine != null)
  183. {
  184. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._demolishBehaviourRoutine);
  185. this._demolishBehaviourRoutine = null;
  186. }
  187. }
  188. }
  189. protected virtual void OnSerialize(Dictionary<string, object> values)
  190. {
  191. values["state"] = (int)this.state;
  192. values["hasRoad"] = this.HasRoad;
  193. if (this.state == BuildingState.Constructing)
  194. {
  195. if (this.constructionEnumerator != null)
  196. {
  197. values["constructed"] = (double)this.constructionEnumerator.Current;
  198. }
  199. else if (this.constructionTime > 0)
  200. {
  201. values["constructed"] = Timing.time + (double)this.constructionTime;
  202. }
  203. }
  204. else if (this.state == BuildingState.WaitingForDemolishing)
  205. {
  206. if (this.spotInDestroyQueue > 0)
  207. {
  208. values["destroyQueueSpot"] = this.spotInDestroyQueue;
  209. }
  210. }
  211. else if (this.state == BuildingState.Demolishing)
  212. {
  213. if (this.demolishEnumerator != null)
  214. {
  215. values["demolished"] = (double)this.demolishEnumerator.Current;
  216. }
  217. else if (this.demolishTime > 0)
  218. {
  219. values["demolished"] = Timing.time + (double)this.demolishTime;
  220. }
  221. }
  222. }
  223. protected virtual void OnDeserialize(Dictionary<string, object> values)
  224. {
  225. if (values.ContainsKey("state"))
  226. {
  227. this._state = (BuildingState)((int)values["state"]);
  228. if (this._state == BuildingState.Constructing && values.ContainsKey("constructed"))
  229. {
  230. this.constructedTime = (double)values["constructed"];
  231. }
  232. else if (this._state == BuildingState.WaitingForDemolishing && values.ContainsKey("destroyQueueSpot"))
  233. {
  234. this.spotInDestroyQueue = (int)values["destroyQueueSpot"];
  235. }
  236. else if (this._state == BuildingState.Demolishing && values.ContainsKey("demolished"))
  237. {
  238. this.demolishedTime = (double)values["demolished"];
  239. }
  240. }
  241. if (values.ContainsKey("hasRoad"))
  242. {
  243. this.hasRoad = (bool)values["hasRoad"];
  244. }
  245. }
  246. protected virtual void OnDeserialized()
  247. {
  248. if (this == null)
  249. {
  250. return;
  251. }
  252. if (this.state == BuildingState.Demolishing)
  253. {
  254. Destroyer componentInParent = base.GetComponentInParent<Destroyer>();
  255. componentInParent.SetCurrentlyDestroying(this);
  256. Clickable component = base.GetComponent<Clickable>();
  257. if (component != null)
  258. {
  259. component.OnClickEvent += this.ClickHandler;
  260. }
  261. ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.Demolish);
  262. buttonGridTileIcon.Init(delegate
  263. {
  264. this.ClickHandler(base.gameObject);
  265. });
  266. if (this._demolishBehaviourRoutine == null)
  267. {
  268. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._demolishBehaviourRoutine = this.DemolishBehaviour(0.0), base.gameObject);
  269. }
  270. }
  271. else
  272. {
  273. if (this.state == BuildingState.WaitingForDemolishing)
  274. {
  275. Destroyer componentInParent2 = base.GetComponentInParent<Destroyer>();
  276. componentInParent2.EnqueueBuilding(this, false);
  277. }
  278. if (this._defaultBehaviourRoutine == null)
  279. {
  280. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._defaultBehaviourRoutine = this.DefaultBehaviour(), base.gameObject);
  281. }
  282. if (this.state == BuildingState.Constructing)
  283. {
  284. this.SetProgressBar(this.ConstructionTimeLeft, (double)this.constructionTime);
  285. }
  286. }
  287. }
  288. protected virtual void OnGridTileStatusChanged(GridTile.Status oldStatus)
  289. {
  290. if (this == null)
  291. {
  292. return;
  293. }
  294. GridTile.Status status = this.tile.status;
  295. if (status != GridTile.Status.Created)
  296. {
  297. if (status == GridTile.Status.Moving || status == GridTile.Status.Preview)
  298. {
  299. this._gridTileIconManager.HideIcon();
  300. }
  301. }
  302. else
  303. {
  304. if (oldStatus != GridTile.Status.Preview)
  305. {
  306. if (oldStatus == GridTile.Status.Moving)
  307. {
  308. this.OnAdjacentRoadsChanged(null);
  309. }
  310. }
  311. else
  312. {
  313. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Build);
  314. if (this.checkForRoad)
  315. {
  316. this.hasRoad = this.CheckForRoad();
  317. }
  318. if (this._defaultBehaviourRoutine != null)
  319. {
  320. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._defaultBehaviourRoutine);
  321. }
  322. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._defaultBehaviourRoutine = this.DefaultBehaviour(), base.gameObject);
  323. }
  324. this._gridTileIconManager.ShowIcon();
  325. }
  326. }
  327. protected virtual void OnGridTileHiddenChanged()
  328. {
  329. if (this._constructionGameObject != null)
  330. {
  331. if (this.tile.hidden)
  332. {
  333. if (this._constructionGameObjectRenderer != null)
  334. {
  335. this._constructionGameObjectRenderer.enabled = false;
  336. }
  337. if (this._constructionGameObjectCollider2D != null)
  338. {
  339. this._constructionGameObjectCollider2D.enabled = false;
  340. }
  341. }
  342. else
  343. {
  344. if (this._constructionGameObjectRenderer != null)
  345. {
  346. this._constructionGameObjectRenderer.enabled = true;
  347. }
  348. if (this._constructionGameObjectCollider2D != null)
  349. {
  350. this._constructionGameObjectCollider2D.enabled = true;
  351. }
  352. if (this.TileRenderer != null)
  353. {
  354. this.TileRenderer.enabled = false;
  355. }
  356. if (this.TileCollider2D != null)
  357. {
  358. this.TileCollider2D.enabled = false;
  359. }
  360. }
  361. }
  362. }
  363. protected virtual void OnConstructionStarted()
  364. {
  365. this.SetProgressBar((double)this.constructionTime, (double)this.constructionTime);
  366. }
  367. protected virtual void OnConstructionCompleted()
  368. {
  369. this.UpdateMissingRoadIcon();
  370. this.FireConstructionCompletedEvent(Timing.time);
  371. this.HideProgressBar();
  372. }
  373. protected virtual void OnDemolishStarted()
  374. {
  375. this.SetProgressBar((double)this.demolishTime, (double)this.demolishTime);
  376. }
  377. protected virtual void OnDemolishCompleted()
  378. {
  379. this.FireDestroyedEvent(this.demolishedTime);
  380. }
  381. protected virtual void OnDemolishCancelled()
  382. {
  383. }
  384. public virtual bool CanDemolish
  385. {
  386. get
  387. {
  388. return this.destructible;
  389. }
  390. }
  391. public bool CheckForRoad()
  392. {
  393. if (this == null || this.tile == null || this.tile.element == null || this.tile.element.Grid == null)
  394. {
  395. return false;
  396. }
  397. foreach (GridTile gridTile in this.tile.element.Grid.GetNeighbourTiles(this.tile))
  398. {
  399. if (gridTile.GetComponent<Road>() != null)
  400. {
  401. return true;
  402. }
  403. }
  404. return false;
  405. }
  406. public bool IsConstructed
  407. {
  408. get
  409. {
  410. return this.state == BuildingState.Normal || this.state == BuildingState.Moving || this.state == BuildingState.WaitingForDemolishing || this.state == BuildingState.Demolishing;
  411. }
  412. }
  413. public virtual void StartDemolishing(double startTime)
  414. {
  415. if (this.state != BuildingState.WaitingForDemolishing)
  416. {
  417. UnityEngine.Debug.LogWarning(string.Format("{0}: Cannot demolish in state {1}", base.name, this.state));
  418. return;
  419. }
  420. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Demolish, true);
  421. Scheduler instance = SingletonMonobehaviour<Scheduler>.Instance;
  422. if (instance != null)
  423. {
  424. if (this._demolishBehaviourRoutine != null)
  425. {
  426. instance.StopRoutine(this._demolishBehaviourRoutine);
  427. this._demolishBehaviourRoutine = null;
  428. }
  429. instance.StartRoutine(this._demolishBehaviourRoutine = this.DemolishBehaviour(startTime), base.gameObject);
  430. }
  431. }
  432. public void FinishDemolishing()
  433. {
  434. if (this.demolishEnumerator != null)
  435. {
  436. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Fairy);
  437. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this.demolishEnumerator);
  438. this.demolishEnumerator = null;
  439. base.BroadcastMessage("OnSpeedupPurchased", SendMessageOptions.DontRequireReceiver);
  440. }
  441. }
  442. public void FinishConstruction()
  443. {
  444. if (this.constructionEnumerator != null)
  445. {
  446. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Fairy);
  447. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this.constructionEnumerator);
  448. this.constructionEnumerator = null;
  449. base.BroadcastMessage("OnSpeedupPurchased", SendMessageOptions.DontRequireReceiver);
  450. }
  451. }
  452. public double ConstructionTimeLeft
  453. {
  454. get
  455. {
  456. if (this.constructionEnumerator != null)
  457. {
  458. return Scheduler.TimeLeft(this.constructionEnumerator);
  459. }
  460. return 0.0;
  461. }
  462. }
  463. public double DemolishTimeLeft
  464. {
  465. get
  466. {
  467. if (this.demolishEnumerator != null)
  468. {
  469. return Scheduler.TimeLeft(this.demolishEnumerator);
  470. }
  471. if (this.state == BuildingState.WaitingForDemolishing)
  472. {
  473. return (double)this.demolishTime;
  474. }
  475. return 0.0;
  476. }
  477. }
  478. public virtual void OnAdjacentRoadsChanged(GridTile road)
  479. {
  480. if (this.checkForRoad)
  481. {
  482. this.HasRoad = this.CheckForRoad();
  483. }
  484. this.UpdateMissingRoadIcon();
  485. }
  486. private void UpdateMissingRoadIcon()
  487. {
  488. if (this.checkForRoad && !this.HasRoad)
  489. {
  490. ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.MissingRoad);
  491. buttonGridTileIcon.Init(delegate
  492. {
  493. this.ClickHandler(base.gameObject);
  494. });
  495. }
  496. else
  497. {
  498. this._gridTileIconManager.RemoveIcon(GridTileIconType.MissingRoad);
  499. }
  500. }
  501. protected void HideProgressBar()
  502. {
  503. if (this._progressOverlay != null)
  504. {
  505. UnityEngine.Object.Destroy(this._progressOverlay.gameObject);
  506. this._gridTileIconManager.RemoveIcon(GridTileIconType.UpgradeArrow);
  507. }
  508. }
  509. protected void SetProgressBar(double time, double totalTime)
  510. {
  511. if (this._progressOverlay == null)
  512. {
  513. this._progressOverlay = OverlayProgress.Get(base.gameObject);
  514. }
  515. this._progressOverlay.Initialize(Timing.Instance.GameTime + time, totalTime);
  516. this.ProgressTimeChanged();
  517. }
  518. protected virtual void ProgressTimeChanged()
  519. {
  520. }
  521. private IEnumerator WaitForConstruction()
  522. {
  523. double finishTime;
  524. if (this.constructedTime < 0.0)
  525. {
  526. finishTime = Timing.time + (double)this.constructionTime;
  527. }
  528. else
  529. {
  530. finishTime = this.constructedTime;
  531. }
  532. yield return finishTime;
  533. yield break;
  534. }
  535. private IEnumerator ConstructionBehaviour()
  536. {
  537. if (this.constructionTime <= 0 || SingletonMonobehaviour<CIGBuilderManager>.Instance.IsSpeedupped(this))
  538. {
  539. yield break;
  540. }
  541. this.SetConstructionSprite();
  542. yield return this.constructionEnumerator = this.WaitForConstruction();
  543. this.constructionEnumerator = null;
  544. this.SetOriginalSprite();
  545. yield break;
  546. }
  547. private IEnumerator DefaultBehaviour()
  548. {
  549. switch (this.state)
  550. {
  551. case BuildingState.Preview:
  552. this.state = BuildingState.Constructing;
  553. SingletonMonobehaviour<CIGGameStats>.Instance.AddBuildingAction();
  554. base.BroadcastMessage("OnConstructionStarted", SendMessageOptions.DontRequireReceiver);
  555. this.serializing.Serialize();
  556. SingletonMonobehaviour<CIGBuilderManager>.Instance.StartTracking(this, Timing.time + (double)this.constructionTime);
  557. break;
  558. case BuildingState.Constructing:
  559. break;
  560. case BuildingState.Normal:
  561. goto IL_125;
  562. case BuildingState.Moving:
  563. goto IL_1A7;
  564. case BuildingState.WaitingForDemolishing:
  565. {
  566. ButtonGridTileIcon icon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.Demolish);
  567. icon.Init(delegate
  568. {
  569. this.ClickHandler(base.gameObject);
  570. });
  571. goto IL_125;
  572. }
  573. default:
  574. goto IL_1A7;
  575. }
  576. yield return this.ConstructionBehaviour();
  577. this.state = BuildingState.Normal;
  578. base.BroadcastMessage("OnConstructionCompleted", SendMessageOptions.DontRequireReceiver);
  579. this.serializing.Serialize();
  580. SingletonMonobehaviour<CIGBuilderManager>.Instance.FinishTracking(this);
  581. IL_125:
  582. Clickable clicker = base.GetComponent<Clickable>();
  583. if (clicker != null)
  584. {
  585. clicker.OnClickEvent += this.ClickHandler;
  586. }
  587. this.UpdateMissingRoadIcon();
  588. goto IL_1CB;
  589. IL_1A7:
  590. UnityEngine.Debug.LogWarning(string.Format("Building is in weird state {0}.", this.state));
  591. IL_1CB:
  592. this._defaultBehaviourRoutine = null;
  593. yield break;
  594. }
  595. private IEnumerator WaitForDemolish(double startTime)
  596. {
  597. if (this.demolishedTime < 0.0)
  598. {
  599. yield return this.demolishedTime = startTime + (double)this.demolishTime;
  600. }
  601. else
  602. {
  603. yield return this.demolishedTime;
  604. }
  605. yield break;
  606. }
  607. public void SetInDemolishingState(int spotInDestroyQueue)
  608. {
  609. if (this.state != BuildingState.Normal)
  610. {
  611. UnityEngine.Debug.Log(string.Format("Cant demolish building from state {0}", this.state));
  612. return;
  613. }
  614. this.spotInDestroyQueue = spotInDestroyQueue;
  615. this.state = BuildingState.WaitingForDemolishing;
  616. this.serializing.Serialize();
  617. ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.Demolish);
  618. buttonGridTileIcon.Init(delegate
  619. {
  620. this.ClickHandler(base.gameObject);
  621. });
  622. }
  623. public void CancelDemolishment()
  624. {
  625. if (this.state != BuildingState.WaitingForDemolishing && this.state != BuildingState.Demolishing)
  626. {
  627. UnityEngine.Debug.Log(string.Format("Cant cancel demolishment from state {0}", this.state));
  628. return;
  629. }
  630. base.GetComponentInParent<Destroyer>().CancelDestroyBuilding(this);
  631. BuildingState state = this.state;
  632. this.state = BuildingState.Normal;
  633. if (state == BuildingState.Demolishing)
  634. {
  635. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this.demolishEnumerator);
  636. this.demolishedTime = -1.0;
  637. }
  638. this.serializing.Serialize();
  639. this._gridTileIconManager.RemoveIcon(GridTileIconType.Demolish);
  640. this.UpdateMissingRoadIcon();
  641. }
  642. private IEnumerator DemolishBehaviour(double startTime)
  643. {
  644. this.state = BuildingState.Demolishing;
  645. base.BroadcastMessage("OnDemolishStarted", SendMessageOptions.DontRequireReceiver);
  646. this.serializing.Serialize();
  647. yield return this.demolishEnumerator = this.WaitForDemolish(startTime);
  648. this.HideProgressBar();
  649. this.demolishEnumerator = null;
  650. if (this.state != BuildingState.Demolishing)
  651. {
  652. base.BroadcastMessage("OnDemolishCancelled", SendMessageOptions.DontRequireReceiver);
  653. this.serializing.Serialize();
  654. this._demolishBehaviourRoutine = null;
  655. yield break;
  656. }
  657. this._gridTileIconManager.RemoveIcon(GridTileIconType.Demolish);
  658. SingletonMonobehaviour<CIGGameStats>.Instance.AddBuildingAction();
  659. base.BroadcastMessage("OnDemolishCompleted", SendMessageOptions.DontRequireReceiver);
  660. IsometricIsland.GetParent(this).builder.DestroyTile(this.tile);
  661. this._demolishBehaviourRoutine = null;
  662. yield break;
  663. }
  664. private void SetConstructionSprite()
  665. {
  666. if (this.constructionPrefab == null)
  667. {
  668. UnityEngine.Debug.LogWarning(string.Format("Building {0} has constructionPrefab null", base.name));
  669. return;
  670. }
  671. this._constructionGameObject = UnityEngine.Object.Instantiate<GameObject>(this.constructionPrefab);
  672. this._constructionGameObjectRenderer = this._constructionGameObject.GetComponent<Renderer>();
  673. this._constructionGameObjectCollider2D = this._constructionGameObject.GetComponent<Collider2D>();
  674. base.gameObject.AttachChildTransform(this._constructionGameObject, SpriteAlignment.Custom);
  675. Clickable.Instance(this._constructionGameObject).OnClickEvent += this.ClickHandler;
  676. if (this.tile.hidden)
  677. {
  678. if (this._constructionGameObjectRenderer != null)
  679. {
  680. this._constructionGameObjectRenderer.enabled = false;
  681. }
  682. if (this._constructionGameObjectRenderer != null)
  683. {
  684. this._constructionGameObjectRenderer.enabled = false;
  685. }
  686. }
  687. this.savedGridTileOffset = this.tile.offset;
  688. GridTile component = this._constructionGameObject.GetComponent<GridTile>();
  689. if (component != null)
  690. {
  691. this.tile.offset = component.offset;
  692. }
  693. this.tile.UpdateTransform();
  694. component.spriteRenderer.sortingOrder = this.tile.spriteRenderer.sortingOrder;
  695. if (this.TileRenderer != null)
  696. {
  697. this.TileRenderer.enabled = false;
  698. }
  699. if (this.TileCollider2D != null)
  700. {
  701. this.TileCollider2D.enabled = false;
  702. }
  703. }
  704. private void SetOriginalSprite()
  705. {
  706. if (this._constructionGameObject != null)
  707. {
  708. if (!this.tile.hidden)
  709. {
  710. if (this.TileRenderer != null)
  711. {
  712. this.TileRenderer.enabled = true;
  713. }
  714. if (this.TileCollider2D != null)
  715. {
  716. this.TileCollider2D.enabled = true;
  717. }
  718. }
  719. this.tile.offset = this.savedGridTileOffset;
  720. this.tile.UpdateTransform();
  721. Clickable.Instance(this._constructionGameObject).OnClickEvent -= this.ClickHandler;
  722. this._constructionGameObject.transform.parent = null;
  723. UnityEngine.Object.Destroy(this._constructionGameObject);
  724. this._constructionGameObject = null;
  725. this._constructionGameObjectRenderer = null;
  726. this._constructionGameObjectCollider2D = null;
  727. }
  728. }
  729. public Bounds RendererBounds()
  730. {
  731. if (this._constructionGameObject != null && this._constructionGameObjectRenderer.enabled)
  732. {
  733. return this._constructionGameObjectRenderer.bounds;
  734. }
  735. return this._renderer.bounds;
  736. }
  737. [SerializeField]
  738. protected GridTileIconManager _gridTileIconManager;
  739. [SerializeField]
  740. protected PlingManager _plingManager;
  741. [SerializeField]
  742. protected CurrencyAnimationSource _currencyAnimationSource;
  743. public GameObject constructionPrefab;
  744. public Currencies initialPurchasePrice;
  745. public int goldCostAtMax;
  746. public int constructionTime;
  747. public int demolishTime;
  748. public bool checkForRoad;
  749. public bool movable;
  750. public bool destructible;
  751. public string stringReference;
  752. [SelfReference]
  753. public Serializing serializing;
  754. [SelfReference]
  755. public GridTile tile;
  756. protected object _currencyAnimationObject = new object();
  757. private string cachedName = string.Empty;
  758. private OverlayProgress _progressOverlay;
  759. private BuildingState _state;
  760. protected double constructedTime = -1.0;
  761. protected double demolishedTime = -1.0;
  762. private GameObject _constructionGameObject;
  763. private Renderer _constructionGameObjectRenderer;
  764. private Collider2D _constructionGameObjectCollider2D;
  765. private bool hasRoad;
  766. private Vector3 savedGridTileOffset;
  767. private int spotInDestroyQueue = -1;
  768. private IEnumerator _defaultBehaviourRoutine;
  769. private IEnumerator _demolishBehaviourRoutine;
  770. private Renderer _tileRenderer;
  771. private Collider2D _tileCollider2D;
  772. protected Renderer _renderer;
  773. private IEnumerator constructionEnumerator;
  774. private IEnumerator demolishEnumerator;
  775. public delegate void TimedBuildingEventHandler(double time);
  776. }
  777. }