Guest User

Untitled

a guest
Dec 15th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Collections;
  4. using UnityEngine;
  5.  
  6. public class SolarNrgRecycler : Part
  7. {
  8.  
  9. protected Rect windowPos;
  10. protected bool soundState;
  11. protected bool oldState;
  12. private static string kspDir;
  13. private static string kspDir2;
  14. public int aluminium;
  15. public int water;
  16.  
  17.  
  18. protected override void onFlightStart()
  19. {
  20. kspDir2 = UnityEngine.Application.dataPath;
  21. int lastIndex = kspDir2.LastIndexOf('/');
  22. if (lastIndex != -1)
  23. {
  24. kspDir = kspDir2.Substring(0, lastIndex + 1);
  25. }
  26. //urMod_LoadAudioFiles(); //launch the loadsoundfile function from here
  27. {
  28. RenderingManager.AddToPostDrawQueue(3, new Callback(drawGUI));//start the GUI
  29.  
  30. }
  31. }
  32.  
  33. private void OnCollisionEnter(Collision collisionInfo)
  34. {
  35. print("COLLISION!:\t" + collisionInfo.gameObject.name);
  36. if (collisionInfo.gameObject.name == "rock1(Clone)")
  37. {
  38. aluminium++;
  39. Destroy(collisionInfo.gameObject);
  40. //do stuff. add to resource etc
  41. }
  42. if (collisionInfo.gameObject.name == "rock2(Clone)")
  43. {
  44. water++;
  45. Destroy(collisionInfo.gameObject);
  46. //do stuff. add to resource etc
  47. }
  48. }
  49.  
  50.  
  51. private void WindowGUI(int windowID)
  52. {
  53. GUIStyle mySty = new GUIStyle(GUI.skin.button);
  54.  
  55. mySty.normal.textColor = mySty.focused.textColor = Color.white;
  56. mySty.hover.textColor = mySty.active.textColor = Color.yellow;
  57. mySty.onNormal.textColor = mySty.onFocused.textColor = mySty.onHover.textColor = mySty.onActive.textColor = Color.green;
  58.  
  59. GUIStyle yellow = new GUIStyle(GUI.skin.label);
  60. GUIStyle white = new GUIStyle(GUI.skin.label);
  61. GUIStyle green = new GUIStyle(GUI.skin.label);
  62.  
  63. yellow.normal.textColor = Color.yellow;
  64. white.normal.textColor = Color.white;
  65. green.normal.textColor = Color.green;
  66.  
  67. //Start building the GUI on screen
  68. GUILayout.BeginVertical();
  69.  
  70. bool oldState = soundState; //Silence switch
  71. soundState = GUILayout.Toggle(soundState, "Report", mySty, GUILayout.ExpandWidth(false), GUILayout.MinWidth(20));
  72.  
  73.  
  74. if (soundState) //kills all warning Timer sounds when depressed
  75. {
  76. print(water);
  77. print(aluminium);
  78. }
  79.  
  80. aluminium = 0;
  81. water = 0;
  82.  
  83. GUILayout.Label("Aluminium", yellow, GUILayout.ExpandWidth(true));
  84. GUI.TextField(new Rect(110, 75, 60, 20), aluminium.ToString("F0"));
  85.  
  86. GUILayout.Label("Water", yellow, GUILayout.ExpandWidth(true));
  87. GUI.TextField(new Rect(175, 75, 60, 20), water.ToString("F0"));
  88.  
  89. GUILayout.EndVertical();
  90.  
  91. GUI.DragWindow(new Rect(0, 0, 10000, 20));
  92.  
  93. }
  94.  
  95.  
  96. //Draw the GUI window
  97. private void drawGUI()
  98. {
  99. GUI.skin = HighLogic.Skin;
  100. windowPos = GUILayout.Window(1403252, windowPos, WindowGUI, "Mining Cargo Inventory", GUILayout.MinWidth(250));
  101. }
  102.  
  103. //Initialize gui when part starts and position
  104. protected override void onPartStart()
  105. {
  106. if ((windowPos.x == 0) && (windowPos.y == 0))//windowPos is used to position the GUI window, lets set it in the center of the screen
  107. {
  108. windowPos = new Rect(Screen.width / 6, Screen.height / 3, 10, 10);
  109. }
  110. }
  111. protected override void onPartDestroy()
  112. {
  113. RenderingManager.RemoveFromPostDrawQueue(3, new Callback(drawGUI)); //close the GUI
  114. }
  115.  
  116. }
Add Comment
Please, Sign In to add comment