Advertisement
Guest User

GridLifeSupport.cs

a guest
Jan 30th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.19 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GridLifeSupport : MonoBehaviour {
  6.  
  7. // check XY
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14. // XY area
  15.  
  16. private float XnumberFloat;
  17. private float YnumberFloat;
  18.  
  19. public int Xnumber;
  20. public int Ynumber;
  21.  
  22. public static int XnumberStatic;
  23. public static int YnumberStatic;
  24.  
  25. // public static int XnumberStatic;
  26. // public static int YnumberStatic;
  27.  
  28. // Area
  29.  
  30. // public bool IsPartOfRoom = false;
  31.  
  32. public bool BuildMode = false;
  33.  
  34. public bool CelingShow = false;
  35. public static bool CelingShowStatic = false;
  36.  
  37. public bool ActiveObjectSet = false;
  38.  
  39. public bool ActiveObject = false;
  40. public static bool ActiveObjectStatic = false;
  41.  
  42. public bool DisabledObject = false;
  43.  
  44. public int OxygenCount = 100;
  45. public int FireCount = 0;
  46. public bool LightState = false;
  47.  
  48. public int MaterialNumber = 0;
  49. public static int MaterialNumberStatic = 0;
  50.  
  51.  
  52. // public int DangerCount = 0; // Most likely to be shown differently in game as different situations , or not
  53.  
  54. // GameObject Area
  55. public GameObject LightObject;
  56.  
  57. public GameObject CelingObject;
  58.  
  59. public GameObject WallObject0;
  60. public GameObject WallObject1;
  61. public GameObject WallObject2;
  62. public GameObject WallObject3;
  63.  
  64. public GameObject PylonObject0;
  65. public GameObject PylonObject1;
  66. public GameObject PylonObject2;
  67. public GameObject PylonObject3;
  68.  
  69. public Material ObjectMaterial;
  70. public Material GridMaterial;
  71. public Material ErrorMaterial;
  72. public Material GoodMaterial;
  73.  
  74. public int SelectPointVar0 = 0;
  75. public int SelectPointVar1 = 0;
  76. public int SelectPointVar2 = 0;
  77. public int SelectPointVar3 = 0;
  78.  
  79. public string StringFront;
  80. public string StringBack;
  81. public string StringLeft;
  82. public string StringRight;
  83.  
  84. private int SelectPointVarX0;
  85. private int SelectPointVarX2;
  86. private int SelectPointVarY1;
  87. private int SelectPointVarY3;
  88.  
  89. public GameObject FrontObject; // Left
  90. public GameObject RightObject; // Right
  91. public GameObject BackObject; // Back
  92. public GameObject LeftObject; // Front
  93.  
  94. private bool Area0 = false;
  95. private bool Area1 = false;
  96. private bool Area2 = false;
  97. private bool Area3 = false;
  98.  
  99. private bool Pylon0 = false;
  100. private bool Pylon1 = false;
  101. private bool Pylon2 = false;
  102. private bool Pylon3 = false;
  103.  
  104. private bool Wall0 = false;
  105. private bool Wall1 = false;
  106. private bool Wall2 = false;
  107. private bool Wall3 = false;
  108.  
  109. public static Ray CameraRay;
  110.  
  111. public bool SelectedFromCamera = false;
  112.  
  113. private bool Looking = false;
  114.  
  115. public string DesignatedName;
  116.  
  117. public static int DesignatedNumberStatic;
  118.  
  119. // TO STRING
  120.  
  121.  
  122. private int XnumberString;
  123. private int YnumberString;
  124.  
  125. public bool Room;
  126.  
  127.  
  128.  
  129. // Use this for initialization
  130. void Start () {
  131. // DesignatedNumber = LifeSupport.AmountOfTilesStatic;
  132. // DesignatedNumber = DesignatedNumberStatic;
  133.  
  134. }
  135.  
  136.  
  137.  
  138. void LookingVoid () {
  139. if (Input.GetButton ("Look")) {
  140. Looking = true;
  141. }
  142.  
  143. else {
  144. Looking = false;
  145. }
  146. }
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. // 0 is Left
  155. // 2 is Right
  156. // 1 is Back
  157. // 3 is Front
  158.  
  159. // ActivateTile Start
  160.  
  161. void ActivateTile(){
  162.  
  163.  
  164.  
  165. // GameObject[] objs;
  166.  
  167. // if (ActiveObjectSet == true) {
  168. // objs = GameObject.FindGameObjectsWithTag ("Tile");
  169.  
  170. // foreach (GameObject GridFloor in objs) {
  171.  
  172.  
  173. // and has Ynumber == SelectPointVarY3 to be a specific object;
  174.  
  175. //like if SelectPointVarY3 = 2 , then the SelectPointObjectY3 would be a specific object and if SelectPointVarY3 was another value, then would be a different object
  176.  
  177.  
  178.  
  179. // if (GridFloor.GetComponent<GridLifeSupport> ().Ynumber == SelectPointVarY3) { //F
  180. // SelectPointVar3 = 0;
  181. // }
  182.  
  183. // 0 is Left
  184. // 2 is Right
  185. // 1 is Back
  186. // 3 is Front
  187.  
  188.  
  189.  
  190.  
  191. if (FrontObject == null) { //F
  192. SelectPointVar3 = 1;
  193. }
  194.  
  195. if (BackObject == null) { //B
  196. SelectPointVar1 = 1;
  197. }
  198.  
  199. if (RightObject == null) { //L
  200. SelectPointVar2 = 1;
  201. }
  202.  
  203. if (LeftObject == null) { //R
  204. SelectPointVar0 = 1;
  205. }
  206.  
  207.  
  208. // if (FrontObject != null) { //F
  209. // SelectPointVar3 = 0;
  210. // }
  211.  
  212. // if (BackObject != null) { //B
  213. // SelectPointVar1 = 0;
  214. // }
  215.  
  216. // if (RightObject != null) { //L
  217. // SelectPointVar2 = 0;
  218. // }
  219.  
  220. // if (LeftObject != null) { //R
  221. // SelectPointVar0 = 0;
  222. // }
  223.  
  224.  
  225.  
  226. if (FrontObject.name == StringFront) { //F
  227. SelectPointVar3 = 0;
  228. }
  229.  
  230. if (BackObject.name == StringBack) { //B
  231. SelectPointVar1 = 0;
  232. }
  233.  
  234. if (RightObject.name == StringRight) { //L
  235. SelectPointVar2 = 0;
  236. }
  237.  
  238. if (LeftObject.name == StringLeft) { //R
  239. SelectPointVar0 = 0;
  240. }
  241.  
  242.  
  243.  
  244.  
  245. else {
  246. SelectPointVar0 = 1;
  247. SelectPointVar1 = 1;
  248. SelectPointVar2 = 1;
  249. SelectPointVar3 = 1;
  250. }
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. // }
  258. // }
  259. }
  260.  
  261. // ActivateTile End
  262.  
  263. void XYNumbersToString(){
  264. this.name = DesignatedName + XnumberString + "," + YnumberString;
  265. XnumberString.ToString();
  266. YnumberString.ToString();
  267.  
  268.  
  269. }
  270.  
  271.  
  272. // Update is called once per frame
  273. void Update () {
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284. if (FrontObject == null) { //F
  285. FrontObject = GameObject.Find (StringFront);
  286. }
  287.  
  288. if (BackObject == null) { //B
  289. BackObject = GameObject.Find (StringBack);
  290. }
  291.  
  292. if (RightObject == null) { //L
  293. RightObject = GameObject.Find (StringRight);
  294. }
  295.  
  296. if (LeftObject == null) { //R
  297. LeftObject = GameObject.Find (StringLeft);
  298. }
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305. XYNumbersToString ();
  306.  
  307.  
  308.  
  309. // 0 is Left
  310. // 2 is Right
  311. // 1 is Back
  312. // 3 is Front
  313.  
  314. XnumberString = Xnumber;
  315. YnumberString = Ynumber;
  316.  
  317. SelectPointVarX0 = Xnumber - 2;
  318. SelectPointVarX2 = Xnumber + 2;
  319. SelectPointVarY1 = Ynumber + 2;
  320. SelectPointVarY3 = Ynumber - 2;
  321.  
  322.  
  323. //String Position Area
  324.  
  325.  
  326. StringFront = XnumberString + "," + SelectPointVarY3.ToString();
  327. StringBack = XnumberString + "," + SelectPointVarY1.ToString();
  328.  
  329. StringRight = SelectPointVarX2.ToString() + "," + YnumberString;
  330. StringLeft = SelectPointVarX0.ToString() + "," + YnumberString;
  331.  
  332.  
  333. //String Position Area End
  334.  
  335.  
  336. XnumberStatic = Xnumber;
  337. YnumberStatic = Ynumber;
  338.  
  339.  
  340.  
  341.  
  342. // XY area
  343.  
  344. XnumberFloat = this.transform.localPosition.x;
  345. YnumberFloat = this.transform.localPosition.y;
  346.  
  347. Xnumber = (int)XnumberFloat ;
  348. Ynumber = (int)YnumberFloat ;
  349.  
  350. LookingVoid ();
  351.  
  352. // Mouse Raycast
  353.  
  354. if (Looking == false) {
  355.  
  356.  
  357. if (Input.GetMouseButton (0)) {
  358.  
  359.  
  360. Camera theCamera = Camera.main;
  361. //Or Camera.main
  362. //can be set to variable
  363.  
  364. Ray ray = theCamera.ScreenPointToRay (Input.mousePosition);
  365.  
  366. RaycastHit hitInfo;
  367.  
  368.  
  369. CameraRay = ray;
  370.  
  371. if (Physics.Raycast (ray, out hitInfo)) {
  372.  
  373. if (hitInfo.collider.GetComponent<Collider> () == this.GetComponent<Collider> ()) {
  374. ActiveObject = true;
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381. SelectedFromCamera = true;
  382. if (SelectedFromCamera == true) {
  383. if (ActiveObject == true) {
  384. MaterialNumber = 3;
  385. }
  386. }
  387. }
  388.  
  389.  
  390. // if (hitInfo.collider.GetComponent<Collider> () != this.GetComponent<Collider>()) {
  391. // if (SelectedFromCamera == false) {
  392. // ActiveObject = false;
  393. // }
  394. // }
  395.  
  396. }
  397.  
  398. }
  399.  
  400.  
  401.  
  402. if (Input.GetMouseButton (1)) {
  403.  
  404. Camera theCamera = Camera.main;
  405. //Or Camera.main
  406. //can be set to variable
  407.  
  408. Ray ray = theCamera.ScreenPointToRay (Input.mousePosition);
  409.  
  410. RaycastHit hitInfo;
  411.  
  412.  
  413. CameraRay = ray;
  414.  
  415. if (Physics.Raycast (ray, out hitInfo)) {
  416.  
  417. if (hitInfo.collider.GetComponent<Collider> () == this.GetComponent<Collider> ()) {
  418. ActiveObject = false;
  419. SelectedFromCamera = false;
  420. if (MouseManager.EditRoomStatic == true) {
  421. if (ActiveObjectSet == true) {
  422. ActiveObjectSet = false;
  423. }
  424. }
  425. }
  426.  
  427. }
  428.  
  429. }
  430. }
  431.  
  432.  
  433. if (Input.GetButtonDown ("Enter")) {
  434. if (SelectedFromCamera == true) {
  435. ActiveObjectSet = true;
  436.  
  437. ActivateTile ();
  438. }
  439. }
  440.  
  441.  
  442.  
  443. // Mouse Raycast
  444.  
  445. if (ActiveObjectSet == true) {
  446. ActiveObject = true;
  447. MaterialNumber = 1;
  448. }
  449.  
  450.  
  451.  
  452. if (MouseManager.DisableCelingStatic == true) {
  453. if (ActiveObjectSet == true) {
  454. CelingObject.SetActive (false);
  455. }
  456. }
  457.  
  458. if (MouseManager.DisableCelingStatic == false) {
  459. if (ActiveObjectSet == true) {
  460. CelingObject.SetActive (true);
  461. }
  462. }
  463.  
  464.  
  465.  
  466. if (ActiveObjectSet != true) {
  467. CelingObject.SetActive (false);
  468.  
  469. }
  470.  
  471. CelingShow = CelingShowStatic;
  472.  
  473. ActiveObjectStatic = ActiveObject;
  474.  
  475. if (MouseManager.DisableGridStatic == false) {
  476. if (ActiveObject == false) {
  477. MaterialNumber = 0;
  478. }
  479. }
  480.  
  481. if (MouseManager.DisableGridStatic == true) {
  482. if (MaterialNumber != 1) {
  483. SelectedFromCamera = false;
  484. ActiveObject = false;
  485. }
  486. if (ActiveObject == false) {
  487. MaterialNumber = -1;
  488. }
  489. }
  490.  
  491.  
  492. MeshRenderer ObjectRender = GetComponent<MeshRenderer> ();
  493.  
  494. //Material change
  495. if (MaterialNumber <= 0) {
  496. LightState = false;
  497. }
  498.  
  499. if (MaterialNumber <= -1) {
  500. GetComponent<Renderer> ().enabled = false;
  501. GetComponent<Collider> ().enabled = false;
  502. }
  503.  
  504. if (MaterialNumber > -1) {
  505. GetComponent<Renderer> ().enabled = true;
  506. GetComponent<Collider> ().enabled = true;
  507. }
  508.  
  509. if (MaterialNumber == 0) {
  510. ObjectRender.material = GridMaterial;
  511. }
  512.  
  513. if (MaterialNumber == 1) {
  514. ObjectRender.material = ObjectMaterial;
  515. }
  516.  
  517. if (MaterialNumber == 2) {
  518. ObjectRender.material = ErrorMaterial;
  519. }
  520.  
  521. if (MaterialNumber == 3) {
  522. ObjectRender.material = GoodMaterial;
  523. }
  524.  
  525. //Material change
  526.  
  527.  
  528.  
  529.  
  530. if (LightState == true) {
  531. LightObject.SetActive(true);
  532. }
  533.  
  534. if (LightState == false) {
  535. LightObject.SetActive(false);
  536. }
  537.  
  538. ////////////////////////////////// Wall Area
  539.  
  540. // Wall Enable
  541.  
  542. if (Wall0 == true) {
  543. WallObject0.SetActive(true);
  544. }
  545.  
  546. if (Wall1 == true) {
  547. WallObject1.SetActive(true);
  548. }
  549.  
  550. if (Wall2 == true) {
  551. WallObject2.SetActive(true);
  552. }
  553.  
  554. if (Wall3 == true) {
  555. WallObject3.SetActive(true);
  556. }
  557.  
  558.  
  559. // Wall Disable
  560.  
  561. if (Wall0 == false) {
  562. WallObject0.SetActive(false);
  563. }
  564.  
  565. if (Wall1 == false) {
  566. WallObject1.SetActive(false);
  567. }
  568.  
  569. if (Wall2 == false) {
  570. WallObject2.SetActive(false);
  571. }
  572.  
  573. if (Wall3 == false) {
  574. WallObject3.SetActive(false);
  575. }
  576.  
  577. // Pylon Enable
  578.  
  579. if (Pylon0 == true) {
  580. PylonObject0.SetActive(true);
  581. }
  582.  
  583. if (Pylon1 == true) {
  584. PylonObject1.SetActive(true);
  585. }
  586.  
  587. if (Pylon2 == true) {
  588. PylonObject2.SetActive(true);
  589. }
  590.  
  591. if (Pylon3 == true) {
  592. PylonObject3.SetActive(true);
  593. }
  594.  
  595.  
  596. // Pylon Disable
  597.  
  598. if (Pylon0 == false) {
  599. PylonObject0.SetActive(false);
  600. }
  601.  
  602. if (Pylon1 == false) {
  603. PylonObject1.SetActive(false);
  604. }
  605.  
  606. if (Pylon2 == false) {
  607. PylonObject2.SetActive(false);
  608. }
  609.  
  610. if (Pylon3 == false) {
  611. PylonObject3.SetActive(false);
  612. }
  613.  
  614.  
  615.  
  616. //SelectPoint Variables
  617. if (SelectPointVar0 == 0) {
  618. Wall0 = false;
  619. Area0 = false;
  620. }
  621. if (SelectPointVar1 == 0) {
  622. Wall1 = false;
  623. Area1 = false;
  624. }
  625. if (SelectPointVar2 == 0) {
  626. Wall2 = false;
  627. Area2 = false;
  628. }
  629. if (SelectPointVar3 == 0) {
  630. Wall3 = false;
  631. Area3 = false;
  632. }
  633.  
  634.  
  635. if (SelectPointVar0 == 1) {
  636. Wall0 = true;
  637. Area0 = true;
  638. }
  639. if (SelectPointVar1 == 1) {
  640. Wall1 = true;
  641. Area1 = true;
  642. }
  643. if (SelectPointVar2 == 1) {
  644. Wall2 = true;
  645. Area2 = true;
  646. }
  647. if (SelectPointVar3 == 1) {
  648. Wall3 = true;
  649. Area3 = true;
  650. }
  651.  
  652.  
  653. // Pylon 0
  654. if (Area0 == true || Area3 == true) {
  655. Pylon0 = true;
  656. }
  657.  
  658.  
  659. // Pylon 1
  660. if (Area1 == true || Area0 == true) {
  661. Pylon1 = true;
  662. }
  663.  
  664.  
  665.  
  666. // Pylon 2
  667. if (Area1 == true || Area2 == true) {
  668. Pylon2 = true;
  669. }
  670.  
  671.  
  672. // Pylon 3
  673. if (Area2 == true || Area3 == true) {
  674. Pylon3 = true;
  675. }
  676.  
  677.  
  678. //Disable Pylons if there is no wall connecting it
  679.  
  680.  
  681. // Pylon 0
  682. if (Area0 == false && Area3 == false) {
  683. Pylon0 = false;
  684. }
  685.  
  686.  
  687. // Pylon 1
  688. if (Area1 == false && Area0 == false) {
  689. Pylon1 = false;
  690. }
  691.  
  692.  
  693. // Pylon 2
  694. if (Area1 == false && Area2 == false) {
  695. Pylon2 = false;
  696. }
  697.  
  698.  
  699. // Pylon 3
  700. if (Area2 == false && Area3 == false) {
  701. Pylon3 = false;
  702. }
  703.  
  704. ////////////////////////////////// Wall Area
  705.  
  706.  
  707. //End Update
  708.  
  709. }
  710.  
  711. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement